готово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.
|
Разверните 3 сервиса на выбор в контейнерах docker с помощью docker-compose.
|
||||||
Требования и docker-compose:
|
Требования и docker-compose:
|
||||||
|
@ -14,10 +14,9 @@ services:
|
|||||||
nginx:
|
nginx:
|
||||||
image: nginx
|
image: nginx
|
||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "8085:8085"
|
||||||
volumes:
|
volumes:
|
||||||
- ./service_a.conf:/etc/nginx/conf.d/service_a.conf
|
- ./nginx.conf:/etc/nginx/conf.d/nginx.conf
|
||||||
- ./service_b.conf:/etc/nginx/conf.d/service_b.conf
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- service_a
|
- service_a
|
||||||
- service_b
|
- 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__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# хранение данных сущности A
|
# "customers"
|
||||||
entity_a_data = []
|
customers_data = []
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entity_a', methods=['GET'])
|
@app.route('/service_a/', methods=['GET'])
|
||||||
def get_entity_a():
|
def get_index():
|
||||||
return jsonify(entity_a_data)
|
return "Hello from service_a"
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entity_a', methods=['POST'])
|
@app.route('/service_a/customers', methods=['GET'])
|
||||||
def create_entity_a():
|
def get_customers():
|
||||||
new_entity = request.json
|
return jsonify(customers_data)
|
||||||
entity_a_data.append(new_entity)
|
|
||||||
return jsonify(new_entity), 201
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entity_a/<int:id>', methods=['PUT'])
|
@app.route('/service_a/customers', methods=['POST'])
|
||||||
def update_entity_a(id):
|
def create_customer():
|
||||||
for entity in entity_a_data:
|
new_customer = request.json
|
||||||
if entity['id'] == id:
|
customers_data.append(new_customer)
|
||||||
entity.update(request.json)
|
return jsonify(new_customer), 201
|
||||||
return jsonify(entity), 200
|
|
||||||
return jsonify({'error': 'Entity not found'}), 404
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entity_a/<int:id>', methods=['DELETE'])
|
@app.route('/service_a/customers/<int:id>', methods=['PUT'])
|
||||||
def delete_entity_a(id):
|
def update_customer(id):
|
||||||
global entity_a_data
|
for customer in customers_data:
|
||||||
entity_a_data = [entity for entity in entity_a_data if entity['id'] != id]
|
if customer['id'] == id:
|
||||||
return jsonify({'message': 'Entity deleted'}), 200
|
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__':
|
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__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# хранение данных сущности B
|
# "clients"
|
||||||
entity_b_data = []
|
clients_data = []
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entity_b', methods=['GET'])
|
@app.route('/', methods=['GET'])
|
||||||
def get_entity_b():
|
def get_index():
|
||||||
return jsonify(entity_b_data)
|
return "Hello from service_b"
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entity_b', methods=['POST'])
|
@app.route('/clients', methods=['GET'])
|
||||||
def create_entity_b():
|
def get_clients():
|
||||||
new_entity = request.json
|
return jsonify(clients_data)
|
||||||
entity_b_data.append(new_entity)
|
|
||||||
return jsonify(new_entity), 201
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entity_b/<int:id>', methods=['PUT'])
|
@app.route('/clients', methods=['POST'])
|
||||||
def update_entity_b(id):
|
def create_client():
|
||||||
for entity in entity_b_data:
|
new_client = request.json
|
||||||
if entity['id'] == id:
|
clients_data.append(new_client)
|
||||||
entity.update(request.json)
|
return jsonify(new_client), 201
|
||||||
return jsonify(entity), 200
|
|
||||||
return jsonify({'error': 'Entity not found'}), 404
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/entity_b/<int:id>', methods=['DELETE'])
|
@app.route('/clients/<int:id>', methods=['PUT'])
|
||||||
def delete_entity_b(id):
|
def update_client(id):
|
||||||
global entity_b_data
|
for client in clients_data:
|
||||||
entity_b_data = [entity for entity in entity_b_data if entity['id'] != id]
|
if client['id'] == id:
|
||||||
return jsonify({'message': 'Entity deleted'}), 200
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user