Skip to content

Commit 4f18d26

Browse files
authored
Merge pull request #583 from raghavyuva/parallel-build-manager-workflow
feat: optimize CI/CD with parallel builds, BuildKit cache mounts, and registry caching
2 parents feabafa + 941929d commit 4f18d26

File tree

4 files changed

+78
-34
lines changed

4 files changed

+78
-34
lines changed

.github/workflows/build_container.yml

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
types: [published]
1313
workflow_dispatch:
1414

15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
1519
env:
1620
REGISTRY: ghcr.io
1721
API_IMAGE: ${{ github.repository }}-api
@@ -20,7 +24,7 @@ env:
2024
NEXT_PUBLIC_PORT: 7443
2125

2226
jobs:
23-
build-and-push:
27+
build-and-push-api:
2428
runs-on: ubuntu-latest
2529
permissions:
2630
contents: read
@@ -33,23 +37,16 @@ jobs:
3337
fetch-depth: 0
3438
ssh-key: ${{ secrets.DEPLOY_KEY }}
3539

36-
- name: Create .env files
37-
run: |
38-
cp .env.sample api/.env
39-
cp .env.sample view/.env
40+
- name: Create .env file
41+
run: cp .env.sample api/.env
4042

4143
- name: Set up Docker Buildx
4244
uses: docker/setup-buildx-action@v3
4345
with:
4446
platforms: linux/amd64,linux/arm64
45-
46-
- name: Cache Docker layers
47-
uses: actions/cache@v4
48-
with:
49-
path: /tmp/.buildx-cache
50-
key: ${{ runner.os }}-buildx-${{ github.sha }}
51-
restore-keys: |
52-
${{ runner.os }}-buildx-
47+
driver-opts: |
48+
image=moby/buildkit:latest
49+
network=host
5350
5451
- name: Log in to the Container registry
5552
uses: docker/login-action@v3
@@ -79,13 +76,39 @@ jobs:
7976
labels: ${{ steps.meta-api.outputs.labels }}
8077
build-args: |
8178
API_PORT=${{ env.API_PORT }}
82-
cache-from: type=local,src=/tmp/.buildx-cache
83-
cache-to: type=local,dest=/tmp/.buildx-cache-new
79+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.API_IMAGE }}:buildcache
80+
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.API_IMAGE }}:buildcache,mode=max
81+
82+
build-and-push-view:
83+
runs-on: ubuntu-latest
84+
permissions:
85+
contents: read
86+
packages: write
87+
88+
steps:
89+
- name: Checkout repository
90+
uses: actions/checkout@v4
91+
with:
92+
fetch-depth: 0
93+
ssh-key: ${{ secrets.DEPLOY_KEY }}
8494

85-
- name: Move cache
86-
run: |
87-
rm -rf /tmp/.buildx-cache
88-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
95+
- name: Create .env file
96+
run: cp .env.sample view/.env
97+
98+
- name: Set up Docker Buildx
99+
uses: docker/setup-buildx-action@v3
100+
with:
101+
platforms: linux/amd64,linux/arm64
102+
driver-opts: |
103+
image=moby/buildkit:latest
104+
network=host
105+
106+
- name: Log in to the Container registry
107+
uses: docker/login-action@v3
108+
with:
109+
registry: ${{ env.REGISTRY }}
110+
username: ${{ github.actor }}
111+
password: ${{ secrets.GITHUB_TOKEN }}
89112

90113
- name: Extract metadata for View
91114
id: meta-view
@@ -108,10 +131,5 @@ jobs:
108131
labels: ${{ steps.meta-view.outputs.labels }}
109132
build-args: |
110133
NEXT_PUBLIC_PORT=${{ env.NEXT_PUBLIC_PORT }}
111-
cache-from: type=local,src=/tmp/.buildx-cache
112-
cache-to: type=local,dest=/tmp/.buildx-cache-new
113-
114-
- name: Move cache
115-
run: |
116-
rm -rf /tmp/.buildx-cache
117-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
134+
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.VIEW_IMAGE }}:buildcache
135+
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.VIEW_IMAGE }}:buildcache,mode=max

api/.dockerignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.git
2+
.gitignore
3+
README.md
4+
*.md
5+
*.log
6+
.env
7+
.env.*
8+
Dockerfile
9+
Dockerfile.*
10+
.dockerignore
11+
bin/
12+
tmp/
13+
.vscode
14+
.idea
15+
coverage
16+
test
17+
tests
18+
*_test.go
19+
*.test
20+
doc/

api/Dockerfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
FROM golang:1.25-alpine AS builder
22
ARG API_PORT
3+
ARG TARGETOS
4+
ARG TARGETARCH
35
RUN apk add --no-cache --no-scripts make git
46

57
WORKDIR /app
68

9+
# Cache dependencies separately
710
COPY go.mod go.sum ./
8-
RUN go mod download
11+
RUN --mount=type=cache,target=/go/pkg/mod \
12+
go mod download
913

14+
# Copy source code
1015
COPY . .
11-
COPY ./migrations /app/migrations
12-
COPY ./templates /app/templates
1316

14-
RUN make build
17+
# Build with cache mounts and cross-compilation
18+
RUN --mount=type=cache,target=/go/pkg/mod \
19+
--mount=type=cache,target=/root/.cache/go-build \
20+
GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build
1521

1622
FROM alpine:3.18
1723
ARG API_PORT

view/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ FROM node:18-alpine AS deps
22
RUN apk add --no-cache libc6-compat
33
WORKDIR /app
44
COPY package.json yarn.lock ./
5-
RUN yarn install --frozen-lockfile --network-timeout 600000 --production=false && \
6-
yarn cache clean
5+
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn \
6+
yarn install --frozen-lockfile --network-timeout 600000 --production=false
77

88
FROM node:18-alpine AS builder
99
WORKDIR /app
@@ -15,8 +15,8 @@ ENV NEXT_TELEMETRY_DISABLED=1
1515
ENV PORT=$NEXT_PUBLIC_PORT
1616
ENV NEXT_PUBLIC_PORT=$NEXT_PUBLIC_PORT
1717

18-
RUN yarn build && \
19-
rm -rf node_modules/.cache
18+
RUN --mount=type=cache,target=/app/.next/cache \
19+
yarn build
2020

2121
FROM node:18-alpine AS runner
2222
WORKDIR /app

0 commit comments

Comments
 (0)