Skip to content

Commit 48c87d2

Browse files
committed
🔧 Stick with save/load mechanism and also add ecr publish
1 parent e3dfdd0 commit 48c87d2

File tree

2 files changed

+328
-29
lines changed

2 files changed

+328
-29
lines changed

.github/workflows/main.yml

Lines changed: 163 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
uses: docker/setup-qemu-action@v3
4444

4545
- name: Set up Docker Buildx
46+
id: buildx
4647
uses: docker/setup-buildx-action@v3
4748

4849
- name: Cache Docker layers
@@ -53,34 +54,178 @@ jobs:
5354
restore-keys: |
5455
${{ runner.os }}-buildx-
5556
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
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: image
96+
path: /tmp/image.tar
97+
retention-days: 1
98+
99+
deploy-ghcr:
100+
runs-on: ubuntu-latest
101+
needs: build
102+
permissions:
103+
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+
56127
- name: Login to GitHub Container Registry
57128
uses: docker/login-action@v3
58129
with:
59130
registry: ghcr.io
60-
username: ${{ github.actor }}
131+
username: "${{ github.actor }}"
61132
password: ${{ secrets.GITHUB_TOKEN }}
62133

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+
63167
- name: Login to Dockerhub
64168
uses: docker/login-action@v3
65169
with:
66170
username: ${{ secrets.DOCKERHUB_USERNAME }}
67171
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 }}
68179
69-
- name: Build & push docker image
70-
id: docker_build_and_push
71-
uses: docker/build-push-action@v5
180+
181+
deploy-ecr:
182+
runs-on: ubuntu-latest
183+
needs: build
184+
permissions:
185+
contents: read # To read secrets
186+
id-token: write # This is required for requesting the JWT
187+
188+
steps:
189+
- name: Download docker image
190+
uses: actions/download-artifact@v4
72191
with:
73-
builder: ${{ steps.buildx.outputs.name }}
74-
context: api
75-
platforms: linux/amd64,linux/arm64
76-
provenance: false
77-
push: true
78-
tags: |
79-
ghcr.io/kafbat/kafka-ui:${{ steps.build.outputs.version }}
80-
ghcr.io/kafbat/kafka-ui:main
81-
kafbat/kafka-ui:${{ steps.build.outputs.version }}
82-
kafbat/kafka-ui:main
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
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 }}

0 commit comments

Comments
 (0)