Makefile 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. .PHONY: image-build default check ca
  2. PWD := $(shell pwd)
  3. PKG=notice
  4. BUILD_DIR := /go/src/$(PKG)
  5. VERSION := $(shell cat VERSION.txt)
  6. GIT_COMMIT := $(shell git rev-parse --short HEAD)
  7. GO_LD_FLAGS := -w -extldflags "-static"
  8. ARCH := x86_64
  9. VERS := $(VERSION)-$(GIT_COMMIT)
  10. DOCKER_IMAGE := golang-1.18:$(ARCH)
  11. DOCKER_BUILD := \
  12. docker run --rm -v $(PWD)/bin:/target -v $(PWD):$(BUILD_DIR) -e GOARM=$(ARMVER) \
  13. -w $(BUILD_DIR) $(DOCKER_IMAGE) go build -ldflags="$(GO_LD_FLAGS)"
  14. ifeq ($(ARMVER),)
  15. DOCKER_BUILD = \
  16. docker run --rm -v $(PWD)/bin:/target -v $(PWD):$(BUILD_DIR) \
  17. -w $(BUILD_DIR) $(DOCKER_IMAGE) go mod tidy && go build -ldflags="$(GO_LD_FLAGS)"
  18. endif
  19. check:
  20. echo arch:$(ARCH) armversion:$(ARMVER)
  21. echo docker_build: $(DOCKER_BUILD)
  22. default: ca
  23. ca: image-build
  24. $(DOCKER_BUILD) -o /target/$(PKG)-$(VERS)-$(ARCH)$(ARMVER); \
  25. # 本机OS:arm64 docker镜像所使用的OS:x86_64
  26. arm64-x86_64-image-build:
  27. if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
  28. docker buildx build -t $(DOCKER_IMAGE) --platform=linux/amd64 -o type=docker -f Dockerfile.build.$(ARCH) .; \
  29. fi
  30. # 本机OS:arm64 docker镜像所使用的OS:arm64
  31. arm64-arm64-image-build:
  32. if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
  33. docker build -t $(DOCKER_IMAGE) -f Dockerfile.build.base-aarch64.$(ARCH) .; \
  34. fi
  35. # 默认本机的OS:x86_64 docker镜像所使用的OS:x86_64
  36. x86_64-image-build:
  37. if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
  38. docker build -t $(DOCKER_IMAGE) -f Dockerfile.build.$(ARCH) .; \
  39. fi
  40. # 默认本机的OS:x86_64 docker镜像所使用的OS:arm64
  41. arm64-image-build:
  42. if ! docker images $(DOCKER_IMAGE)|grep -q golang-1.18; then \
  43. docker buildx build -t $(DOCKER_IMAGE) --platform=linux/arm64 -o type=docker -f Dockerfile.build.base-aarch64.$(ARCH) .; \
  44. fi