Skip to content

Commit 8d451b6

Browse files
authored
Add GitHub action to build multi-arch image (#153)
Signed-off-by: rick <[email protected]> Co-authored-by: rick <[email protected]>
1 parent a22850f commit 8d451b6

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

.github/workflows/build.yaml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Image Build
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- test-* # make it be easier for contributors to test
8+
tags:
9+
- 'v*.*.*'
10+
pull_request:
11+
branches:
12+
- 'master'
13+
14+
jobs:
15+
Build:
16+
runs-on: ubuntu-20.04
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Docker meta for KubeSphere
20+
id: meta
21+
if: github.repository_owner == 'kubesphere'
22+
uses: docker/metadata-action@v3
23+
with:
24+
images: |
25+
kubespheredev/s2ioperator
26+
ghcr.io/${{ github.repository_owner }}/s2ioperator
27+
tags: |
28+
type=schedule
29+
type=ref,event=branch
30+
type=ref,event=pr
31+
type=semver,pattern=v{{version}}
32+
type=semver,pattern=v{{major}}.{{minor}}
33+
type=semver,pattern=v{{major}}
34+
type=sha
35+
- name: Docker meta for Contributors
36+
id: metaContributors
37+
if: github.repository_owner != 'kubesphere'
38+
uses: docker/metadata-action@v3
39+
with:
40+
images: |
41+
ghcr.io/${{ github.repository_owner }}/s2ioperator
42+
tags: |
43+
type=schedule
44+
type=ref,event=branch
45+
type=ref,event=pr
46+
type=semver,pattern=v{{version}}
47+
type=semver,pattern=v{{major}}.{{minor}}
48+
type=semver,pattern=v{{major}}
49+
type=sha
50+
- name: Set up QEMU
51+
uses: docker/setup-qemu-action@v1
52+
- name: Set up Docker Buildx
53+
uses: docker/setup-buildx-action@v1
54+
- name: Login to DockerHub
55+
if: github.event_name != 'pull_request'
56+
uses: docker/login-action@v1
57+
with:
58+
username: ${{ secrets.DOCKER_HUB_USER }}
59+
password: ${{ secrets.DOCKER_HUB_SECRETS }}
60+
- name: Login to GHCR
61+
if: github.event_name != 'pull_request'
62+
uses: docker/login-action@v1
63+
with:
64+
registry: ghcr.io
65+
username: ${{ github.repository_owner }}
66+
password: ${{ secrets.GHCR_TOKEN }}
67+
- name: Build and push Docker images
68+
uses: docker/[email protected]
69+
if: github.repository_owner == 'kubesphere'
70+
with:
71+
context: .
72+
file: deploy/Dockerfile.multiarch
73+
tags: ${{ steps.meta.outputs.tags }}
74+
push: ${{ github.event_name != 'pull_request' }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
platforms: linux/amd64,linux/arm64
77+
- name: Build and push Docker images for Contributors
78+
uses: docker/[email protected]
79+
if: github.repository_owner != 'kubesphere'
80+
with:
81+
context: .
82+
file: deploy/Dockerfile.multiarch
83+
tags: ${{ steps.metaContributors.outputs.tags }}
84+
push: ${{ github.event_name != 'pull_request' }}
85+
labels: ${{ steps.metaContributors.outputs.labels }}
86+
platforms: linux/amd64,linux/arm64

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ docker-build:
5454
docker build -f deploy/Dockerfile -t $(IMG) bin/
5555
docker push $(IMG)
5656

57+
image-multiarch:
58+
docker build . -t $(IMG) -f deploy/Dockerfile.multiarch
59+
5760
debug: manager
5861
./hack/build-image.sh
5962

deploy/Dockerfile.multiarch

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM golang:1.12 AS builder
2+
3+
WORKDIR /work
4+
COPY . .
5+
RUN CGO_ENABLED=0 go build -ldflags "-w" -o bin/manager \
6+
github.com/kubesphere/s2ioperator/cmd/manager
7+
8+
FROM alpine:3.10
9+
10+
WORKDIR /
11+
COPY --from=builder /work/bin/manager manager
12+
ENTRYPOINT ["/manager"]

0 commit comments

Comments
 (0)