Skip to content

Commit

Permalink
Use .env file for docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanExtreme002 committed Jul 15, 2024
1 parent 27b5392 commit 91147ec
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
19 changes: 19 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Elasticsearch]
ELASTICSEARCH_HOST="elasticsearch"
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_MAX_RESULTS=20
ELASTICSEARCH_TIMEOUT=10

[Back-end]
BACKEND_HOST="0.0.0.0"
BACKEND_PORT=5000
WORKERS_COUNT=1
RELOAD="true"
LOG_LEVEL="INFO"

[Front-end]
REACT_APP_API_URL="http://localhost:5000/graphql"
REACT_APP_PORT=3000

[SEED]
seed=false
2 changes: 0 additions & 2 deletions COMMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,3 @@ Irei dedicar essa seção para falar de coisas que eu faria, ou gostaria de impl
- Implementar testes automatizados de UI;

- Caso esse projeto fosse deployado para uma cloud, eu implementaria um CD no workflow do GitHub Actions;

- Utilizar alguma ferramenta para passar as variáveis de ambiente de um arquivo para o *docker-compose*.
5 changes: 2 additions & 3 deletions back/.env.sample
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[Application]
ENVIRONMENT="DEV"
APPLICATION_HOST="0.0.0.0"
APPLICATION_PORT=5000
BACKEND_HOST="0.0.0.0"
BACKEND_PORT=5000
WORKERS_COUNT=1
RELOAD="true"
LOG_LEVEL="INFO"
Expand Down
4 changes: 2 additions & 2 deletions back/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class Config:
Base configuration.
"""

HOST = os.getenv("APPLICATION_HOST", "0.0.0.0")
PORT = int(os.getenv("APPLICATION_PORT", "5000"))
HOST = os.getenv("BACKEND_HOST", "0.0.0.0")
PORT = int(os.getenv("BACKEND_PORT", "5000"))
WORKERS_COUNT = int(os.getenv("WORKERS_COUNT", "1"))
RELOAD = os.getenv("RELOAD", "true").lower() == "true"
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").lower()
Expand Down
20 changes: 11 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,31 @@ services:
environment:
- discovery.type=single-node
ports:
- "9200:9200"
- "${ELASTICSEARCH_PORT}:${ELASTICSEARCH_PORT}"
- "9300:9300"
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:9200 || exit 1"]
test: ["CMD-SHELL", "curl -f http://localhost:${ELASTICSEARCH_PORT} || exit 1"]
interval: 10s
timeout: 5s
retries: 5

backend:
image: python:3.10
env_file: .env
working_dir: /app
volumes:
- ./back:/app
ports:
- "5000:5000"
- "${BACKEND_PORT}:${BACKEND_PORT}"

command: >
sh -c 'pip install poetry && poetry install && (echo "Waiting for Elasticsearch to be ready..." &&
until curl -s http://elasticsearch:9200/_cluster/health | grep -q "\"status\":\"green\|yellow\""; do
until curl -s http://elasticsearch:${ELASTICSEARCH_PORT}/_cluster/health | grep -q "\"status\":\"green\|yellow\""; do
echo "Elasticsearch not ready yet, waiting...";
sleep 5;
done) &&
echo "Elasticsearch is ready!";
if [ "$seed" = "true" ]; then
Expand All @@ -40,21 +41,22 @@ services:
depends_on:
- elasticsearch
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:5000 || exit 1"]
test: ["CMD-SHELL", "curl -f http://localhost:${BACKEND_PORT} || exit 1"]
interval: 10s
timeout: 5s
retries: 5

frontend:
image: node:16
env_file: .env
working_dir: /app
volumes:
- ./front:/app
ports:
- "3000:3000"
command: sh -c "npm install && npm start"
- "${REACT_APP_PORT}:${REACT_APP_PORT}"
command: sh -c "npm install && export PORT=${REACT_APP_PORT} && npm start"
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:3000 || exit 1"]
test: ["CMD-SHELL", "curl -f http://localhost:${REACT_APP_PORT} || exit 1"]
interval: 10s
timeout: 5s
retries: 5

0 comments on commit 91147ec

Please sign in to comment.