Skip to content

Commit

Permalink
feat: add ARM docker image build (#45)
Browse files Browse the repository at this point in the history
* style: as -> AS in Dockerfile

* feat: add TARGETARCH for go build

* feat: use Github action for docker image build

* chore: add default TARGETARCH=amd64 for Makefile
  • Loading branch information
kanya-approve committed Nov 25, 2023
1 parent 2b611bd commit c3f8ee5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
57 changes: 35 additions & 22 deletions .github/workflows/release-container-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,45 @@ on:
workflow_dispatch: {}
push:
tags:
- v*
- v*

jobs:
build:
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- name: "Extract Version"
id: extract_version
run: |
GIT_TAG=${GITHUB_REF##*/}
VERSION=${GIT_TAG##v}
echo "::set-output name=version::$(echo $VERSION)"
- uses: actions/checkout@v2
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the Docker image
run: make image
- name: Push docker image to ghcr.io
env:
VERSION: ${{ steps.extract_version.outputs.version }}
run: |
docker tag ghcr.io/strrl/cloudflare-tunnel-ingress-controller:latest ghcr.io/strrl/cloudflare-tunnel-ingress-controller:$VERSION
docker push ghcr.io/strrl/cloudflare-tunnel-ingress-controller:$VERSION
- uses: actions/checkout@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/${{ github.repository_owner }}/cloudflare-tunnel-ingress-controller
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
file: image/cloudflare-tunnel-ingress-controller/Dockerfile
platforms: linux/amd64,linux/arm,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dev:

.PHONY: image
image:
DOCKER_BUILDKIT=1 docker build -t ghcr.io/strrl/cloudflare-tunnel-ingress-controller -f ./image/cloudflare-tunnel-ingress-controller/Dockerfile .
DOCKER_BUILDKIT=1 TARGETARCH=amd64 docker build -t ghcr.io/strrl/cloudflare-tunnel-ingress-controller -f ./image/cloudflare-tunnel-ingress-controller/Dockerfile .

.PHONY: unit-test
unit-test:
Expand Down
4 changes: 2 additions & 2 deletions image/cloudflare-tunnel-ingress-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.20 as builder
FROM golang:1.20 AS builder

WORKDIR /workspace

Expand All @@ -10,7 +10,7 @@ RUN go mod download && go mod verify
# Build
COPY . .
RUN --mount=type=cache,target=/go \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on \
CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH GO111MODULE=on \
go build -o cloudflare-tunnel-ingress-controller ./cmd/cloudflare-tunnel-ingress-controller

# Use distroless as minimal base image to package the manager binary
Expand Down

0 comments on commit c3f8ee5

Please sign in to comment.