Browse Source

initial commit

master
Anja Freudenreich 7 months ago
commit
f077ffdf3c
6 changed files with 100 additions and 0 deletions
  1. 11
    0
      Dockerfile
  2. 11
    0
      Dockerfile_py
  3. 27
    0
      app.py
  4. 21
    0
      docker-compose.yml
  5. 27
    0
      player.py
  6. 3
    0
      requirements.txt

+ 11
- 0
Dockerfile View File

@@ -0,0 +1,11 @@
# Dockerfile
FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY app.py .

CMD ["python", "app.py"]

+ 11
- 0
Dockerfile_py View File

@@ -0,0 +1,11 @@
# Dockerfile
FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install requests

COPY player.py .

CMD ["python", "player.py"]

+ 27
- 0
app.py View File

@@ -0,0 +1,27 @@
# app.py
from flask import Flask, request
from werkzeug.urls import url_quote_plus

app = Flask(__name__)

def fizzbuzz(num):
if num % 3 == 0 and num % 5 == 0:
return "fizzbuzz"
elif num % 3 == 0:
return "fizz"
elif num % 5 == 0:
return "buzz"
else:
return str(num)

@app.route('/fizzbuzz', methods=['POST'])
def compute_fizzbuzz():
data = request.json
try:
number = int(data['number'])
return fizzbuzz(number)
except (KeyError, ValueError):
return "Invalid input: Please provide a valid number", 400

if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)

+ 21
- 0
docker-compose.yml View File

@@ -0,0 +1,21 @@
version: '3.8'

services:
fizzbuzz_server:
image: fizzbuzz_app
ports:
- "8080:8080"
networks:
- fizzbuzz_network
hostname: fizzbuzz_server

fizzbuzz_client:
image: player
depends_on:
- fizzbuzz_server
networks:
- fizzbuzz_network

networks:
fizzbuzz_network:
driver: bridge

+ 27
- 0
player.py View File

@@ -0,0 +1,27 @@
import requests
import json

# Define the server adress and port
#SERVER_ADDR = "http://172.18.0.2"
#SERVER_ADDR = "http://127.0.0.1"
#SERVER_ADDR = "host.docker.internal"
SERVER_ADDR = "http://fizzbuzz_server"
SERVER_PORT =8080

# Define the URL for the FizzBuzz endpoint
URL = f"{SERVER_ADDR}:{SERVER_PORT}/fizzbuzz"

try:
for number in range(1,101):
# Define the payload data (JSON format)
payload = {'number': number}

# Send the HTTP POST request with JSON payload
response = requests.post(URL, json=payload)

# Print the response
print(f"Number: {number}, Response: {response.text}")

except requests.RequestException as e:
# Handle request exceptions
print("Error:", e)

+ 3
- 0
requirements.txt View File

@@ -0,0 +1,3 @@
# requirements.txt
Flask==2.0.1
Werkzeug==2.2.2

Loading…
Cancel
Save