Skip to content

Commit 3539df9

Browse files
authored
Update dockerfile to try and fix running on m1 macs (#37)
* Update dockerfile to try and fix running on m1 macs * Upgrade docker push action
1 parent 2b696bc commit 3539df9

File tree

5 files changed

+76
-185
lines changed

5 files changed

+76
-185
lines changed

.github/workflows/branches.yaml

Lines changed: 0 additions & 58 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- v*
9+
pull_request:
10+
branches:
11+
- main
12+
pull_request_target:
13+
types:
14+
- closed
15+
16+
env:
17+
REGISTRY: docker.io
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
jobs:
21+
test:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read # for actions/checkout to fetch code
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
29+
- name: Setup
30+
uses: actions/setup-go@v3
31+
with:
32+
go-version: 1.19.x
33+
cache: true
34+
35+
- name: Test
36+
run: make test
37+
38+
build:
39+
runs-on: ubuntu-latest
40+
permissions:
41+
contents: read # for actions/checkout to fetch code
42+
packages: write
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v3
46+
with:
47+
fetch-depth: 0 # for git describe
48+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
49+
50+
- name: Publish | Login to Docker Hub
51+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
52+
with:
53+
registry: ${{ env.REGISTRY }}
54+
username: ${{ secrets.DOCKERHUB_USERNAME }}
55+
password: ${{ secrets.DOCKERHUB_TOKEN }}
56+
57+
- name: Extract metadata (tags, labels) for Docker
58+
id: meta
59+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
60+
with:
61+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
62+
63+
- name: Build and push Docker image
64+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
65+
with:
66+
context: .
67+
push: true
68+
tags: ${{ steps.meta.outputs.tags }}
69+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/main.yaml

Lines changed: 0 additions & 88 deletions
This file was deleted.

.github/workflows/tags.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Build the manager binary
22
FROM golang:1.19 as builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
35

46
WORKDIR /workspace
57
# Copy the Go Modules manifests
@@ -15,7 +17,11 @@ COPY api/ api/
1517
COPY controllers/ controllers/
1618

1719
# Build
18-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
1925

2026
# Use distroless as minimal base image to package the manager binary
2127
# Refer to https://github.com/GoogleContainerTools/distroless for more details

0 commit comments

Comments
 (0)