Skip to content

Commit a0cc993

Browse files
committed
fix(ci): optimize CI to be faster and more efficient
1 parent 95342f2 commit a0cc993

File tree

2 files changed

+103
-19
lines changed

2 files changed

+103
-19
lines changed

.github/workflows/build.yml

Lines changed: 96 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI for Native Docker Image
1+
name: Build
22

33
on:
44
push:
@@ -9,10 +9,52 @@ on:
99
- main
1010

1111
jobs:
12+
warm-cache:
13+
name: Warm Dependencies Cache
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Log in to the GitHub Container Registry
26+
if: github.event_name == 'push'
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GH_PAT }}
32+
33+
- name: Build dependencies stage
34+
uses: docker/build-push-action@v6
35+
with:
36+
context: .
37+
file: ./src/main/docker/Dockerfile.native
38+
target: dependencies
39+
platforms: linux/amd64
40+
push: ${{ github.event_name == 'push' }}
41+
cache-from: |
42+
type=gha,scope=deps
43+
type=registry,ref=ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:deps-cache
44+
cache-to: |
45+
type=gha,mode=max,scope=deps
46+
${{ github.event_name == 'push' && 'type=registry,ref=ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:deps-cache,mode=max' || '' }}
47+
tags: |
48+
${{ github.event_name == 'push' && format('ghcr.io/{0}/podmortem-log-parser:deps-cache', github.repository_owner) || '' }}
49+
build-args: |
50+
GITHUB_USER=${{ github.actor }}
51+
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
52+
1253
test-build:
13-
name: Test Build on Pull Request
54+
name: Test Build
1455
if: github.event_name == 'pull_request'
15-
runs-on: builder
56+
needs: warm-cache
57+
runs-on: ubuntu-latest
1658
steps:
1759
- name: Checkout repository
1860
uses: actions/checkout@v4
@@ -27,20 +69,31 @@ jobs:
2769
file: ./src/main/docker/Dockerfile.native
2870
platforms: linux/amd64
2971
push: false
30-
cache-from: type=gha
31-
cache-to: type=gha,mode=max
72+
cache-from: |
73+
type=gha,scope=deps
74+
type=gha,scope=build-amd64
75+
type=registry,ref=ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:deps-cache
76+
cache-to: type=gha,mode=max,scope=build-amd64
3277
build-args: |
3378
GITHUB_USER=${{ github.actor }}
3479
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
3580
36-
build-and-push:
37-
name: Build and Push on Main
81+
build-arch:
82+
name: Build ${{ matrix.arch }}
3883
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
39-
runs-on: builder
84+
needs: warm-cache
85+
runs-on: ubuntu-latest
4086
permissions:
4187
contents: read
4288
packages: write
43-
89+
strategy:
90+
matrix:
91+
arch: [amd64, arm64]
92+
include:
93+
- arch: amd64
94+
platform: linux/amd64
95+
- arch: arm64
96+
platform: linux/arm64
4497
steps:
4598
- name: Checkout repository
4699
uses: actions/checkout@v4
@@ -55,19 +108,46 @@ jobs:
55108
username: ${{ github.actor }}
56109
password: ${{ secrets.GH_PAT }}
57110

58-
- name: Build and push Docker image
59-
id: build-and-push
111+
- name: Build and push ${{ matrix.arch }} image
60112
uses: docker/build-push-action@v6
61113
with:
62114
context: .
63115
file: ./src/main/docker/Dockerfile.native
64-
platforms: linux/amd64,linux/arm64
116+
platforms: ${{ matrix.platform }}
65117
push: true
66-
cache-from: type=gha
67-
cache-to: type=gha,mode=max
118+
cache-from: |
119+
type=gha,scope=deps
120+
type=gha,scope=build-${{ matrix.arch }}
121+
type=registry,ref=ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:deps-cache
122+
cache-to: type=gha,mode=max,scope=build-${{ matrix.arch }}
68123
tags: |
69-
ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:latest
70-
ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}
124+
ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-${{ matrix.arch }}
71125
build-args: |
72126
GITHUB_USER=${{ github.actor }}
73127
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
128+
129+
create-manifest:
130+
name: Create Multi-Arch Manifest
131+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
132+
needs: build-arch
133+
runs-on: ubuntu-latest
134+
permissions:
135+
contents: read
136+
packages: write
137+
steps:
138+
- name: Log in to the GitHub Container Registry
139+
uses: docker/login-action@v3
140+
with:
141+
registry: ghcr.io
142+
username: ${{ github.actor }}
143+
password: ${{ secrets.GH_PAT }}
144+
145+
- name: Create and push multi-arch manifest
146+
run: |
147+
docker buildx imagetools create -t ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:latest \
148+
ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-amd64 \
149+
ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-arm64
150+
151+
docker buildx imagetools create -t ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }} \
152+
ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-amd64 \
153+
ghcr.io/${{ github.repository_owner }}/podmortem-log-parser:${{ github.sha }}-arm64

src/main/docker/Dockerfile.native

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM registry.access.redhat.com/quarkus/mandrel-for-jdk-21-rhel8:23.1 AS build
1+
FROM registry.access.redhat.com/quarkus/mandrel-for-jdk-21-rhel8:23.1 AS dependencies
22
WORKDIR /home/quarkus
33

44
COPY --chown=quarkus:quarkus mvnw .
55
COPY --chown=quarkus:quarkus .mvn .mvn
66
COPY --chown=quarkus:quarkus pom.xml .
7-
COPY --chown=quarkus:quarkus src src
7+
COPY --chown=quarkus:quarkus src/main/resources/settings.xml src/main/resources/settings.xml
88

99
USER quarkus
1010

@@ -13,7 +13,11 @@ ARG GITHUB_TOKEN
1313
ENV GITHUB_USER=$GITHUB_USER
1414
ENV GITHUB_TOKEN=$GITHUB_TOKEN
1515

16-
RUN ./mvnw --no-transfer-progress -s src/main/resources/settings.xml -U package -Dnative
16+
RUN ./mvnw --no-transfer-progress -s src/main/resources/settings.xml dependency:go-offline -DskipTests
17+
18+
FROM dependencies AS build
19+
COPY --chown=quarkus:quarkus src src
20+
RUN ./mvnw --no-transfer-progress -s src/main/resources/settings.xml -U package -Dnative -DskipTests
1721

1822
FROM registry.access.redhat.com/ubi9/ubi-minimal
1923

0 commit comments

Comments
 (0)