Skip to content

Commit

Permalink
feat: optimize ci (#89)
Browse files Browse the repository at this point in the history
Signed-off-by: iutx <[email protected]>
  • Loading branch information
iutx authored Oct 11, 2023
1 parent f4fbbcd commit 2417ccd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG ARCH

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

ARG GO_PROJECT_ROOT
ARG GO_PROXY
Expand All @@ -12,8 +12,7 @@ ENV GOPATH=/go

RUN go env -w GOPROXY=${GO_PROXY}

COPY go.mod go.mod
COPY go.sum go.sum
COPY go.mod go.sum ./

RUN go mod download

Expand All @@ -23,7 +22,7 @@ COPY cmd cmd
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
go build -o bin/dice-operator cmd/dice-operator/main.go

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

ARG GO_PROJECT_ROOT

Expand Down
30 changes: 19 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ ARCH ?= amd64

REGISTRY ?= registry.erda.cloud/erda
VERSION ?= $(shell cat ./VERSION)
BUILD_TIME ?= $(shell date -u '+%Y-%m-%d %H:%M:%S')
GIT_SHORT_COMMIT ?= $(shell git rev-parse --short HEAD)
GIT_COMMIT ?= $(shell git rev-parse HEAD)
IMG ?= ${REGISTRY}/dice-operator:${VERSION}-$(shell date '+%Y%m%d')-${GIT_SHORT_COMMIT}
BUILD_TIME := $(shell date -u '+%Y-%m-%d %H:%M:%S')
GIT_SHORT_COMMIT := $(shell git rev-parse --short HEAD)
GIT_COMMIT := $(shell git rev-parse HEAD)
DEFAULT_IMAGE_TAG := ${VERSION}-$(shell date -u +"%Y%m%d%H%M%S")-${GIT_SHORT_COMMIT}
IMAGE_TAG ?= $(DEFAULT_IMAGE_TAG)
IMAGE := ${REGISTRY}/dice-operator:$(IMAGE_TAG)
IMAGE_VERSION_LATEST := ${REGISTRY}/dice-operator:${VERSION}

ifeq ($(GO_PROXY_ENV),)
GO_PROXY := "https://goproxy.cn,direct"
Expand All @@ -32,7 +35,7 @@ build-version:
@echo Version: ${VERSION}
@echo Build Time: ${BUILD_TIME}
@echo Git Commit: ${GIT_COMMIT}
@echo IMG: ${IMG}
@echo Image: ${IMAGE}

default: build

Expand All @@ -41,12 +44,17 @@ build: build-version
@CGO_ENABLED=0 GOARCH=${ARCH} go build -o bin/dice-operator-${ARCH} ./cmd/dice-operator

docker-build: build-version
@docker build -t ${IMG} \
--build-arg ARCH=$(ARCH) \
--build-arg GO_PROJECT_ROOT=$(GO_PROJECT_ROOT) \
@docker build -t $(IMAGE) \
--build-arg ARCH=$(ARCH) \
--build-arg GO_PROJECT_ROOT=$(GO_PROJECT_ROOT) \
--build-arg GO_PROXY=$(GO_PROXY) .

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

docker-build-push: docker-build docker-push
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)
19 changes: 2 additions & 17 deletions pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,7 @@ stages:
commands:
- cd ${{ dirs.erda-operator }}
- docker login ${{ configs.docker_registry }} -u ${{ configs.docker_registry_username }} -p ${{ configs.docker_registry_password }}
- GO_PROXY_ENV=https://goproxy.cn/ REGISTRY_HOST=${{ configs.docker_registry }} IMAGE_TAG=${{ outputs.extract-repo-version.image_tag }} make push
- REGISTRY=${{ configs.docker_registry }} IMAGE_TAG=${{ outputs.extract-repo-version.image_tag }} make docker-version-latest
resources:
cpu: 2
mem: 2048
- stage:
- custom-script:
alias: retag-erda-operator-image
version: "1.0"
commands:
- cd ${erda-operator}
- docker pull ${{ outputs.build-erda-operator.image }}
- docker login ${{ configs.docker_registry }} -u ${{ configs.docker_registry_username }} -p ${{ configs.docker_registry_password }}
- export new_image=${{ configs.docker_registry }}/dice-operator:${{ outputs.extract-repo-version.version }}
- docker tag ${{ outputs.build-erda-operator.image }} $new_image
- docker push $new_image
- echo "action meta:image=$new_image"
resources:
cpu: 2
mem: 2048
mem: 2048

0 comments on commit 2417ccd

Please sign in to comment.