12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- .PHONY: image-build default check ca
- PWD := $(shell pwd)
- PKG=notice
- BUILD_DIR := /go/src/$(PKG)
- VERSION := $(shell cat VERSION.txt)
- GIT_COMMIT := $(shell git rev-parse --short HEAD)
- GO_LD_FLAGS := -w -extldflags "-static"
- ARCH := x86_64
- VERS := $(VERSION)-$(GIT_COMMIT)
- DOCKER_IMAGE := golang-1.18:$(ARCH)
- DOCKER_BUILD := \
- docker run --rm -v $(PWD)/bin:/target -v $(PWD):$(BUILD_DIR) -e GOARM=$(ARMVER) \
- -w $(BUILD_DIR) $(DOCKER_IMAGE) go build -ldflags="$(GO_LD_FLAGS)"
- ifeq ($(ARMVER),)
- DOCKER_BUILD = \
- docker run --rm -v $(PWD)/bin:/target -v $(PWD):$(BUILD_DIR) \
- -w $(BUILD_DIR) $(DOCKER_IMAGE) go mod tidy && go build -ldflags="$(GO_LD_FLAGS)"
- endif
- check:
- echo arch:$(ARCH) armversion:$(ARMVER)
- echo docker_build: $(DOCKER_BUILD)
- default: ca
- ca: image-build
- $(DOCKER_BUILD) -o /target/$(PKG)-$(VERS)-$(ARCH)$(ARMVER); \
- # 本机OS:arm64 docker镜像所使用的OS:x86_64
- arm64-x86_64-image-build:
- if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
- docker buildx build -t $(DOCKER_IMAGE) --platform=linux/amd64 -o type=docker -f Dockerfile.build.$(ARCH) .; \
- fi
- # 本机OS:arm64 docker镜像所使用的OS:arm64
- arm64-arm64-image-build:
- if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
- docker build -t $(DOCKER_IMAGE) -f Dockerfile.build.base-aarch64.$(ARCH) .; \
- fi
- # 默认本机的OS:x86_64 docker镜像所使用的OS:x86_64
- x86_64-image-build:
- if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
- docker build -t $(DOCKER_IMAGE) -f Dockerfile.build.$(ARCH) .; \
- fi
- # 默认本机的OS:x86_64 docker镜像所使用的OS:arm64
- arm64-image-build:
- if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
- docker buildx build -t $(DOCKER_IMAGE) --platform=linux/arm64 -o type=docker -f Dockerfile.build.base-aarch64.$(ARCH) .; \
- fi
|