Skip to content

Commit 022a039

Browse files
committed
fixes docker compose and build_and_run script.
1 parent ab5da53 commit 022a039

File tree

2 files changed

+49
-46
lines changed

2 files changed

+49
-46
lines changed

build_and_run.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# filepath: build_and_run.sh
3+
# This script builds and runs the Docker images using docker-compose.
4+
# It uses the .env file (default: .env.local) for environment variables.
5+
# Usage: ./build_and_run.sh [optional_env_file]
6+
# If you don't pass an env file, it defaults to .env.local.
7+
8+
set -e
9+
10+
# Use first argument as env file if provided, else default to .env.local
11+
ENV_FILE=${1:-.env.local}
12+
13+
if [ ! -f "$ENV_FILE" ]; then
14+
echo "ERROR: ${ENV_FILE} not found. Please create it with the required environment variables."
15+
exit 1
16+
fi
17+
18+
echo "Using environment file: ${ENV_FILE}"
19+
20+
# Export ENV_FILE variable so docker-compose can use it
21+
export ENV_FILE
22+
23+
echo "Building and running Docker images via docker-compose using ${ENV_FILE}..."
24+
docker-compose --env-file="${ENV_FILE}" up --build -d
25+
26+
echo "Docker containers are up and running on your localhost."
27+
echo "To view logs, run: docker-compose logs -f"
28+
echo "To stop the containers, run: docker-compose down"

docker-compose.yaml

+21-46
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,51 @@
1+
version: '3.8'
12
services:
23
# Local PostgreSQL container (used for local development when needed)
3-
postgres:
4-
image: postgres:17 # Use PostgreSQL version 17
5-
container_name: postgres # Name the container "postgres"
6-
environment:
7-
POSTGRES_USER: ${POSTGRES_USER} # Set PostgreSQL user from environment variable
8-
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # Set PostgreSQL password from environment variable
9-
POSTGRES_DB: ${POSTGRES_DB} # Set PostgreSQL database name from environment variable
4+
db:
5+
image: postgres:latest # Use latest PostgreSQL version
6+
env_file:
7+
- ${ENV_FILE:-.env.local} # Override by setting ENV_FILE; defaults to .env.local
108
ports:
11-
- "${POSTGRES_PORT}:5432" # Map host port to container's PostgreSQL port
9+
- "${DB_PORT:-5432}:5432" # Map host port from .env variable to container's PostgreSQL port
1210
volumes:
13-
- postgres_data:/var/lib/postgresql/data # Persist PostgreSQL data
11+
- db_data:/var/lib/postgresql/data # Persist PostgreSQL data
1412
- ./migration/src/setup.sql:/docker-entrypoint-initdb.d/0-setup.sql # Initialize database with setup.sql
15-
- ./migration/src/refactor_platform_rs.sql:/docker-entrypoint-initdb.d/1-refactor_plaform_rs.sql # Initialize with refactor_platform_rs.sql
13+
- ./migration/src/refactor_platform_rs.sql:/docker-entrypoint-initdb.d/1-refactor_platform_rs.sql # Initialize with refactor_platform_rs.sql
1614
- ./migration/src/setup_default_user.sql:/docker-entrypoint-initdb.d/2-setup_default_user.sql # Initialize with setup_default_user.sql
1715
networks:
1816
- backend_network # Connect to backend_network
1917

2018
# Rust application that connects to either local or remote PostgreSQL
21-
rust-app:
22-
image: rust-backend # Use the built image
19+
backend:
2320
build:
2421
context: . # Build context is current directory
2522
dockerfile: Dockerfile # Use specified Dockerfile
26-
target: runtime # Use runtime target
27-
platform: ${PLATFORM} # Specify the platform
28-
container_name: ${CONTAINER_NAME} # Name the container, default is "rust-app"
29-
environment:
30-
POSTGRES_USER: ${POSTGRES_USER} # Set PostgreSQL user from environment variable
31-
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # Set PostgreSQL password from environment variable
32-
POSTGRES_DB: ${POSTGRES_DB} # Set PostgreSQL database name from environment variable
33-
POSTGRES_SCHEMA: ${POSTGRES_SCHEMA} # Set PostgreSQL schema from environment variable
34-
POSTGRES_HOST: postgres # Set PostgreSQL host to "postgres" service
35-
POSTGRES_PORT: ${POSTGRES_PORT} # Set PostgreSQL port from environment variable
36-
DATABASE_URL: postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:${POSTGRES_PORT}/${POSTGRES_DB} # Configure database URL
37-
BACKEND_PORT: ${BACKEND_PORT} # Set service port from environment variable
38-
BACKEND_INTERFACE: ${BACKEND_INTERFACE} # Set service interface from environment variable
39-
BACKEND_ALLOWED_ORIGINS: ${BACKEND_ALLOWED_ORIGINS}
40-
BACKEND_LOG_FILTER_LEVEL: ${BACKEND_LOG_FILTER_LEVEL}
23+
env_file:
24+
- ${ENV_FILE:-.env.local} # Same override capability
4125
ports:
4226
- "${BACKEND_PORT}:${BACKEND_PORT}" # Map host port to container's service port
4327
depends_on:
44-
- postgres # Ensure postgres service starts before rust-app
28+
- db # Ensure db service starts before backend
4529
networks:
4630
- backend_network # Connect to backend_network
4731
command: ["sh", "-c", "sleep 5 && /usr/local/bin/refactor_platform_rs"] # Wait for Postgres and run the app
4832

49-
nextjs-app:
33+
frontend:
5034
build:
51-
context: https://github.com/refactor-group/refactor-platform-fe.git#main # change to fs directory to run locally
35+
context: .
5236
dockerfile: Dockerfile
53-
target: runner # Use runner target
54-
args:
55-
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL: ${BACKEND_SERVICE_PROTOCOL}
56-
NEXT_PUBLIC_BACKEND_SERVICE_PORT: ${BACKEND_PORT}
57-
NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${BACKEND_SERVICE_HOST}
58-
NEXT_PUBLIC_BACKEND_API_VERSION: ${BACKEND_API_VERSION}
59-
FRONTEND_SERVICE_PORT: ${FRONTEND_SERVICE_PORT}
60-
FRONTEND_SERVICE_INTERFACE: ${FRONTEND_SERVICE_INTERFACE}
61-
environment:
62-
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL: ${BACKEND_SERVICE_PROTOCOL}
63-
NEXT_PUBLIC_BACKEND_SERVICE_PORT: ${BACKEND_PORT}
64-
NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${BACKEND_SERVICE_HOST}
65-
NEXT_PUBLIC_BACKEND_API_VERSION: ${BACKEND_API_VERSION}
37+
env_file:
38+
- ${ENV_FILE:-.env.local}
6639
ports:
67-
- "${FRONTEND_SERVICE_PORT}:${FRONTEND_SERVICE_PORT}" # Map host port to frontend container's service port
40+
- "${FRONTEND_PORT}:${FRONTEND_PORT}" # Map a different host port to distinguish frontend
6841
depends_on:
69-
- rust-app # Ensure postgres service starts before rust-app
42+
- backend
43+
# Override command to run the frontend binary instead of the backend binary
44+
command: ["sh", "-c", "sleep 5 && /usr/local/bin/refactor_platform_rs"]
7045

7146
networks:
7247
backend_network:
7348
driver: bridge # Use bridge network driver
7449

7550
volumes:
76-
postgres_data: # Define postgres_data volume
51+
db_data: # Define db_data volume

0 commit comments

Comments
 (0)