Skip to content

Commit 87ce8b4

Browse files
robozorclaude
andcommitted
FE: adopt build-time API base (config.js) + build FE image in CI
Merge the deployment mechanism from main into this (sky-map) branch so the map version is deployable the same way: A) Build-time API base via config.js - frontend/config.js: window.API_BASE (default /api) - app.js reads window.API_BASE instead of hardcoding the API host - index.html loads config.js before app.js - docker/fe/Dockerfile bakes config.js from the API_BASE build arg - docker-compose.yml dev build passes API_BASE=http://localhost:8000 B) CI builds and pushes ghcr.io/bolidozor/meteorpointer-fe (with the sky map) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 250f421 commit 87ce8b4

6 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,24 @@ jobs:
4141
push: true
4242
tags: ${{ steps.meta.outputs.tags }}
4343
labels: ${{ steps.meta.outputs.labels }}
44+
45+
- name: Docker metadata for FE (tags + labels)
46+
id: meta-fe
47+
uses: docker/metadata-action@v5
48+
with:
49+
images: ghcr.io/bolidozor/meteorpointer-fe
50+
tags: |
51+
type=raw,value=latest,enable={{is_default_branch}}
52+
type=ref,event=branch
53+
type=semver,pattern={{version}}
54+
type=semver,pattern={{major}}.{{minor}}
55+
type=sha
56+
57+
- name: Build and push FE image
58+
uses: docker/build-push-action@v6
59+
with:
60+
context: .
61+
file: docker/fe/Dockerfile
62+
push: true
63+
tags: ${{ steps.meta-fe.outputs.tags }}
64+
labels: ${{ steps.meta-fe.outputs.labels }}

‎docker-compose.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ services:
5656
build:
5757
context: .
5858
dockerfile: docker/fe/Dockerfile
59+
args:
60+
# Dev: FE on :8080 talks to the API on :8000 directly (no /api prefix,
61+
# no proxy). Production builds keep the default `/api`.
62+
API_BASE: http://localhost:8000
5963
container_name: MeteorPointer-FE
6064
depends_on:
6165
- api

‎docker/fe/Dockerfile‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Minimal login-test frontend container (static files via nginx).
22
# The real frontend (MeteorPointer-FE / webUI) will replace this.
33
FROM nginx:1.27-alpine
4+
5+
# API base baked into config.js. Defaults to `/api` (production: same origin,
6+
# proxy serves the API under :443/api/ and strips the prefix). Override per
7+
# environment, e.g. --build-arg API_BASE=http://localhost:8000 for local dev.
8+
# Must NOT end with a slash.
9+
ARG API_BASE=/api
10+
411
COPY frontend/ /usr/share/nginx/html/
12+
RUN printf "window.API_BASE = '%s';\n" "$API_BASE" > /usr/share/nginx/html/config.js
513
EXPOSE 80

‎frontend/app.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Minimal login-test frontend. The real frontend (framework, full UI) follows.
2-
// The API is assumed to run on the same host, port 8000.
3-
const API = `${location.protocol}//${location.hostname}:8000`;
2+
// API base is injected at build time via config.js (window.API_BASE). It must
3+
// NOT end with a slash. Default `/api` matches the production deployment, where
4+
// the proxy serves the API under :443/api/ and strips the /api prefix before
5+
// forwarding to the container. Dev (FE on :8080) overrides it to the API host.
6+
const API = (window.API_BASE ?? '/api');
47
const t = (k, v) => window.MPI18n.t(k, v);
58

69
const $ = (id) => document.getElementById(id);

‎frontend/config.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Runtime config. The Docker image overwrites this at build time from the
2+
// API_BASE build arg (docker/fe/Dockerfile). Must NOT end with a slash.
3+
// `/api` = same origin, production proxy under :443/api/.
4+
window.API_BASE = '/api';

‎frontend/index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ <h3 data-i18n="about_box.coordsH"></h3>
162162
</div>
163163
</div>
164164

165+
<script src="config.js"></script>
165166
<script src="i18n.js"></script>
166167
<script src="sky.js"></script>
167168
<script src="app.js"></script>

0 commit comments

Comments
 (0)