Skip to content

Commit 751ce0e

Browse files
authored
Merge pull request #1598 from neodix42/improve-docker-img-1
Speed up docker image arm64 build
1 parent 72aeec7 commit 751ce0e

File tree

2 files changed

+154
-26
lines changed

2 files changed

+154
-26
lines changed

.github/workflows/docker-ubuntu-branch-image.yml

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ env:
1111
IMAGE_NAME: ${{ github.repository }}
1212

1313
jobs:
14-
build-and-push:
15-
runs-on: ubuntu-22.04
14+
build-arm64:
15+
runs-on: ubuntu-22.04-arm
1616
steps:
1717
- name: Check out repository
1818
uses: actions/checkout@v3
1919
with:
2020
submodules: 'recursive'
2121

22+
- name: Get tag as branch name
23+
id: tag
24+
run: |
25+
echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
26+
2227
- name: Set up QEMU
2328
uses: docker/[email protected]
2429

2530
- name: Set up Docker Buildx
2631
uses: docker/[email protected]
2732
with:
28-
driver-opts: image=moby/buildkit:v0.11.0
33+
driver-opts: image=moby/buildkit:v0.20.2
2934

3035
- name: Login to GitHub Container Registry
3136
uses: docker/login-action@v3
@@ -34,28 +39,80 @@ jobs:
3439
username: ${{ github.repository_owner }}
3540
password: ${{ secrets.GITHUB_TOKEN }}
3641

37-
- name: Build and export to Docker
42+
- name: Build and push
3843
uses: docker/build-push-action@v6
3944
with:
40-
load: true
45+
platforms: linux/arm64
46+
push: true
4147
context: ./
42-
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
48+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}-arm64
4349

44-
- name: Test
45-
run: |
46-
docker run --rm -e "TEST=1" ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
50+
51+
build-amd64:
52+
runs-on: ubuntu-22.04
53+
steps:
54+
- name: Check out repository
55+
uses: actions/checkout@v3
56+
with:
57+
submodules: 'recursive'
4758

4859
- name: Get tag as branch name
4960
id: tag
5061
run: |
5162
echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
5263
64+
- name: Set up QEMU
65+
uses: docker/[email protected]
66+
67+
- name: Set up Docker Buildx
68+
uses: docker/[email protected]
69+
with:
70+
driver-opts: image=moby/buildkit:v0.20.2
71+
72+
- name: Login to GitHub Container Registry
73+
uses: docker/login-action@v3
74+
with:
75+
registry: ${{ env.REGISTRY }}
76+
username: ${{ github.repository_owner }}
77+
password: ${{ secrets.GITHUB_TOKEN }}
78+
5379
- name: Build and push
54-
id: docker_build
5580
uses: docker/build-push-action@v6
5681
with:
57-
platforms: linux/amd64,linux/arm64
82+
platforms: linux/amd64
5883
push: true
5984
context: ./
60-
tags: |
61-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}
85+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}-amd64
86+
87+
88+
merge:
89+
runs-on: ubuntu-22.04
90+
needs:
91+
- build-amd64
92+
- build-arm64
93+
steps:
94+
- name: Get tag as branch name
95+
id: tag
96+
run: |
97+
echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
98+
99+
- name: Login to GitHub Container Registry
100+
uses: docker/login-action@v3
101+
with:
102+
registry: ${{ env.REGISTRY }}
103+
username: ${{ github.repository_owner }}
104+
password: ${{ secrets.GITHUB_TOKEN }}
105+
106+
- name: Set up Docker Buildx
107+
uses: docker/[email protected]
108+
109+
- name: Create manifest list and push
110+
run: |
111+
docker buildx imagetools create \
112+
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }} \
113+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}-arm64 \
114+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}-amd64
115+
116+
- name: Inspect image
117+
run: |
118+
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}

.github/workflows/docker-ubuntu-image.yml

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ env:
1111
IMAGE_NAME: ${{ github.repository }}
1212

1313
jobs:
14-
build-and-push:
15-
runs-on: ubuntu-22.04
14+
build-arm64:
15+
runs-on: ubuntu-22.04-arm
1616
steps:
1717
- name: Check out repository
1818
uses: actions/checkout@v3
@@ -32,16 +32,47 @@ jobs:
3232
username: ${{ github.repository_owner }}
3333
password: ${{ secrets.GITHUB_TOKEN }}
3434

35-
- name: Build and export to Docker
35+
- name: Get next tag
36+
id: tag
37+
run: |
38+
git fetch --all --tags
39+
git tag -l
40+
NEW_TAG=v$(date +'%Y.%m')
41+
FOUND=$(git tag -l | grep $NEW_TAG | wc -l)
42+
if [ $FOUND -eq 0 ]; then
43+
echo "TAG=$NEW_TAG" >> $GITHUB_OUTPUT
44+
else
45+
echo "TAG=$NEW_TAG-$FOUND" >> $GITHUB_OUTPUT
46+
fi
47+
48+
- name: Build and push
3649
uses: docker/build-push-action@v6
3750
with:
38-
load: true
51+
platforms: linux/arm64
52+
push: true
3953
context: ./
40-
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
54+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}-arm64
4155

42-
- name: Test
43-
run: |
44-
docker run --rm -e "TEST=1" ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
56+
build-amd64:
57+
runs-on: ubuntu-22.04
58+
steps:
59+
- name: Check out repository
60+
uses: actions/checkout@v3
61+
with:
62+
submodules: 'recursive'
63+
64+
- name: Set up QEMU
65+
uses: docker/[email protected]
66+
67+
- name: Set up Docker Buildx
68+
uses: docker/[email protected]
69+
70+
- name: Login to GitHub Container Registry
71+
uses: docker/login-action@v3
72+
with:
73+
registry: ${{ env.REGISTRY }}
74+
username: ${{ github.repository_owner }}
75+
password: ${{ secrets.GITHUB_TOKEN }}
4576

4677
- name: Get next tag
4778
id: tag
@@ -57,12 +88,52 @@ jobs:
5788
fi
5889
5990
- name: Build and push
60-
id: docker_build
6191
uses: docker/build-push-action@v6
6292
with:
63-
platforms: linux/amd64,linux/arm64
93+
platforms: linux/amd64
6494
push: true
6595
context: ./
66-
tags: |
67-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
68-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}
96+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}-amd64
97+
98+
merge:
99+
runs-on: ubuntu-22.04
100+
needs:
101+
- build-amd64
102+
- build-arm64
103+
steps:
104+
- name: Check out repository
105+
uses: actions/checkout@v3
106+
107+
- name: Get next tag
108+
id: tag
109+
run: |
110+
git fetch --all --tags
111+
git tag -l
112+
NEW_TAG=v$(date +'%Y.%m')
113+
FOUND=$(git tag -l | grep $NEW_TAG | wc -l)
114+
if [ $FOUND -eq 0 ]; then
115+
echo "TAG=$NEW_TAG" >> $GITHUB_OUTPUT
116+
else
117+
echo "TAG=$NEW_TAG-$FOUND" >> $GITHUB_OUTPUT
118+
fi
119+
120+
- name: Login to GitHub Container Registry
121+
uses: docker/login-action@v3
122+
with:
123+
registry: ${{ env.REGISTRY }}
124+
username: ${{ github.repository_owner }}
125+
password: ${{ secrets.GITHUB_TOKEN }}
126+
127+
- name: Set up Docker Buildx
128+
uses: docker/[email protected]
129+
130+
- name: Create manifest list and push
131+
run: |
132+
docker buildx imagetools create \
133+
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
134+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}-arm64 \
135+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.TAG }}-amd64
136+
137+
- name: Inspect image
138+
run: |
139+
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

0 commit comments

Comments
 (0)