Add week 6 materials

This commit is contained in:
2026-10-14 20:13:57 +03:00
parent 991a0c8b56
commit 1ee860859a
17 changed files with 490 additions and 0 deletions
@@ -0,0 +1,10 @@
FROM python:3.9-slim-buster
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "./main.py"]
@@ -0,0 +1,33 @@
import os
from flask import Flask
from consul import Consul, Check
app = Flask(__name__)
consul_host = os.environ.get('CONSUL_HOST', 'localhost')
consul_port = os.environ.get('CONSUL_PORT', 8500)
my_host = os.environ.get('MY_HOST', 'localhost')
my_port = os.environ.get('MY_PORT', 5000)
# Initialize Consul client
consul = Consul(host=consul_host, port=consul_port)
# Register the Flask app in Consul
service_name = 'flask-hello-world'
consul.agent.service.register(
name=service_name,
service_id=f'{service_name}-{my_host}',
port=my_port,
check=Check.http(f'http://{my_host}:{my_port}/health', interval='10s', deregister='30s')
)
@app.route('/')
def hello():
return 'Hello, World!'
@app.route('/health')
def health():
return 'OK'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=my_port)
@@ -0,0 +1,3 @@
python-consul==1.1.0
Flask==2.2.2
Werkzeug==2.2.2