Skip to content

Commit 612019d

Browse files
committed
Use a single multi-stage Dockerfile for the UI
There is no need for two separate Dockerfiles. In fact, this only makes the setup more complex and in many cases slower. This commit merges the dev and production Dockerfiles into a single multi-stage Dockerfile. I’ve also adjusted the GitHub Actions workflow to use the official action to build the image, which should bring down build times by enabling caching.
1 parent c7689f4 commit 612019d

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

.github/workflows/build-ui.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ jobs:
2424
- name: Setup
2525
run: echo "ALEPH_SECRET=batman\n" >> aleph.env
2626

27-
- name: Build development image
28-
run: |
29-
docker build -t ghcr.io/alephdata/aleph-ui:${GITHUB_SHA} ui
30-
docker tag ghcr.io/alephdata/aleph-ui:${GITHUB_SHA} ghcr.io/alephdata/aleph-ui:latest
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Build Docker image
31+
uses: docker/build-push-action@v6
32+
with:
33+
context: ./ui
34+
push: false
35+
tags: ghcr.io/alephdata/aleph-ui-production:${{ github.sha }}
36+
cache-from: type=gha
37+
cache-to: type=gha,mode=max
3138

3239
- name: Check code formatting
3340
run: make format-check-ui
@@ -38,13 +45,6 @@ jobs:
3845
- name: Run tests
3946
run: make test-ui
4047

41-
- name: Build
42-
run: make build-ui
43-
44-
- name: Build production image
45-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
46-
run: docker build -t ghcr.io/alephdata/aleph-ui-production:${GITHUB_SHA} -f ui/Dockerfile.production ui
47-
4848
- name: Push docker image (tagged)
4949
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
5050
run: |

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ build:
7777
$(COMPOSE) build
7878

7979
build-ui:
80-
docker build -t ghcr.io/alephdata/aleph-ui-production:$(ALEPH_TAG) -f ui/Dockerfile.production ui
80+
docker build -t ghcr.io/alephdata/aleph-ui-production:$(ALEPH_TAG) -f ui/Dockerfile ui
8181

8282
build-e2e:
8383
$(COMPOSE_E2E) build --build-arg PLAYWRIGHT_VERSION=$(shell awk -F'==' '/^playwright==/ { print $$2 }' e2e/requirements.txt)

docker-compose.dev.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,17 @@ services:
138138
- aleph.env
139139

140140
ui:
141+
image: ghcr.io/alephdata/aleph-ui-production:${ALEPH_TAG:-latest}
141142
build:
142143
context: ui
143-
image: ghcr.io/alephdata/aleph-ui:${ALEPH_TAG:-latest}
144+
target: builder
144145
depends_on:
145146
- api
146-
command: "npm run start"
147+
command: "bash -c 'npm install && npm start'"
147148
ports:
148149
- "8080:8080"
149150
volumes:
150151
- "./ui:/alephui"
151-
env_file:
152-
- aleph.env
153152

154153
worker:
155154
build:

ui/Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
FROM node:23-slim
2-
ENV DEBIAN_FRONTEND noninteractive
1+
FROM node:23-slim AS builder
32

43
RUN mkdir /alephui
54
WORKDIR /alephui
@@ -8,4 +7,10 @@ COPY package.json /alephui
87
COPY package-lock.json /alephui
98

109
RUN npm ci
11-
COPY . .
10+
COPY . .
11+
RUN npm run build
12+
13+
FROM nginx:alpine
14+
15+
COPY nginx.conf /etc/nginx/nginx.conf
16+
COPY --from=builder /alephui/build /assets

ui/Dockerfile.production

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

0 commit comments

Comments
 (0)