Skip to content

Commit

Permalink
Updated docker-compose.yml to connect the services between each other
Browse files Browse the repository at this point in the history
  • Loading branch information
lhbelfanti committed Jun 6, 2024
1 parent 29edf79 commit f56b3e1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Dockerfile_migrations
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM alpine:latest

LABEL maintainer="Lucas Belfanti"

# Install necessary dependencies
RUN apk update && apk add --no-cache curl \
&& rm -rf /var/cache/apk/*

# Make HTTP request to /run-migrations/v1 endpoint
CMD ["sh", "-c", "curl -X POST http://app:8090/run-migrations/v1"]

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ erDiagram
To connect to the database we need to define a `.env` file in the root of the project. It should contain the following environment variables

```
DB_PORT=<Database port>
DB_NAME=<Database name>
DB_USER=<Database username>
DB_PASS=<Database password>
Expand Down
26 changes: 22 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
services:
app:
build: .
build:
context: .
dockerfile: Dockerfile_app
container_name: app
environment:
POSTGRES_DB_PORT: ${DB_PORT}
POSTGRES_DB_NAME: ${DB_NAME}
POSTGRES_DB_USER: ${DB_USER}
POSTGRES_DB_PASS: ${DB_PASS}
ports:
- 8000:8080
- 8080:8090
restart: on-failure
volumes:
- .:/app
Expand All @@ -17,6 +18,23 @@ services:
condition: service_healthy
networks:
- network
healthcheck:
test: ["CMD-SHELL", "sh -c 'curl -sSf http://localhost:8090/ping/v1 || exit 1'"]
interval: 5s
timeout: 10s
retries: 5

migrations:
image: alpine:latest
build:
context: .
dockerfile: Dockerfile_migrations
container_name: migrations
depends_on:
app:
condition: service_healthy
networks:
- network

postgres_db:
image: postgres:latest
Expand All @@ -26,7 +44,7 @@ services:
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
ports:
- '1234:${DB_PORT}'
- 1234:5432
volumes:
- database:/var/lib/postgresql/data
networks:
Expand Down

0 comments on commit f56b3e1

Please # to comment.