готово2
This commit is contained in:
parent
23dfef9856
commit
b166d347a9
@ -1,4 +1,4 @@
|
||||
# Лабораторная работа №1 - Знакомство с docker и docker-compose
|
||||
# Лабораторная работа №3 - Знакомство с docker и docker-compose
|
||||
|
||||
Разверните 3 сервиса на выбор в контейнерах docker с помощью docker-compose.
|
||||
Требования и docker-compose:
|
||||
|
@ -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
|
13
antonov_dmitry_lab_3/nginx.conf
Normal file
13
antonov_dmitry_lab_3/nginx.conf
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name service_a;
|
||||
|
||||
location / {
|
||||
proxy_pass http://service_a:5000;
|
||||
}
|
||||
}
|
@ -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/<int:id>', 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/<int:id>', 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/<int:id>', 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/<int:id>', 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__':
|
||||
|
@ -1,8 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name service_b;
|
||||
|
||||
location / {
|
||||
proxy_pass http://service_b:5001;
|
||||
}
|
||||
}
|
@ -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/<int:id>', 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/<int:id>', 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/<int:id>', 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/<int:id>', 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__':
|
||||
|
Loading…
Reference in New Issue
Block a user