From 914b056c48d501ff7e45d6c6ead0330304600db3 Mon Sep 17 00:00:00 2001 From: mrasheduzzaman Date: Sun, 9 Jun 2024 17:09:54 +0600 Subject: [PATCH] fix: docker image buiild and database issue --- Makefile | 23 +++++++++++++---------- compose.yml | 24 +++++++++++++++++------- test.sh | 4 ++-- 3 files changed, 32 insertions(+), 19 deletions(-) mode change 100644 => 100755 test.sh diff --git a/Makefile b/Makefile index 229a0fa..0f1e0b0 100644 --- a/Makefile +++ b/Makefile @@ -11,25 +11,28 @@ setup: cargo install cargo-watch cargo install diesel_cli --no-default-features --features postgres -services: +up: @echo "Starting all services" docker compose up -data: - @echo "Starting postgres container" - docker compose up -d db - -is_db_running: - @./check_container.sh $(DB_CONTAINER_NAME) +down: + @echo "Down all services" + docker compose down stop: + @echo "Stop service named $(APP_NAME)" docker container stop $(APP_NAME) + +data: + @echo "Starting postgres container" + docker compose up -d db + test: ./test.sh -compose: - docker compose up -d +is_db_running: + @./check_container.sh $(DB_CONTAINER_NAME) run: is_db_running cargo watch -q -c -w src/ -x run @@ -68,4 +71,4 @@ remove: docker container rm --force --volumes $(APP_NAME) list: - docker container ls --all --no-trunc + docker container ls --all diff --git a/compose.yml b/compose.yml index 5431c92..2e5dc09 100644 --- a/compose.yml +++ b/compose.yml @@ -5,24 +5,25 @@ services: postgres: image: postgres:latest container_name: ${DATABASE} - restart: always - user: ${POSTGRES_USER} + restart: unless-stopped secrets: - postgres_password volumes: - postgres-data:/var/lib/postgresql/data environment: - POSTGRES_DB: ${POSTGRES_DB} + POSTGRES_DB: ${POSTGRES_DB:-fakes} POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password - expose: - - 5432 + ports: + - 5432:5432 healthcheck: - test: [ "CMD", "pg_isready"] + test: [ "CMD", "pg_isready", "-U", "${POSTGRES_USER}"] start_period: 5s start_interval: 10s interval: 10s timeout: 5s retries: 5 + networks: + - rusty_network migration: build: @@ -32,6 +33,8 @@ services: depends_on: postgres: condition: service_healthy + networks: + - rusty_network backend: build: @@ -45,7 +48,14 @@ services: postgres: condition: service_healthy migration: - condition: service_healthy + condition: service_completed_successfully + networks: + - rusty_network + + +networks: + rusty_network: + driver: bridge volumes: diff --git a/test.sh b/test.sh old mode 100644 new mode 100755 index 4207313..649c175 --- a/test.sh +++ b/test.sh @@ -1,8 +1,8 @@ #!/bin/bash set -ex -res=$(curl -s -X POST http://127.0.0.1:5001/users -H "Content-Type: application/json" \ - -d '{"name": "Rashed", "age": "27"}') +res=$(curl -s -X GET http://127.0.0.1:5001/fakes -H "Content-Type: application/json" \ + -d '{ "results": [] }') echo "${res}"