Skip to content

Commit ee06e75

Browse files
authored
Merge pull request #455 from TineoC/fix/deploy-api-and-ci
fix: deploy API and CI — release-based image tags, version endpoint, prod compose
2 parents 109b6c7 + a25bb1b commit ee06e75

File tree

17 files changed

+250
-186
lines changed

17 files changed

+250
-186
lines changed

.github/workflows/containers-publish.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ jobs:
2626
- name: Compute Docker container image addresses
2727
run: |
2828
DOCKER_REPOSITORY="ghcr.io/${GITHUB_REPOSITORY,,}"
29+
git fetch --tags --force
2930
3031
if [[ "${{ github.event_name }}" == "release" ]]; then
31-
DOCKER_TAG="${GITHUB_REF:11}"
32+
TAG="${GITHUB_REF#refs/tags/}"
33+
DOCKER_TAG="${TAG#v}"
3234
else
33-
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
34-
DOCKER_TAG="dev-${SHORT_SHA}"
35+
# Pre-release for develop
36+
BASE_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
37+
VERSION="${BASE_TAG#v}"
38+
TIMESTAMP=$(date +%Y%m%d%H%M%S)
39+
DOCKER_TAG="${VERSION}-dev.${TIMESTAMP}"
3540
fi
3641
3742
echo "DOCKER_REPOSITORY=${DOCKER_REPOSITORY}" >> $GITHUB_ENV
@@ -52,6 +57,7 @@ jobs:
5257
--file Dockerfile.prod \
5358
--tag "${DOCKER_REPOSITORY}/app:latest" \
5459
--tag "${DOCKER_REPOSITORY}/app:${DOCKER_TAG}" \
60+
--build-arg VERSION="${DOCKER_TAG}" \
5561
.
5662
5763
- name: "Push Docker container image app:latest"

.github/workflows/deploy-downstream.yml

Lines changed: 0 additions & 110 deletions
This file was deleted.

.github/workflows/frontend-ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: "Frontend: Lint and Build"
2+
3+
on:
4+
push:
5+
branches: [develop]
6+
pull_request:
7+
branches: [develop]
8+
9+
jobs:
10+
frontend:
11+
name: Lint and Build
12+
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
working-directory: frontend
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: "18"
23+
cache: "npm"
24+
cache-dependency-path: frontend/package-lock.json
25+
26+
- name: Install dependencies
27+
run: npm ci --legacy-peer-deps
28+
29+
- name: Lint
30+
run: npm run lint
31+
continue-on-error: true
32+
33+
- name: Build
34+
run: npm run build
35+
continue-on-error: true

Dockerfile.prod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ RUN npm run build
2121
# Stage 2: Build Backend
2222
FROM python:3.11.4-slim-bullseye
2323

24+
# Receive version argument from build command
25+
ARG VERSION
26+
ENV VERSION=${VERSION}
27+
2428
# Set work directory
2529
WORKDIR /usr/src/app
2630

db/Dockerfile

Lines changed: 0 additions & 26 deletions
This file was deleted.

docker-compose.prod.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: balancer-prod
2+
version: "3.8"
3+
4+
services:
5+
db:
6+
image: pgvector/pgvector:pg15
7+
volumes:
8+
- postgres_data_prod:/var/lib/postgresql/data/
9+
- ./db/init-vector-extension.sql:/docker-entrypoint-initdb.d/init-vector-extension.sql
10+
environment:
11+
- POSTGRES_USER=balancer
12+
- POSTGRES_PASSWORD=balancer
13+
- POSTGRES_DB=balancer_dev
14+
networks:
15+
- app_net
16+
healthcheck:
17+
test: ["CMD-SHELL", "pg_isready -U balancer -d balancer_dev"]
18+
interval: 5s
19+
timeout: 5s
20+
retries: 5
21+
22+
app:
23+
image: balancer-app
24+
build:
25+
context: .
26+
dockerfile: Dockerfile.prod
27+
ports:
28+
- "8000:8000"
29+
env_file:
30+
- ./config/env/prod.env
31+
depends_on:
32+
db:
33+
condition: service_healthy
34+
networks:
35+
- app_net
36+
37+
volumes:
38+
postgres_data_prod:
39+
40+
networks:
41+
app_net:
42+
driver: bridge

docker-compose.yml

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
services:
22
db:
3-
# Workaround for PostgreSQL crash with pgvector v0.6.1 on ARM64
4-
# image: pgvector/pgvector:pg15
5-
# volumes:
6-
# - postgres_data:/var/lib/postgresql/data/
7-
# - ./db/init-vector-extension.sql:/docker-entrypoint-initdb.d/init-vector-extension.sql
8-
build:
9-
context: ./db
10-
dockerfile: Dockerfile
3+
image: pgvector/pgvector:pg15
114
volumes:
125
- postgres_data:/var/lib/postgresql/data/
6+
- ./db/init-vector-extension.sql:/docker-entrypoint-initdb.d/init-vector-extension.sql
137
environment:
148
- POSTGRES_USER=balancer
159
- POSTGRES_PASSWORD=balancer
@@ -24,17 +18,26 @@ services:
2418
networks:
2519
app_net:
2620
ipv4_address: 192.168.0.2
27-
# pgadmin:
28-
# container_name: pgadmin4
29-
# image: dpage/pgadmin4
30-
# environment:
31-
# PGADMIN_DEFAULT_EMAIL: balancer-noreply@codeforphilly.org
32-
# PGADMIN_DEFAULT_PASSWORD: balancer
33-
# ports:
34-
# - "5050:80"
35-
# networks:
36-
# app_net:
37-
# ipv4_address: 192.168.0.4
21+
healthcheck:
22+
test: ["CMD-SHELL", "pg_isready -U balancer -d balancer_dev"]
23+
interval: 5s
24+
timeout: 5s
25+
retries: 5
26+
27+
pgadmin:
28+
image: dpage/pgadmin4
29+
environment:
30+
- PGADMIN_DEFAULT_EMAIL=balancer-noreply@codeforphilly.org
31+
- PGADMIN_DEFAULT_PASSWORD=balancer
32+
ports:
33+
- "5050:80"
34+
depends_on:
35+
db:
36+
condition: service_healthy
37+
networks:
38+
app_net:
39+
ipv4_address: 192.168.0.4
40+
3841
backend:
3942
image: balancer-backend
4043
build: ./server
@@ -52,6 +55,13 @@ services:
5255
networks:
5356
app_net:
5457
ipv4_address: 192.168.0.3
58+
healthcheck:
59+
test: ["CMD-SHELL", "python3 -c 'import http.client;conn=http.client.HTTPConnection(\"localhost:8000\");conn.request(\"GET\",\"/admin/login/\");res=conn.getresponse();exit(0 if res.status in [200,301,302,401] else 1)'"]
60+
interval: 10s
61+
timeout: 5s
62+
retries: 5
63+
start_period: 10s
64+
5565
frontend:
5666
image: balancer-frontend
5767
build:
@@ -67,10 +77,17 @@ services:
6777
- "./frontend:/usr/src/app:delegated"
6878
- "/usr/src/app/node_modules/"
6979
depends_on:
70-
- backend
80+
backend:
81+
condition: service_healthy
7182
networks:
7283
app_net:
7384
ipv4_address: 192.168.0.5
85+
healthcheck:
86+
test: ["CMD-SHELL", "curl -f http://localhost:3000 || exit 1"]
87+
interval: 10s
88+
timeout: 5s
89+
retries: 5
90+
7491
volumes:
7592
postgres_data:
7693
networks:
@@ -79,4 +96,4 @@ networks:
7996
driver: default
8097
config:
8198
- subnet: "192.168.0.0/24"
82-
gateway: 192.168.0.1
99+
gateway: 192.168.0.1

frontend/.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# VITE_API_BASE_URL=https://balancertestsite.com/
2-
VITE_API_BASE_URL=http://localhost:8000
1+
# Optional: add VITE_* vars here if needed. None required for docker-compose;
2+
# the app uses relative API URLs and vite.config.ts proxies /api to the backend.

frontend/.env.production

Lines changed: 0 additions & 1 deletion
This file was deleted.

frontend/src/api/apiClient.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
endpoints,
88
} from "./endpoints";
99

10-
// Use empty string for relative URLs - all API calls will be relative to current domain
10+
// Empty baseURL so API calls are relative to current origin; one image works for both sandbox and production.
1111
const baseURL = "";
1212

1313
export const publicApi = axios.create({ baseURL });
@@ -306,6 +306,17 @@ const sendAssistantMessage = async (
306306
}
307307
};
308308

309+
export interface VersionResponse {
310+
version: string;
311+
}
312+
313+
const fetchVersion = async (): Promise<VersionResponse> => {
314+
const response = await publicApi.get<VersionResponse>(
315+
V1_API_ENDPOINTS.VERSION,
316+
);
317+
return response.data;
318+
};
319+
309320
export {
310321
handleSubmitFeedback,
311322
handleSendDrugSummary,
@@ -320,4 +331,5 @@ export {
320331
handleSendDrugSummaryStreamLegacy,
321332
fetchRiskDataWithSources,
322333
sendAssistantMessage,
334+
fetchVersion,
323335
};

0 commit comments

Comments
 (0)