Skip to content

Commit 90adbee

Browse files
authored
Add support for arm64 image (#81)
1 parent 8effe29 commit 90adbee

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,9 @@ concurrency:
3434

3535
jobs:
3636
build:
37-
if: github.repository == 'apache/cloudstack-kubernetes-provider' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
37+
if: github.repository == 'apache/cloudstack-kubernetes-provider'
3838
runs-on: ubuntu-22.04
3939
steps:
40-
- name: Login to Docker Registry
41-
uses: docker/login-action@v3
42-
with:
43-
registry: ${{ secrets.DOCKER_REGISTRY }}
44-
username: ${{ secrets.DOCKERHUB_USER }}
45-
password: ${{ secrets.DOCKERHUB_TOKEN }}
46-
4740
- name: Set Docker repository name
4841
run: echo "DOCKER_REPOSITORY=apache" >> $GITHUB_ENV
4942

@@ -57,8 +50,41 @@ jobs:
5750
- name: Set Docker image FULL TAG
5851
run: echo "FULL_TAG=$(if [ "${{ secrets.DOCKER_REGISTRY }}" = "" ];then echo ${DOCKER_REPOSITORY}/cloudstack-kubernetes-provider:${TAG};else echo ${{ secrets.DOCKER_REGISTRY }}/${DOCKER_REPOSITORY}/cloudstack-kubernetes-provider:${TAG};fi)" >> $GITHUB_ENV
5952

60-
- name: Build the Docker image for cloudstack-kubernetes-provider
61-
run: docker build . --file Dockerfile --tag ${FULL_TAG}
53+
- name: Check if should push
54+
id: should_push
55+
run: |
56+
if [ "${{ github.event_name }}" != "pull_request" ] || [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
57+
echo "should_push=true" >> $GITHUB_OUTPUT
58+
else
59+
echo "should_push=false" >> $GITHUB_OUTPUT
60+
fi
6261
63-
- name: Push Docker image to Docker Registry
64-
run: docker push ${FULL_TAG}
62+
- name: Set up Docker Buildx
63+
uses: docker/setup-buildx-action@v3
64+
65+
- name: Login to Docker Registry
66+
if: steps.should_push.outputs.should_push == 'true'
67+
uses: docker/login-action@v3
68+
with:
69+
registry: ${{ secrets.DOCKER_REGISTRY }}
70+
username: ${{ secrets.DOCKERHUB_USER }}
71+
password: ${{ secrets.DOCKERHUB_TOKEN }}
72+
73+
- name: Set cache configuration
74+
id: cache_config
75+
run: |
76+
if [ "${{ steps.should_push.outputs.should_push }}" = "true" ]; then
77+
echo "cache_from=type=registry,ref=${FULL_TAG}-cache" >> $GITHUB_OUTPUT
78+
echo "cache_to=type=registry,ref=${FULL_TAG}-cache,mode=max" >> $GITHUB_OUTPUT
79+
fi
80+
81+
- name: Build and push Docker image for cloudstack-kubernetes-provider (multi-arch)
82+
uses: docker/build-push-action@v6
83+
with:
84+
context: .
85+
file: ./Dockerfile
86+
platforms: linux/amd64,linux/arm64
87+
push: ${{ steps.should_push.outputs.should_push == 'true' }}
88+
tags: ${{ env.FULL_TAG }}
89+
cache-from: ${{ steps.cache_config.outputs.cache_from }}
90+
cache-to: ${{ steps.cache_config.outputs.cache_to }}

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
FROM golang:1.21 as builder
18+
FROM --platform=$BUILDPLATFORM golang:1.23 AS builder
19+
ARG BUILDPLATFORM
20+
ARG TARGETOS
21+
ARG TARGETARCH
1922
COPY . /go/src/github.com/apache/cloudstack-kubernetes-provider
2023
WORKDIR /go/src/github.com/apache/cloudstack-kubernetes-provider
21-
RUN make clean && CGO_ENABLED=0 GOOS=linux make
24+
RUN make clean && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} make
2225

2326
FROM gcr.io/distroless/static:nonroot
2427
COPY --from=builder /go/src/github.com/apache/cloudstack-kubernetes-provider/cloudstack-ccm /app/cloudstack-ccm

0 commit comments

Comments
 (0)