Skip to content

Commit f5dfa13

Browse files
feat(ci): use multi-layer build caching for frontend container
1 parent b4403e4 commit f5dfa13

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

.github/workflows/release-containers.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,44 @@ jobs:
3030
3131
echo "Using: ${DOCKER_REPOSITORY}/*:${DOCKER_TAG}"
3232
33-
- name: 'Pull latest existing Docker container image: backend'
33+
- name: 'Pull previous Docker container image: backend:latest'
3434
run: docker pull "${DOCKER_REPOSITORY}/backend:latest" || true
3535

36-
- name: 'Pull latest existing Docker container image: frontend'
36+
- name: 'Pull previous Docker container image: frontend:latest-builder'
37+
run: docker pull "${DOCKER_REPOSITORY}/frontend:latest-builder" || true
38+
39+
- name: 'Pull previous Docker container image: frontend:latest'
3740
run: docker pull "${DOCKER_REPOSITORY}/frontend:latest" || true
3841

39-
- name: 'Build Docker container image: backend'
42+
- name: 'Build Docker container image: backend:latest'
4043
run: |
4144
docker build \
4245
--cache-from "${DOCKER_REPOSITORY}/backend:latest" \
4346
--tag "${DOCKER_REPOSITORY}/backend:latest" \
4447
--tag "${DOCKER_REPOSITORY}/backend:${DOCKER_TAG}" \
4548
.
4649
47-
- name: 'Build Docker container image: frontend'
50+
- name: 'Build Docker container image: frontend:latest-builder'
51+
run: |
52+
docker build \
53+
--target builder \
54+
--cache-from "${DOCKER_REPOSITORY}/frontend:latest-builder" \
55+
--tag "${DOCKER_REPOSITORY}/frontend:latest-builder" \
56+
frontend
57+
58+
- name: 'Build Docker container image: frontend:latest'
4859
run: |
4960
docker build \
61+
--target runtime \
62+
--cache-from "${DOCKER_REPOSITORY}/frontend:latest-builder" \
5063
--cache-from "${DOCKER_REPOSITORY}/frontend:latest" \
5164
--tag "${DOCKER_REPOSITORY}/frontend:latest" \
5265
--tag "${DOCKER_REPOSITORY}/frontend:${DOCKER_TAG}" \
5366
frontend
5467
68+
- name: Push Docker container image frontend:latest-builder"
69+
run: docker push "${DOCKER_REPOSITORY}/frontend:latest-builder"
70+
5571
- name: Push Docker container image frontend:latest"
5672
run: docker push "${DOCKER_REPOSITORY}/frontend:latest"
5773

frontend/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FROM node:10-alpine
1+
FROM node:10-alpine as builder
22
WORKDIR app
33
COPY ./ /app
44
RUN yarn && yarn build
55

6-
FROM nginx:alpine
7-
COPY --from=0 /app/dist /usr/share/nginx/html
6+
FROM nginx:alpine as runtime
7+
COPY --from=builder /app/dist /usr/share/nginx/html

0 commit comments

Comments
 (0)