Skip to content

Commit 4c99a1c

Browse files
authored
Merge pull request #614 from Northeastern-Electric-Racing/613-speed-up-client-build
#613 Speed up client-build: hoist ng build out of Docker
2 parents 7da70ed + 0b484f2 commit 4c99a1c

2 files changed

Lines changed: 55 additions & 38 deletions

File tree

.github/workflows/client-build.yml

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,58 @@
1-
#
21
name: Create and publish client docker image
32

43
on:
54
workflow_dispatch:
65

7-
8-
9-
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
106
env:
117
REGISTRY: ghcr.io
12-
IMAGE_NAME: ${{ github.repository }}
8+
IMAGE_NAME: northeastern-electric-racing/argos-client
139

14-
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
1510
jobs:
16-
build-and-push-image:
17-
runs-on: ubuntu-latest
18-
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
11+
build-and-push:
12+
runs-on: ubuntu-24.04
1913
permissions:
2014
contents: read
2115
packages: write
22-
#
16+
defaults:
17+
run:
18+
working-directory: ./angular-client
2319
steps:
24-
- name: Set up Docker Buildx
25-
uses: docker/setup-buildx-action@v4.0.0
26-
- name: Checkout repository
27-
uses: actions/checkout@v6
28-
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
29-
- name: Log in to the Container registry
30-
uses: docker/login-action@v4.0.0
20+
- uses: actions/checkout@v6
21+
22+
- uses: actions/setup-node@v6
23+
with:
24+
node-version: 20.17.0
25+
26+
- name: Install deps
27+
run: npm ci
28+
29+
- name: Build production bundle
30+
run: npm run build:production
31+
32+
# Stage dist where Dockerfile.prebuilt expects it; /dist is in .dockerignore,
33+
# so the docker context can't pull from dist/angular-client/browser directly.
34+
- name: Stage dist into docker context
35+
run: cp -r dist/angular-client/browser browser
36+
37+
- uses: docker/setup-qemu-action@v3
38+
with:
39+
platforms: arm64
40+
41+
- uses: docker/setup-buildx-action@v4.0.0
42+
43+
- uses: docker/login-action@v4.0.0
3144
with:
3245
registry: ${{ env.REGISTRY }}
3346
username: ${{ github.actor }}
3447
password: ${{ secrets.GITHUB_TOKEN }}
35-
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
36-
- name: Extract metadata (tags, labels) for Docker
37-
id: meta
38-
uses: docker/metadata-action@v6.0.0
39-
with:
40-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-client
41-
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
42-
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
43-
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
44-
- name: Build and push Docker image for angular client
45-
uses: docker/build-push-action@v7.0.0
48+
49+
# Multi-arch in one buildx push — apk add gettext is the only RUN, fine under QEMU.
50+
# All real CPU work (ng build) ran natively above; arch-sensitive part is just the nginx base layer.
51+
- uses: docker/build-push-action@v7.0.0
4652
with:
4753
context: ./angular-client
54+
file: ./angular-client/Dockerfile.prebuilt
4855
push: true
49-
target: production
50-
platforms: linux/arm64,linux/amd64
51-
tags: ${{ steps.meta.outputs.tags }}
52-
labels: ${{ steps.meta.outputs.labels }}
53-
# for caching
54-
# cache-from: type=gha,scope=global
55-
# cache-to: type=gha,mode=max,scope=global
56-
# https://github.com/docker/build-push-action/issues/820
56+
platforms: linux/amd64,linux/arm64
57+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
5758
provenance: false
58-
build-args: |
59-
PROD=true

angular-client/Dockerfile.prebuilt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Used by .github/workflows/client-build.yml — expects the Angular production
2+
# bundle to already be built on the runner and staged at browser/.
3+
# For local/compose builds that build from source, use Dockerfile.
4+
FROM nginx:alpine
5+
6+
RUN apk add --no-cache gettext
7+
8+
WORKDIR /usr/share/nginx/html
9+
10+
COPY browser/ .
11+
COPY nginx.conf /etc/nginx/conf.d/default.conf
12+
COPY env.prod.js ./assets/env.prod.js
13+
COPY --chmod=755 entrypoint.sh /entrypoint.sh
14+
15+
EXPOSE 80
16+
17+
ENTRYPOINT ["/entrypoint.sh"]
18+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)