Skip to content

Commit f3f57d8

Browse files
committed
Feat/test split (#1)
* ♻️ Split actions into composable ones
1 parent 48c87d2 commit f3f57d8

File tree

7 files changed

+373
-373
lines changed

7 files changed

+373
-373
lines changed

.github/workflows/docker_build.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: "Docker build"
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
sha:
7+
required: true
8+
type: string
9+
version:
10+
required: true
11+
type: string
12+
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
ref: ${{ github.event.pull_request.head.sha }}
26+
token: ${{ github.token }}
27+
28+
- name: Download maven artifacts
29+
uses: actions/download-artifact@v4
30+
with:
31+
name: kafbat-ui-${{ inputs.version }}
32+
path: api/target
33+
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v3
36+
37+
- name: Set up Docker Buildx
38+
id: buildx
39+
uses: docker/setup-buildx-action@v3
40+
41+
- name: Cache Docker layers
42+
uses: actions/cache@v4
43+
with:
44+
path: /tmp/.buildx-cache
45+
key: ${{ runner.os }}-buildx-${{ inputs.sha }}
46+
restore-keys: |
47+
${{ runner.os }}-buildx-
48+
49+
# Build multi platform images and loading them at the same time is not possible with default container runtime : https://github.com/docker/buildx/issues/59
50+
# So let's use containerd instead as it supports this option
51+
# Also containerd is one of the option to allow preserving provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations
52+
- name: Setup docker with containerd
53+
uses: crazy-max/ghaction-setup-docker@v3
54+
with:
55+
daemon-config: |
56+
{
57+
"features": {
58+
"containerd-snapshotter": true
59+
}
60+
}
61+
62+
- name: debug
63+
run: |
64+
ls -laRh api/target
65+
66+
- name: Build docker image
67+
id: docker_build
68+
uses: docker/build-push-action@v5
69+
with:
70+
builder: ${{ steps.buildx.outputs.name }}
71+
context: api
72+
platforms: linux/amd64,linux/arm64
73+
provenance: mode=min
74+
sbom: true
75+
push: false
76+
load: true
77+
tags: |
78+
kafka-ui:temp
79+
build-args: |
80+
JAR_FILE=api-${{ inputs.version }}.jar
81+
cache-from: type=local,src=/tmp/.buildx-cache
82+
cache-to: type=local,dest=/tmp/.buildx-cache
83+
84+
- name: Dump docker image
85+
run: |
86+
docker image save kafka-ui:temp > /tmp/image.tar
87+
88+
- name: Upload docker image
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: image
92+
path: /tmp/image.tar
93+
retention-days: 1

.github/workflows/docker_publish.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
name: "Docker publish"
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
version:
8+
required: true
9+
type: string
10+
generic_tag:
11+
required: true
12+
type: string
13+
jobs:
14+
15+
# load-image:
16+
# runs-on: ubuntu-latest
17+
# steps:
18+
# - name: Download docker image
19+
# uses: actions/download-artifact@v4
20+
# with:
21+
# name: image
22+
# path: /tmp
23+
24+
# # setup containerd to preserve provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations
25+
# - name: Setup docker with containerd
26+
# uses: crazy-max/ghaction-setup-docker@v3
27+
# with:
28+
# daemon-config: |
29+
# {
30+
# "features": {
31+
# "containerd-snapshotter": true
32+
# }
33+
# }
34+
35+
# - name: Load docker image into daemon
36+
# run: |
37+
# docker load --input /tmp/image.tar
38+
39+
deploy-ghcr:
40+
permissions:
41+
packages: write
42+
uses: ./.github/workflows/publish_ghcr.yml
43+
secrets: inherit
44+
with:
45+
version: ${{ inputs.version }}
46+
generic_tag: ${{ inputs.generic_tag }}
47+
48+
deploy-dockerhub:
49+
uses: ./.github/workflows/publish_dockerhub.yml
50+
secrets: inherit
51+
with:
52+
version: ${{ inputs.version }}
53+
generic_tag: ${{ inputs.generic_tag }}
54+
55+
deploy-ecr:
56+
uses: ./.github/workflows/publish_ecr.yml
57+
permissions:
58+
contents: read # To read secrets
59+
id-token: write # This is required for requesting the JWT
60+
secrets: inherit
61+
with:
62+
version: ${{ inputs.version }}
63+
generic_tag: ${{ inputs.generic_tag }}

.github/workflows/main.yml

Lines changed: 26 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ permissions:
99
contents: read
1010

1111
jobs:
12-
build:
12+
jar-build:
1313
runs-on: ubuntu-latest
14+
1415
permissions:
1516
contents: read
1617
packages: write
1718

19+
outputs:
20+
version: ${{steps.build.outputs.version}}
21+
1822
steps:
1923
- name: Checkout
2024
uses: actions/checkout@v4
@@ -37,195 +41,32 @@ jobs:
3741
export VERSION=$(./mvnw -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
3842
echo "version=${VERSION}" >> $GITHUB_OUTPUT
3943
40-
# docker images
41-
42-
- name: Set up QEMU
43-
uses: docker/setup-qemu-action@v3
44-
45-
- name: Set up Docker Buildx
46-
id: buildx
47-
uses: docker/setup-buildx-action@v3
48-
49-
- name: Cache Docker layers
50-
uses: actions/cache@v4
51-
with:
52-
path: /tmp/.buildx-cache
53-
key: ${{ runner.os }}-buildx-${{ github.sha }}
54-
restore-keys: |
55-
${{ runner.os }}-buildx-
56-
57-
# Build multi platform images and loading them at the same time is not possible with default container runtime : https://github.com/docker/buildx/issues/59
58-
# So let's use containerd instead as it supports this option
59-
# Also containerd is one of the option to allow preserving provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations
60-
- name: Setup docker with containerd
61-
uses: crazy-max/ghaction-setup-docker@v3
62-
with:
63-
daemon-config: |
64-
{
65-
"features": {
66-
"containerd-snapshotter": true
67-
}
68-
}
69-
70-
- name: Build docker image
71-
id: docker_build
72-
uses: docker/build-push-action@v5
73-
with:
74-
builder: ${{ steps.buildx.outputs.name }}
75-
context: api
76-
platforms: linux/amd64,linux/arm64
77-
provenance: mode=min
78-
sbom: true
79-
push: false
80-
load: true
81-
tags: |
82-
kafka-ui:temp
83-
build-args: |
84-
JAR_FILE=api-${{ steps.build.outputs.version }}.jar
85-
cache-from: type=local,src=/tmp/.buildx-cache
86-
cache-to: type=local,dest=/tmp/.buildx-cache
87-
88-
- name: Dump docker image
89-
run: |
90-
docker image save kafka-ui:temp > /tmp/image.tar
91-
92-
- name: Upload docker image
44+
- name: Upload jar
9345
uses: actions/upload-artifact@v4
9446
with:
95-
name: image
96-
path: /tmp/image.tar
97-
retention-days: 1
47+
name: kafbat-ui-${{ steps.build.outputs.version }}
48+
path: api/target/api-${{ steps.build.outputs.version }}.jar
49+
retention-days: 7
9850

99-
deploy-ghcr:
100-
runs-on: ubuntu-latest
101-
needs: build
51+
docker-build:
52+
needs: jar-build
10253
permissions:
54+
contents: read
10355
packages: write
104-
105-
steps:
106-
- name: Download docker image
107-
uses: actions/download-artifact@v4
108-
with:
109-
name: image
110-
path: /tmp
111-
112-
# setup containerd to preserve provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations
113-
- name: Setup docker with containerd
114-
uses: crazy-max/ghaction-setup-docker@v3
115-
with:
116-
daemon-config: |
117-
{
118-
"features": {
119-
"containerd-snapshotter": true
120-
}
121-
}
122-
123-
- name: Load docker image into daemon
124-
run: |
125-
docker load --input /tmp/image.tar
126-
127-
- name: Login to GitHub Container Registry
128-
uses: docker/login-action@v3
129-
with:
130-
registry: ghcr.io
131-
username: "${{ github.actor }}"
132-
password: ${{ secrets.GITHUB_TOKEN }}
133-
134-
- name: Push images to GHCR
135-
run: |
136-
docker tag kafka-ui:temp ghcr.io/kafbat/kafka-ui:main
137-
docker tag kafka-ui:temp ghcr.io/kafbat/kafka-ui:${{ needs.build.outputs.version }}
138-
docker push ghcr.io/kafbat/kafka-ui:main
139-
docker push ghcr.io/kafbat/kafka-ui:${{ needs.build.outputs.version }}
140-
141-
deploy-dockerhub:
142-
runs-on: ubuntu-latest
143-
needs: build
144-
145-
steps:
146-
- name: Download docker image
147-
uses: actions/download-artifact@v4
148-
with:
149-
name: image
150-
path: /tmp
151-
152-
# setup containerd to preserve provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations
153-
- name: Setup docker with containerd
154-
uses: crazy-max/ghaction-setup-docker@v3
155-
with:
156-
daemon-config: |
157-
{
158-
"features": {
159-
"containerd-snapshotter": true
160-
}
161-
}
162-
163-
- name: Load docker image into daemon
164-
run: |
165-
docker load --input /tmp/image.tar
166-
167-
- name: Login to Dockerhub
168-
uses: docker/login-action@v3
169-
with:
170-
username: ${{ secrets.DOCKERHUB_USERNAME }}
171-
password: ${{ secrets.DOCKERHUB_TOKEN }}
172-
173-
- name: Push images to dockerhub
174-
run: |
175-
docker tag kafka-ui:temp docker.io/kafbat/kafka-ui:main
176-
docker tag kafka-ui:temp docker.io/kafbat/kafka-ui:${{ needs.build.outputs.version }}
177-
docker push docker.io/kafbat/kafka-ui:main
178-
docker push docker.io/kafbat/kafka-ui:${{ needs.build.outputs.version }}
179-
180-
181-
deploy-ecr:
182-
runs-on: ubuntu-latest
183-
needs: build
56+
uses: ./.github/workflows/docker_build.yml
57+
secrets: inherit
58+
with:
59+
sha: ${{ github.sha }}
60+
version: ${{ needs.jar-build.outputs.version }}
61+
62+
docker-deploy:
63+
needs: [jar-build, docker-build]
18464
permissions:
18565
contents: read # To read secrets
18666
id-token: write # This is required for requesting the JWT
187-
188-
steps:
189-
- name: Download docker image
190-
uses: actions/download-artifact@v4
191-
with:
192-
name: image
193-
path: /tmp
194-
195-
# setup containerd to preserve provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations
196-
- name: Setup docker with containerd
197-
uses: crazy-max/ghaction-setup-docker@v3
198-
with:
199-
daemon-config: |
200-
{
201-
"features": {
202-
"containerd-snapshotter": true
203-
}
204-
}
205-
206-
- name: Load docker image into daemon
207-
run: |
208-
docker load --input /tmp/image.tar
209-
210-
- name: Configure AWS credentials
211-
uses: aws-actions/configure-aws-credentials@v4
212-
with:
213-
aws-region: us-east-1 # This region only for public ECR
214-
role-to-assume: ${{ secrets.AWS_ROLE }}
215-
216-
- name: Login to public ECR
217-
id: login-ecr-public
218-
uses: aws-actions/amazon-ecr-login@v2
219-
with:
220-
registry-type: public
221-
222-
- name: Push to ECR
223-
env:
224-
REGISTRY: ${{steps.login-ecr-public.outputs.registry }}
225-
REGISTRY_ALIAS: j4u0y1h1
226-
REPOSITORY: kafka-ui
227-
run: |
228-
docker tag kafka-ui:temp $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:main
229-
docker tag kafka-ui:temp $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:${{ needs.build.outputs.version }}
230-
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:main
231-
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:${{ needs.build.outputs.version }}
67+
packages: write
68+
uses: ./.github/workflows/docker_publish.yml
69+
secrets: inherit
70+
with:
71+
version: ${{ needs.jar-build.outputs.version }}
72+
generic_tag: main

0 commit comments

Comments
 (0)