Skip to content

Commit

Permalink
dockerfile support multiarch(amd64,arm64) (#83)
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>

Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>
  • Loading branch information
zmberg authored Sep 13, 2022
1 parent 5525846 commit f21c3fb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
26 changes: 26 additions & 0 deletions Dockerfile_multiarch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.16 as builder

WORKDIR /workspace

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY pkg/ pkg/

# Build
ARG TARGETOS TARGETARCH
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Platforms to build the image for
PLATFORMS ?= linux/amd64,linux/arm64

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -68,6 +70,9 @@ docker-build: ## Build docker image with the manager.
docker-push: ## Push docker image with the manager.
docker push ${IMG}

# Build and push the multiarchitecture docker images and manifest.
docker-multiarch:
docker buildx build -f ./Dockerfile_multiarch --pull --no-cache --platform=$(PLATFORMS) --push . -t $(IMG)
##@ Deployment

install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
Expand Down
6 changes: 2 additions & 4 deletions docs/tutorials/basic_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
containers:
- name: echoserver
# mac m1 should choics image can support arm64,such as image e2eteam/echoserver:2.2-linux-arm64
image: cilium/echoserver:1.10.2
image: cilium/echoserver:1.10.2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
Expand Down Expand Up @@ -107,9 +107,7 @@ spec:
trafficRoutings:
# echoserver service name
- service: echoserver
# nginx ingress
type: nginx
# echoserver ingress name
# echoserver ingress name, current only nginx ingress
ingress:
name: echoserver
```
Expand Down

0 comments on commit f21c3fb

Please sign in to comment.