diff --git a/antonov_dmitry_lab_3/README.md b/antonov_dmitry_lab_3/README.md index 4f087bf..7c6afb0 100644 --- a/antonov_dmitry_lab_3/README.md +++ b/antonov_dmitry_lab_3/README.md @@ -1,4 +1,4 @@ -# Лабораторная работа №1 - Знакомство с docker и docker-compose +# Лабораторная работа №3 - Знакомство с docker и docker-compose Разверните 3 сервиса на выбор в контейнерах docker с помощью docker-compose. Требования и docker-compose: diff --git a/antonov_dmitry_lab_3/docker-compose.yml b/antonov_dmitry_lab_3/docker-compose.yml index b155a69..0b0fe2e 100644 --- a/antonov_dmitry_lab_3/docker-compose.yml +++ b/antonov_dmitry_lab_3/docker-compose.yml @@ -14,10 +14,9 @@ services: nginx: image: nginx ports: - - "80:80" + - "8085:8085" volumes: - - ./service_a.conf:/etc/nginx/conf.d/service_a.conf - - ./service_b.conf:/etc/nginx/conf.d/service_b.conf + - ./nginx.conf:/etc/nginx/conf.d/nginx.conf depends_on: - service_a - - service_b + - service_b \ No newline at end of file diff --git a/antonov_dmitry_lab_3/nginx.conf b/antonov_dmitry_lab_3/nginx.conf new file mode 100644 index 0000000..c07aa54 --- /dev/null +++ b/antonov_dmitry_lab_3/nginx.conf @@ -0,0 +1,13 @@ +server { + listen 8085; + listen [::]:8085; + server_name localhost; + + location /service_a/ { + proxy_pass http://127.0.0.1:5000; + } + + location /service_b/ { + proxy_pass http://127.0.0.1:5001; + } +} \ No newline at end of file diff --git a/antonov_dmitry_lab_3/service_a.conf b/antonov_dmitry_lab_3/service_a.conf deleted file mode 100644 index cece274..0000000 --- a/antonov_dmitry_lab_3/service_a.conf +++ /dev/null @@ -1,8 +0,0 @@ -server { - listen 80; - server_name service_a; - - location / { - proxy_pass http://service_a:5000; - } -} \ No newline at end of file diff --git a/antonov_dmitry_lab_3/service_a/app.py b/antonov_dmitry_lab_3/service_a/app.py index f5d6095..4836e89 100644 --- a/antonov_dmitry_lab_3/service_a/app.py +++ b/antonov_dmitry_lab_3/service_a/app.py @@ -2,36 +2,41 @@ from flask import Flask, jsonify, request app = Flask(__name__) -# хранение данных сущности A -entity_a_data = [] +# "customers" +customers_data = [] -@app.route('/entity_a', methods=['GET']) -def get_entity_a(): - return jsonify(entity_a_data) +@app.route('/service_a/', methods=['GET']) +def get_index(): + return "Hello from service_a" -@app.route('/entity_a', methods=['POST']) -def create_entity_a(): - new_entity = request.json - entity_a_data.append(new_entity) - return jsonify(new_entity), 201 +@app.route('/service_a/customers', methods=['GET']) +def get_customers(): + return jsonify(customers_data) -@app.route('/entity_a/', methods=['PUT']) -def update_entity_a(id): - for entity in entity_a_data: - if entity['id'] == id: - entity.update(request.json) - return jsonify(entity), 200 - return jsonify({'error': 'Entity not found'}), 404 +@app.route('/service_a/customers', methods=['POST']) +def create_customer(): + new_customer = request.json + customers_data.append(new_customer) + return jsonify(new_customer), 201 -@app.route('/entity_a/', methods=['DELETE']) -def delete_entity_a(id): - global entity_a_data - entity_a_data = [entity for entity in entity_a_data if entity['id'] != id] - return jsonify({'message': 'Entity deleted'}), 200 +@app.route('/service_a/customers/', methods=['PUT']) +def update_customer(id): + for customer in customers_data: + if customer['id'] == id: + customer.update(request.json) + return jsonify(customer), 200 + return jsonify({'error': 'Customer not found'}), 404 + + +@app.route('/service_a/customers/', methods=['DELETE']) +def delete_customer(id): + global customers_data + customers_data = [customer for customer in customers_data if customer['id'] != id] + return jsonify({'message': 'Customer deleted'}), 200 if __name__ == '__main__': diff --git a/antonov_dmitry_lab_3/service_b.conf b/antonov_dmitry_lab_3/service_b.conf deleted file mode 100644 index fc397e1..0000000 --- a/antonov_dmitry_lab_3/service_b.conf +++ /dev/null @@ -1,8 +0,0 @@ -server { - listen 80; - server_name service_b; - - location / { - proxy_pass http://service_b:5001; - } -} diff --git a/antonov_dmitry_lab_3/service_b/app.py b/antonov_dmitry_lab_3/service_b/app.py index 49d7c42..cb9766d 100644 --- a/antonov_dmitry_lab_3/service_b/app.py +++ b/antonov_dmitry_lab_3/service_b/app.py @@ -2,36 +2,41 @@ from flask import Flask, jsonify, request app = Flask(__name__) -# хранение данных сущности B -entity_b_data = [] +# "clients" +clients_data = [] -@app.route('/entity_b', methods=['GET']) -def get_entity_b(): - return jsonify(entity_b_data) +@app.route('/', methods=['GET']) +def get_index(): + return "Hello from service_b" -@app.route('/entity_b', methods=['POST']) -def create_entity_b(): - new_entity = request.json - entity_b_data.append(new_entity) - return jsonify(new_entity), 201 +@app.route('/clients', methods=['GET']) +def get_clients(): + return jsonify(clients_data) -@app.route('/entity_b/', methods=['PUT']) -def update_entity_b(id): - for entity in entity_b_data: - if entity['id'] == id: - entity.update(request.json) - return jsonify(entity), 200 - return jsonify({'error': 'Entity not found'}), 404 +@app.route('/clients', methods=['POST']) +def create_client(): + new_client = request.json + clients_data.append(new_client) + return jsonify(new_client), 201 -@app.route('/entity_b/', methods=['DELETE']) -def delete_entity_b(id): - global entity_b_data - entity_b_data = [entity for entity in entity_b_data if entity['id'] != id] - return jsonify({'message': 'Entity deleted'}), 200 +@app.route('/clients/', methods=['PUT']) +def update_client(id): + for client in clients_data: + if client['id'] == id: + client.update(request.json) + return jsonify(client), 200 + return jsonify({'error': 'Client not found'}), 404 + + +@app.route('/clients/', methods=['DELETE']) +def delete_client(id): + global clients_data + clients_data = [client for client in clients_data if client['id'] != id] + return jsonify({'message': 'Client deleted'}), 200 if __name__ == '__main__':