Skip to content

Commit

Permalink
feat: build dual arch image (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
CeerDecy authored Sep 12, 2024
1 parent 2417ccd commit f16ae12
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
ARG ARCH

FROM --platform=${ARCH} registry.erda.cloud/retag/golang:1.19-bullseye as builder
FROM --platform=${TARGETARCH} registry.erda.cloud/retag/golang:1.19-bullseye as builder

ARG GO_PROJECT_ROOT
ARG GO_PROXY
Expand All @@ -19,10 +17,10 @@ RUN go mod download
COPY pkg pkg
COPY cmd cmd

RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \
go build -o bin/dice-operator cmd/dice-operator/main.go

FROM --platform=${ARCH} registry.erda.cloud/retag/debian:bullseye-slim
FROM --platform=${TARGETARCH} registry.erda.cloud/retag/debian:bullseye-slim

ARG GO_PROJECT_ROOT

Expand Down
23 changes: 9 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

GO_PROJECT_ROOT := github.com/erda-project/erda
ARCH ?= amd64
PLATFORM ?= linux/amd64,linux/arm64

REGISTRY ?= registry.erda.cloud/erda
VERSION ?= $(shell cat ./VERSION)
Expand All @@ -31,7 +32,7 @@ else
endif

build-version:
@echo Arch: ${ARCH}
@echo Arch: ${PLATFORM}
@echo Version: ${VERSION}
@echo Build Time: ${BUILD_TIME}
@echo Git Commit: ${GIT_COMMIT}
Expand All @@ -43,18 +44,12 @@ build: build-version
@echo "build dice-operator"
@CGO_ENABLED=0 GOARCH=${ARCH} go build -o bin/dice-operator-${ARCH} ./cmd/dice-operator

docker-build: build-version
@docker build -t $(IMAGE) \
--build-arg ARCH=$(ARCH) \
docker-build-push: build-version
@docker buildx create --use --platform $(PLATFORM) --driver docker-container
@docker buildx build \
--push \
--platform $(PLATFORM)\
-t $(IMAGE) \
-t $(IMAGE_VERSION_LATEST) \
--build-arg GO_PROJECT_ROOT=$(GO_PROJECT_ROOT) \
--build-arg GO_PROXY=$(GO_PROXY) .

docker-build-push: docker-build
@docker push $(IMAGE)
@echo action meta: image=$(IMAGE)

docker-version-latest: docker-build-push
@echo "retag image $(IMAGE) to $(IMAGE_VERSION_LATEST)"
@docker tag $(IMAGE) $(IMAGE_VERSION_LATEST)
@docker push $(IMAGE_VERSION_LATEST)
@echo action meta: image_version_latest=$(IMAGE_VERSION_LATEST)
2 changes: 1 addition & 1 deletion pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ stages:
commands:
- cd ${{ dirs.erda-operator }}
- docker login ${{ configs.docker_registry }} -u ${{ configs.docker_registry_username }} -p ${{ configs.docker_registry_password }}
- REGISTRY=${{ configs.docker_registry }} IMAGE_TAG=${{ outputs.extract-repo-version.image_tag }} make docker-version-latest
- REGISTRY=${{ configs.docker_registry }} IMAGE_TAG=${{ outputs.extract-repo-version.image_tag }} make docker-build-push
resources:
cpu: 2
mem: 2048

0 comments on commit f16ae12

Please sign in to comment.