Skip to content

Commit

Permalink
release:update makefile (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored May 19, 2023
1 parent 9fbd31d commit 6037cda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
env:
DOCKER_TAG: ${{ steps.get_version.outputs.VERSION }}
run: |
make all-nologin REPO=polarismesh/polaris-controller IMAGE_TAG=${DOCKER_TAG}
make all REPO=polarismesh/polaris-controller IMAGE_TAG=${DOCKER_TAG}
42 changes: 6 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,30 @@ ENVOY_SIDECAR_INIT_REPO = polarismesh/polaris-envoy-bootstrap-generator
IMAGE_TAG = v1.2.2
PLATFORMS = linux/amd64,linux/arm64

IS_LOGIN := $(shell jq '.auths | length' $(HOME)/.docker/config.json)
HAS_BUILDER := $(shell docker buildx ls | grep -q polaris-controller-builder; echo $$?)

.PHONY: all
all: init-builder build-amd64 build-arm64 build-multi-arch-image \
build-sidecar-init build-envoy-sidecar-init \
login push-image

.PHONY: all-nologin
all-nologin: build-amd64 build-arm64 build-multi-arch-image \
build-sidecar-init build-envoy-sidecar-init \
push-image

.PHONY: init-builder
init-builder:
@echo "------------------"
@echo "--> Create a builder instance (if not created yet) and switch the build environment to the newly created builder instance"
@echo "------------------"
@if [ $(HAS_BUILDER) -ne 0 ]; then \
docker buildx create --name polaris-controller-builder --use; \
fi
all: build-amd64 build-arm64 build-multi-arch-image \
build-sidecar-init build-envoy-sidecar-init push-image

.PHONY: build-amd64
build-amd64:
@echo "------------------"
@echo "--> Building binary for polaris-controller (amd64)"
@echo "--> Building binary for polaris-controller (linux/amd64)"
@echo "------------------"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o ./bin/amd64/polaris-controller ./cmd/polaris-controller/main.go

.PHONY: build-arm64
build-arm64:
@echo "------------------"
@echo "--> Building binary for polaris-controller (arm64)"
@echo "--> Building binary for polaris-controller (linux/arm64)"
@echo "------------------"
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -a -o ./bin/arm64/polaris-controller ./cmd/polaris-controller/main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -o ./bin/arm64/polaris-controller ./cmd/polaris-controller/main.go

.PHONY: build-multi-arch-image
build-multi-arch-image:
@echo "------------------"
@echo "--> Building multi-arch docker image for polaris-controller"
@echo "------------------"
@docker buildx build \
--platform $(PLATFORMS) \
--tag $(REPO):$(IMAGE_TAG) \
--load \
-f ./docker/Dockerfile \
.
@docker buildx build --platform $(PLATFORMS) --tag $(REPO):$(IMAGE_TAG) -f ./docker/Dockerfile --push ./

.PHONY: build-sidecar-init
build-sidecar-init:
Expand All @@ -61,14 +38,7 @@ build-sidecar-init:
build-envoy-sidecar-init:
docker build ./sidecar/envoy-bootstrap-config-generator -f ./sidecar/envoy-bootstrap-config-generator/Dockerfile -t $(REGISTRY)$(ENVOY_SIDECAR_INIT_REPO):$(IMAGE_TAG)

.PHONY: login
login:
@if [ $(IS_LOGIN) -eq 0 ]; then \
@docker login --username=$(DOCKER_USER) --password=$(DOCKER_PASS) $(REGISTRY)
fi

.PHONY: push-image
push-image:
docker push $(REGISTRY)$(REPO):$(IMAGE_TAG)
docker push $(REGISTRY)$(SIDECAR_INIT_REPO):$(IMAGE_TAG)
docker push $(REGISTRY)$(ENVOY_SIDECAR_INIT_REPO):$(IMAGE_TAG)

0 comments on commit 6037cda

Please sign in to comment.