Skip to content

Commit cae98c9

Browse files
committed
feat: Enhance configuration for environment variables and update Docker setup
1 parent 6244600 commit cae98c9

6 files changed

Lines changed: 42 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ coverage/
3838
.env
3939
.env.local
4040
.env.docker
41+
.env.production
4142

4243
# CD and deployment files
4344
publish-profile.yml

backend/services/pg_connection.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
DB_PASS = env.get("DB_PASS", "postgres")
77
DB_HOST = env.get("DB_HOST", "127.0.0.1")
88
DB_PORT = env.get("DB_PORT", "5432")
9+
DB_UNIX_SOCKET = env.get("DB_UNIX_SOCKET")
910

1011

1112
def get_connection():
12-
conn = psycopg2.connect(
13-
dbname=DB_NAME, user=DB_USER, password=DB_PASS, host=DB_HOST, port=DB_PORT
14-
)
13+
# Use Unix socket if available (Cloud SQL), otherwise use host/port (local dev)
14+
if DB_UNIX_SOCKET:
15+
conn = psycopg2.connect(
16+
dbname=DB_NAME, user=DB_USER, password=DB_PASS, host=DB_UNIX_SOCKET
17+
)
18+
else:
19+
conn = psycopg2.connect(
20+
dbname=DB_NAME, user=DB_USER, password=DB_PASS, host=DB_HOST, port=DB_PORT
21+
)
1522
conn.autocommit = True
1623
return conn

frontend/Dockerfile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Frontend Dockerfile
22
FROM node:20 AS build
33
WORKDIR /app
4+
5+
# Build arguments for environment variables
6+
ARG VITE_API_BASE_URL
7+
ARG VITE_AZURE_REDIRECT_URI
8+
9+
# Set environment variables for build
10+
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
11+
ENV VITE_AZURE_REDIRECT_URI=$VITE_AZURE_REDIRECT_URI
12+
413
COPY package.json package-lock.json ./
514
RUN npm install
615
COPY . .
@@ -11,4 +20,12 @@ WORKDIR /usr/share/nginx/html
1120
COPY --from=build /app/dist .
1221
EXPOSE 4000
1322
RUN rm -rf /etc/nginx/conf.d/default.conf
14-
COPY nginx.conf /etc/nginx/conf.d
23+
COPY nginx.conf /etc/nginx/conf.d/default.conf.template
24+
25+
# Create script to substitute environment variables in nginx config
26+
RUN echo '#!/bin/sh' > /docker-entrypoint.sh && \
27+
echo 'envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf' >> /docker-entrypoint.sh && \
28+
echo 'exec nginx -g "daemon off;"' >> /docker-entrypoint.sh && \
29+
chmod +x /docker-entrypoint.sh
30+
31+
CMD ["/docker-entrypoint.sh"]

frontend/app.config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const USE_MSAL_AUTH = true;
1010

1111
/**
1212
* Defines the base URL for the backend API.
13-
* Change this to point to your deployed backend service.
14-
* For local development, this typically points to a local server.
13+
* Uses environment variable if available, otherwise defaults to localhost for development.
1514
*/
16-
export const API_BASE_URL = 'http://localhost:8000';
15+
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000';

frontend/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
server {
2-
listen 80;
2+
listen ${PORT:-80};
33
server_name localhost;
44

55
location / {

frontend/vite-env.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference types="vite/client" />
2+
3+
interface ImportMetaEnv {
4+
readonly VITE_API_BASE_URL: string
5+
readonly VITE_AZURE_REDIRECT_URI: string
6+
}
7+
8+
interface ImportMeta {
9+
readonly env: ImportMetaEnv
10+
}

0 commit comments

Comments
 (0)