Skip to content

Commit e516932

Browse files
authored
Merge pull request #88 from refactor-group/pass_env_from_backend_for_container_build
2 parents 1808420 + 7d50ea7 commit e516932

File tree

2 files changed

+72
-23
lines changed

2 files changed

+72
-23
lines changed

docker-compose.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,20 @@ services:
5151
context: https://github.com/refactor-group/refactor-platform-fe.git#main # change to fs directory to run locally
5252
dockerfile: Dockerfile
5353
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}
5466
ports:
55-
- "${FRONTEND_PORT}:${FRONTEND_PORT}" # Map host port to frontend container's service port
67+
- "${FRONTEND_SERVICE_PORT}:${FRONTEND_SERVICE_PORT}" # Map host port to frontend container's service port
5668
depends_on:
5769
- rust-app # Ensure postgres service starts before rust-app
5870

docs/runbooks/Container-README.md

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ Decide whether you're connecting to a **local PostgreSQL container** (using Dock
3030

3131
- Create a `.env.local` file based on the template below and specify `POSTGRES_HOST=postgres`.
3232

33-
#### **For Remote PostgreSQL**
34-
35-
- Create a `.env.remote-db` file and set `POSTGRES_HOST` to the external IP or hostname of the remote PostgreSQL instance.
36-
37-
Example `.env.local`:
33+
**Example** `.env.local`:
3834

3935
```env
4036
POSTGRES_USER=refactor
@@ -44,41 +40,70 @@ POSTGRES_HOST=postgres
4440
POSTGRES_PORT=5432
4541
POSTGRES_SCHEMA=refactor_platform
4642
DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB
43+
44+
BACKEND_LOG_FILTER_LEVEL="DEBUG"
4745
BACKEND_PORT=4000
4846
BACKEND_INTERFACE=0.0.0.0
4947
BACKEND_ALLOWED_ORIGINS="http://localhost:3000,https://localhost:3000"
50-
FRONTEND_PORT=3000
48+
49+
BACKEND_SERVICE_PROTOCOL="http"
50+
BACKEND_SERVICE_PORT=${BACKEND_PORT}
51+
BACKEND_SERVICE_HOST="localhost"
52+
BACKEND_API_VERSION="0.0.1"
53+
FRONTEND_SERVICE_INTERFACE=0.0.0.0
54+
FRONTEND_SERVICE_PORT=3000
55+
5156
USERNAME=appuser
5257
USER_UID=1000
5358
USER_GID=1000
5459
CONTAINER_NAME=refactor-platform
5560
PLATFORM=linux/arm64
5661
```
5762

63+
#### **For Remote PostgreSQL**
64+
65+
- Create a `.env.remote-db` file and set `POSTGRES_HOST` to the external IP or hostname of the remote PostgreSQL instance.
66+
5867
**Example** `.env.remote-db`:
5968

6069
```env
61-
POSTGRES_USER=remote_refactor
62-
POSTGRES_PASSWORD=remote_password
63-
POSTGRES_DB=refactor
64-
POSTGRES_HOST=postgres.example.com
65-
POSTGRES_SCHEMA=refactor_platform
66-
DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB
67-
POSTGRES_PORT=5432
70+
# PostgreSQL environment variables for local development
71+
POSTGRES_USER=refactor # Default PostgreSQL user for local development
72+
POSTGRES_PASSWORD=password # Default PostgreSQL password for local development
73+
POSTGRES_DB=refactor # Default PostgreSQL database for local development
74+
POSTGRES_HOST=postgres # The local Docker Compose PostgreSQL container hostname
75+
POSTGRES_PORT=5432 # PostgreSQL default port for local development
76+
POSTGRES_SCHEMA=refactor_platform # PostgreSQL schema for the application
77+
# Database connection URL for the Rust application
78+
DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
79+
80+
# Rust application environment variables
81+
BACKEND_LOG_FILTER_LEVEL="DEBUG"
82+
BACKEND_ALLOWED_ORIGINS="http://localhost:3000,https://localhost:3000"
6883
BACKEND_PORT=4000
6984
BACKEND_INTERFACE=0.0.0.0
70-
BACKEND_ALLOWED_ORIGINS="http://localhost:3000,https://localhost:3000"
71-
FRONTEND_PORT=3000
72-
USERNAME=remote_appuser
73-
USER_UID=1001
74-
USER_GID=1001
75-
CONTAINER_NAME=refactor-platform
76-
PLATFORM=linux/arm64
85+
86+
# Next.js application build & environment variables
87+
BACKEND_SERVICE_PROTOCOL="http"
88+
BACKEND_SERVICE_PORT=${BACKEND_PORT}
89+
BACKEND_SERVICE_HOST="localhost"
90+
BACKEND_API_VERSION="0.0.1"
91+
FRONTEND_SERVICE_INTERFACE=0.0.0.0
92+
FRONTEND_SERVICE_PORT=3000
93+
94+
PLATFORM=linux/arm64 # For Raspberry Pi 5 or Apple Silicon
95+
CONTAINER_NAME="refactor-platform"
96+
97+
# App user configuration
98+
USERNAME=appuser # Username for the non-root user in the container
99+
USER_UID=1000 # User ID for the appuser
100+
USER_GID=1000 # Group ID for the appuser
77101
```
78102

79103
### 3. **Review `docker-compose.yaml`**
80104

81-
The `docker-compose.yaml` file uses environment variables defined in your `.env` files.
105+
The `docker-compose.yaml` file uses environment variables defined in your `.env` file setting important
106+
configuration variables for both the Rust backend and the Next.js frontend applications.
82107

83108
```yaml
84109
services:
@@ -132,8 +157,20 @@ services:
132157
context: https://github.com/refactor-group/refactor-platform-fe.git#main
133158
dockerfile: Dockerfile
134159
target: runner
160+
args:
161+
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL: ${BACKEND_SERVICE_PROTOCOL}
162+
NEXT_PUBLIC_BACKEND_SERVICE_PORT: ${BACKEND_PORT}
163+
NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${BACKEND_SERVICE_HOST}
164+
NEXT_PUBLIC_BACKEND_API_VERSION: ${BACKEND_API_VERSION}
165+
FRONTEND_SERVICE_PORT: ${FRONTEND_SERVICE_PORT}
166+
FRONTEND_SERVICE_INTERFACE: ${FRONTEND_SERVICE_INTERFACE}
167+
environment:
168+
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL: ${BACKEND_SERVICE_PROTOCOL}
169+
NEXT_PUBLIC_BACKEND_SERVICE_PORT: ${BACKEND_PORT}
170+
NEXT_PUBLIC_BACKEND_SERVICE_HOST: ${BACKEND_SERVICE_HOST}
171+
NEXT_PUBLIC_BACKEND_API_VERSION: ${BACKEND_API_VERSION}
135172
ports:
136-
- "${FRONTEND_PORT}:${FRONTEND_PORT}"
173+
- "${FRONTEND_SERVICE_PORT}:${FRONTEND_SERVICE_PORT}"
137174
depends_on:
138175
- rust-app
139176

0 commit comments

Comments
 (0)