-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.mk
58 lines (45 loc) · 1.83 KB
/
docker.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# To use buildx: https://github.com/docker/buildx#docker-ce
export DOCKER_CLI_EXPERIMENTAL=enabled
# Docker image build and push setting
DOCKER:=DOCKER_BUILDKIT=1 docker
# BUILDX_PLATFORMS ?= $(subst -,/,$(ARCH))
BUILDX_PLATFORMS ?= linux/amd64,linux/arm64
BUILDX_BUILDER ?= "$(APP_NAME)-builder"
# Image URL to use all building/pushing image targets
IMG ?= docker.io/apecloud/$(APP_NAME)
IMAGE_TAG ?=
ifeq ($(IMAGE_TAG),)
ifeq ($(TAG_LATEST), true)
IMAGE_TAG = latest
else
IMAGE_TAG = $(VERSION)
endif
endif
DOCKERFILE_DIR = .
GO_BUILD_ARGS ?= --build-arg GITHUB_PROXY=$(GITHUB_PROXY) --build-arg GOPROXY=$(GOPROXY)
BUILD_ARGS ?=
DOCKER_BUILD_ARGS ?=
DOCKER_BUILD_ARGS += $(GO_BUILD_ARGS) $(BUILD_ARGS)
##@ Docker containers
.PHONY: build-docker-image
build-docker-image: install-docker-buildx ## Build container image.
ifneq ($(BUILDX_ENABLED), true)
$(DOCKER) build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile --tag $(IMG):$(IMAGE_TAG)
else
$(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile --platform $(BUILDX_PLATFORMS) --tag $(IMG):$(IMAGE_TAG)
endif
.PHONY: push-docker-image
push-docker-image: install-docker-buildx ## Push container image.
ifneq ($(BUILDX_ENABLED), true)
$(DOCKER) push $(IMG):$(IMAGE_TAG)
else
$(DOCKER) buildx build . $(DOCKER_BUILD_ARGS) --file $(DOCKERFILE_DIR)/Dockerfile --platform $(BUILDX_PLATFORMS) --tag $(IMG):$(IMAGE_TAG) --push
endif
.PHONY: install-docker-buildx
install-docker-buildx: ## Create `docker buildx` builder.
@if ! docker buildx inspect $(BUILDX_BUILDER) > /dev/null; then \
echo "Buildx builder $(BUILDX_BUILDER) does not exist, creating..."; \
docker buildx create --name=$(BUILDX_BUILDER) --use --driver=docker-container --platform linux/amd64,linux/arm64; \
else \
echo "Buildx builder $(BUILDX_BUILDER) already exists"; \
fi