Skip to content

Commit abc75ae

Browse files
authored
fix(ui): pass app version via Docker build arg (#149)
## Summary - The UI footer was showing `v0.0.1` because the Dockerfile set `ENV VITE_APP_VERSION=""` (empty build arg default), which took precedence over the `.env.production` file that the workflow was writing. The footer fell back to `package.json`'s version. - Now passes the git version as a Docker `build-arg` (`APP_VERSION`) in the CI workflow, docker-compose, and Makefile. - Removes the hardcoded `v` prefix from the footer since `git describe` already includes it. ## Test plan - [x] Run `make docker-run` locally and verify the footer shows the correct version (e.g. `v0.1.0-58-g2d74b19-dirty`) - [ ] Verify the CI workflow builds and pushes the image with the correct version baked in
1 parent 2d74b19 commit abc75ae

7 files changed

Lines changed: 35 additions & 21 deletions

File tree

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ coverage.html
3636
# Misc
3737
*.log
3838
.ai_plans/
39-
!.build-version

.github/workflows/deploy-docker.core.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ jobs:
2626
VERSION=$(git describe --tags --always 2>/dev/null || echo "dev")
2727
COMMIT=$(git rev-parse --short HEAD)
2828
DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
29-
echo "VERSION=${VERSION}" >> .build-version
30-
echo "COMMIT=${COMMIT}" >> .build-version
31-
echo "DATE=${DATE}" >> .build-version
32-
echo "Writing build version: VERSION=${VERSION} COMMIT=${COMMIT} DATE=${DATE}"
29+
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
30+
echo "COMMIT=${COMMIT}" >> "$GITHUB_ENV"
31+
echo "DATE=${DATE}" >> "$GITHUB_ENV"
32+
echo "Build version: VERSION=${VERSION} COMMIT=${COMMIT} DATE=${DATE}"
3333
3434
- name: Deploy docker images
35-
uses: ethpandaops/actions/docker-build-push@7d7b7bfe36fe4cfa538acd0e23706a23ce07c3ac # master
35+
uses: ethpandaops/actions/docker-build-push@99b48ca2b233a2eff93e6a6df76e46b718aca108
3636
with:
3737
registry: ghcr.io
3838
registry_username: ${{ github.actor }}
@@ -41,3 +41,7 @@ jobs:
4141
push: true
4242
platforms: linux/amd64,linux/arm64
4343
file: Dockerfile
44+
build-args: |
45+
VERSION=${{ env.VERSION }}
46+
COMMIT=${{ env.COMMIT }}
47+
DATE=${{ env.DATE }}

.github/workflows/deploy-docker.ui.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ jobs:
2424
- name: Set app version from git
2525
run: |
2626
VERSION=$(git describe --tags --always 2>/dev/null || git rev-parse --short HEAD)
27-
echo "Setting VITE_APP_VERSION=${VERSION}"
28-
# Write a .env file that Vite picks up at build time
29-
echo "VITE_APP_VERSION=${VERSION}" > ui/.env.production
27+
echo "Setting APP_VERSION=${VERSION}"
28+
echo "APP_VERSION=${VERSION}" >> "$GITHUB_ENV"
3029
3130
- name: Deploy docker images
32-
uses: ethpandaops/actions/docker-build-push@7d7b7bfe36fe4cfa538acd0e23706a23ce07c3ac # master
31+
uses: ethpandaops/actions/docker-build-push@99b48ca2b233a2eff93e6a6df76e46b718aca108
3332
with:
3433
registry: ghcr.io
3534
registry_username: ${{ github.actor }}
@@ -38,3 +37,5 @@ jobs:
3837
push: true
3938
platforms: linux/amd64,linux/arm64
4039
file: Dockerfile.ui
40+
build-args: |
41+
APP_VERSION=${{ env.APP_VERSION }}

Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ ARG VERSION=dev
1717
ARG COMMIT=none
1818
ARG DATE=unknown
1919

20-
# Build the binary. If .build-version exists (CI), source it to override ARG defaults.
21-
RUN if [ -f .build-version ]; then \
22-
. ./.build-version; \
23-
fi && \
24-
CGO_ENABLED=0 GOOS=linux go build \
20+
# Build the binary
21+
RUN CGO_ENABLED=0 GOOS=linux go build \
2522
-tags "exclude_graphdriver_btrfs,exclude_graphdriver_devicemapper,containers_image_openpgp" \
2623
-ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \
2724
-o /benchmarkoor ./cmd/benchmarkoor

Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build build-core build-ui clean test-core test-coverage-core lint-core lint-core-all lint-ui fmt-core tidy-core install-core deps-ui run-core version-core run-ui help docker-build docker-build-core docker-build-ui docker-down docker-run docker-run-benchmark
1+
.PHONY: build build-core build-ui clean test-core test-coverage-core lint-core lint-core-all lint-ui fmt-core tidy-core install-core deps-ui run-core version-core run-ui help docker-build docker-build-core docker-build-ui docker-down docker-run docker-run-ui docker-run-api docker-run-benchmark
22

33
# Build variables
44
BINARY_NAME=benchmarkoor
@@ -120,13 +120,20 @@ docker-build-ui:
120120
docker-down:
121121
docker compose down
122122

123-
## docker-run: Start the UI and API services with docker-compose (UI_PORT=number to override UI port, API_PORT=number to override API port)
123+
## docker-run: Start the UI and API services with docker-compose
124+
docker-run: docker-run-ui docker-run-api
125+
126+
## docker-run-ui: Start the UI service with docker-compose (UI_PORT=number to override UI port)
124127
UI_PORT?=8080
128+
docker-run-ui:
129+
APP_VERSION=$(VERSION) UI_PORT=$(UI_PORT) docker compose up -d --build ui
130+
131+
## docker-run-api: Start the API service with docker-compose (API_PORT=number to override API port)
125132
API_PORT?=9090
126-
docker-run:
127-
UI_PORT=$(UI_PORT) API_PORT=$(API_PORT) docker compose up -d --build ui api
133+
docker-run-api:
134+
VERSION=$(VERSION) COMMIT=$(COMMIT) DATE=$(DATE) API_PORT=$(API_PORT) docker compose up -d --build api
128135

129136
## docker-run-benchmark: Start the benchmarkoor service with docker-compose (CLIENT=name to limit, CONFIG=file to override config)
130137
CONFIG?=config.example.docker.yaml
131138
docker-run-benchmark:
132-
USER_UID=$(shell id -u) USER_GID=$(shell id -g) BENCHMARKOOR_CONFIG=$(CONFIG) docker compose run --rm --build benchmarkoor run --config /app/config.yaml $(if $(CLIENT),--limit-instance-client=$(CLIENT))
139+
VERSION=$(VERSION) COMMIT=$(COMMIT) DATE=$(DATE) USER_UID=$(shell id -u) USER_GID=$(shell id -g) BENCHMARKOOR_CONFIG=$(CONFIG) docker compose run --rm --build benchmarkoor run --config /app/config.yaml $(if $(CLIENT),--limit-instance-client=$(CLIENT))

docker-compose.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ services:
44
build:
55
context: .
66
dockerfile: Dockerfile
7+
args:
8+
VERSION: ${VERSION:-dev}
9+
COMMIT: ${COMMIT:-none}
10+
DATE: ${DATE:-unknown}
711
# Required for dropping memory caches, ZFS/overlayfs datadir methods, etc.
812
privileged: true
913
# Share host PID namespace so nsenter can access /proc/<pid>/ns/net
@@ -69,6 +73,8 @@ services:
6973
build:
7074
context: .
7175
dockerfile: Dockerfile.ui
76+
args:
77+
APP_VERSION: ${APP_VERSION:-dev}
7278
ports:
7379
- "${UI_PORT:-8080}:80"
7480
volumes:

ui/src/components/layout/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function Footer() {
1616
ethpandaops/benchmarkoor
1717
</a>
1818
<span className="mx-2"></span>
19-
<span>v{appVersion}</span>
19+
<span>{appVersion}</span>
2020
</div>
2121
</footer>
2222
)

0 commit comments

Comments
 (0)