Skip to content

Commit

Permalink
setup docker compose for prod
Browse files Browse the repository at this point in the history
  • Loading branch information
ese-erigha committed May 30, 2021
1 parent 432fe33 commit 749993a
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 0 deletions.
191 changes: 191 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
version: '3.7'

services:
flask_api:
image: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/flask-api
build:
context: ./services/flask
container_name: flask_api # Do not use when in a swarm; cannot scale a service beyond 1 container if you have specified a custom name
volumes:
- ./services/flask/:/usr/src/app/
ports:
- "5000:5000"
env_file:
- env.prod
environment:
- MODE=${MODE}
- AUTH_TOKEN=${AUTH_TOKEN}
- MONGO_HOST=${MONGO_HOST}
- MONGO_PORT=${MONGO_PORT}
- MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE}
- MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
- DATABASE_USERNAME=${DATABASE_USERNAME}
- DATABASE_PASSWORD=${DATABASE_PASSWORD}
- ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST}
- ELASTIC_USERNAME=${ELASTIC_USERNAME}
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
depends_on:
- mongodb
- elasticsearch
networks:
- frontend
- backend

mongodb:
image: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/mongodb
container_name: mongodb
build:
context: mongodb/
volumes:
- mongodb_data:/data/db
expose:
- "27017"
env_file:
- env.prod
environment:
- MONGO_HOST=${MONGO_HOST}
- MONGO_PORT=${MONGO_PORT}
- MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE}
- MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
- DATABASE_USERNAME=${DATABASE_USERNAME}
- DATABASE_PASSWORD=${DATABASE_PASSWORD}
networks:
- backend

mongo_express:
image: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/mongo-express
container_name: mongo_express
build:
context: mongo-express/
ports:
- "8085:8081"
env_file:
- env.prod
environment:
- ME_CONFIG_BASICAUTH_USERNAME=${DATABASE_USERNAME}
- ME_CONFIG_BASICAUTH_PASSWORD=${DATABASE_PASSWORD}
- ME_CONFIG_MONGODB_SERVER=${MONGO_HOST}
- ME_CONFIG_MONGODB_PORT=${MONGO_PORT}
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_INITDB_ROOT_USERNAME}
- ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
depends_on:
- mongodb
networks:
- backend

nginx:
image: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/nginx
container_name: nginx
build:
context: nginx/
ports:
- "80:80"
- "443:443"
depends_on:
- flask_api
networks:
- frontend
- backend

elasticsearch:
image: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/elasticsearch
container_name: elasticsearch
build:
context: elasticsearch/
args:
ELK_VERSION: ${ELK_VERSION}
env_file:
- env.prod
environment:
ELASTIC_USERNAME: ${ELASTIC_USERNAME}
ELASTIC_PASSWORD: ${ELASTIC_PASSWORD}
ELASTIC_CLUSTER_NAME: ${ELASTIC_CLUSTER_NAME}
ELASTIC_NODE_NAME: ${ELASTIC_NODE_NAME}
ELASTIC_INIT_MASTER_NODE: ${ELASTIC_INIT_MASTER_NODE}
ELASTIC_DISCOVERY_SEEDS: ${ELASTIC_DISCOVERY_SEEDS}
ES_JAVA_OPTS: -Xmx${ELASTICSEARCH_HEAP} -Xms${ELASTICSEARCH_HEAP}
bootstrap.memory_lock: "true"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 200000
hard: 200000
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
secrets:
- source: elasticsearch.keystore
target: /usr/share/elasticsearch/config/elasticsearch.keystore
- source: elastic.certificates
target: /usr/share/elasticsearch/config/certs/elastic-certificates.p12
expose:
- "9200"
- "9300"
networks:
- backend

kibana:
image: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/kibana
container_name: kibana
build:
context: kibana/
args:
ELK_VERSION: ${ELK_VERSION}
ports:
- 5605:5601
depends_on:
- elasticsearch
env_file:
- env.prod
environment:
ELASTIC_USERNAME: ${ELASTIC_USERNAME}
ELASTIC_PASSWORD: ${ELASTIC_PASSWORD}
ELASTICSEARCH_HOST_PORT: ${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}
volumes:
- ./kibana/config/:/usr/share/kibana/config:ro
networks:
- backend

logstash:
image: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/logstash
container_name: logstash
build:
context: logstash/
args:
ELK_VERSION: ${ELK_VERSION}
volumes:
- ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro
- ./logstash/pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf:ro
depends_on:
- elasticsearch
env_file:
- env.prod
environment:
ELASTIC_USERNAME: ${ELASTIC_USERNAME}
ELASTIC_PASSWORD: ${ELASTIC_PASSWORD}
ELASTICSEARCH_HOST_PORT: ${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}
LS_JAVA_OPTS: "-Xmx${LOGSTASH_HEAP} -Xms${LOGSTASH_HEAP}"
networks:
- backend

networks:
frontend:
driver: bridge
backend:
driver: bridge

volumes:
elasticsearch-data:
driver: local
mongodb_data:
driver: local

secrets:
elasticsearch.keystore:
file: ./secrets/elasticsearch.keystore
elastic.certificates:
file: ./secrets/elastic-certificates.p12
1 change: 1 addition & 0 deletions mongo-express/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mongo-express
1 change: 1 addition & 0 deletions mongodb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM mongo:4.4
5 changes: 5 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:1.17-alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
EXPOSE 80 443
23 changes: 23 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
server {

listen 80;
listen [::]:80;
server_name docker_flask_gunicorn_nginx;

location / {
set $upstream http://flask:5000;
proxy_pass $upstream;

# Do not change this
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 75s;
proxy_read_timeout 75s;
}

location /static {
rewrite ^/static(.*) /$1 break;
root /static;
}
}

0 comments on commit 749993a

Please sign in to comment.