2019-12-11 21:32:45 +00:00
|
|
|
# All these commands must run from repository root.
|
|
|
|
|
2024-06-24 14:28:50 +00:00
|
|
|
DOCKER_REGISTRY ?= docker.io
|
2023-05-08 06:34:05 +00:00
|
|
|
DOCKER_NAMESPACE ?= victoriametrics
|
2020-04-19 22:09:52 +00:00
|
|
|
|
2024-05-28 17:36:15 +00:00
|
|
|
ROOT_IMAGE ?= alpine:3.20.0
|
2024-06-03 09:43:28 +00:00
|
|
|
ROOT_IMAGE_SCRATCH ?= scratch
|
2024-06-24 14:28:50 +00:00
|
|
|
SKIP_SCRATCH_BUILD ?= false
|
2024-05-28 17:36:15 +00:00
|
|
|
CERTS_IMAGE := alpine:3.20.0
|
2023-05-18 21:08:34 +00:00
|
|
|
|
2024-07-02 22:07:07 +00:00
|
|
|
GO_BUILDER_IMAGE := golang:1.22.5-alpine
|
2022-02-08 14:25:59 +00:00
|
|
|
BUILDER_IMAGE := local/builder:2.0.0-$(shell echo $(GO_BUILDER_IMAGE) | tr :/ __)-1
|
2023-02-09 22:01:16 +00:00
|
|
|
BASE_IMAGE := local/base:1.1.4-$(shell echo $(ROOT_IMAGE) | tr :/ __)-$(shell echo $(CERTS_IMAGE) | tr :/ __)
|
2023-11-09 08:50:21 +00:00
|
|
|
DOCKER ?= docker
|
2024-06-24 14:28:50 +00:00
|
|
|
DOCKER_BUILD_OPTS ?=
|
2023-11-09 08:50:21 +00:00
|
|
|
DOCKER_RUN ?= $(DOCKER) run
|
|
|
|
DOCKER_BUILD ?= $(DOCKER) build
|
|
|
|
DOCKER_COMPOSE ?= $(DOCKER) compose
|
|
|
|
DOCKER_IMAGE_LS ?= $(DOCKER) image ls --format '{{.Repository}}:{{.Tag}}'
|
2024-06-24 14:28:50 +00:00
|
|
|
TARGET_PLATFORM ?= linux/amd64,linux/arm,linux/arm64,linux/ppc64le,linux/386
|
|
|
|
COMMA := ,
|
2019-05-22 21:16:55 +00:00
|
|
|
|
2020-03-27 19:18:32 +00:00
|
|
|
package-base:
|
2023-08-02 11:04:38 +00:00
|
|
|
($(DOCKER_IMAGE_LS) | grep -q '$(BASE_IMAGE)$$') \
|
|
|
|
|| $(DOCKER_BUILD) \
|
2020-04-19 22:09:52 +00:00
|
|
|
--build-arg root_image=$(ROOT_IMAGE) \
|
|
|
|
--build-arg certs_image=$(CERTS_IMAGE) \
|
2021-02-16 15:42:24 +00:00
|
|
|
--tag $(BASE_IMAGE) \
|
2024-06-24 14:28:50 +00:00
|
|
|
$(DOCKER_BUILD_OPTS) \
|
2020-04-19 22:09:52 +00:00
|
|
|
deployment/docker/base
|
2019-05-22 21:16:55 +00:00
|
|
|
|
|
|
|
package-builder:
|
2023-08-02 11:04:38 +00:00
|
|
|
($(DOCKER_IMAGE_LS) | grep -q '$(BUILDER_IMAGE)$$') \
|
|
|
|
|| $(DOCKER_BUILD) \
|
2020-04-19 22:09:52 +00:00
|
|
|
--build-arg go_builder_image=$(GO_BUILDER_IMAGE) \
|
2021-02-16 15:42:24 +00:00
|
|
|
--tag $(BUILDER_IMAGE) \
|
2024-06-24 14:28:50 +00:00
|
|
|
$(DOCKER_BUILD_OPTS) \
|
2020-04-19 22:09:52 +00:00
|
|
|
deployment/docker/builder
|
2019-05-22 21:16:55 +00:00
|
|
|
|
2021-02-12 02:31:19 +00:00
|
|
|
app-via-docker: package-builder
|
2019-05-22 21:16:55 +00:00
|
|
|
mkdir -p gocache-for-docker
|
2023-11-09 08:50:21 +00:00
|
|
|
$(DOCKER_RUN) --rm \
|
2019-05-22 21:16:55 +00:00
|
|
|
--user $(shell id -u):$(shell id -g) \
|
|
|
|
--mount type=bind,src="$(shell pwd)",dst=/VictoriaMetrics \
|
|
|
|
-w /VictoriaMetrics \
|
|
|
|
--mount type=bind,src="$(shell pwd)/gocache-for-docker",dst=/gocache \
|
|
|
|
--env GOCACHE=/gocache \
|
2019-07-23 16:54:50 +00:00
|
|
|
$(DOCKER_OPTS) \
|
2019-05-22 21:16:55 +00:00
|
|
|
$(BUILDER_IMAGE) \
|
2022-08-07 17:39:05 +00:00
|
|
|
go build $(RACE) -trimpath -buildvcs=false \
|
2020-05-19 22:21:46 +00:00
|
|
|
-ldflags "-extldflags '-static' $(GO_BUILDINFO)" \
|
2021-09-23 21:14:11 +00:00
|
|
|
-tags 'netgo osusergo nethttpomithttp2 musl' \
|
2019-09-13 19:43:56 +00:00
|
|
|
-o bin/$(APP_NAME)$(APP_SUFFIX)-prod $(PKG_PREFIX)/app/$(APP_NAME)
|
2019-05-22 21:16:55 +00:00
|
|
|
|
2021-03-16 18:49:07 +00:00
|
|
|
app-via-docker-windows: package-builder
|
|
|
|
mkdir -p gocache-for-docker
|
2023-11-09 08:50:21 +00:00
|
|
|
$(DOCKER_RUN) --rm \
|
2021-03-16 18:49:07 +00:00
|
|
|
--user $(shell id -u):$(shell id -g) \
|
|
|
|
--mount type=bind,src="$(shell pwd)",dst=/VictoriaMetrics \
|
|
|
|
-w /VictoriaMetrics \
|
|
|
|
--mount type=bind,src="$(shell pwd)/gocache-for-docker",dst=/gocache \
|
|
|
|
--env GOCACHE=/gocache \
|
|
|
|
$(DOCKER_OPTS) \
|
|
|
|
$(BUILDER_IMAGE) \
|
2022-08-07 17:39:05 +00:00
|
|
|
go build $(RACE) -trimpath -buildvcs=false \
|
2021-03-16 18:49:07 +00:00
|
|
|
-ldflags "-s -w -extldflags '-static' $(GO_BUILDINFO)" \
|
|
|
|
-tags 'netgo osusergo nethttpomithttp2' \
|
|
|
|
-o bin/$(APP_NAME)-windows$(APP_SUFFIX)-prod.exe $(PKG_PREFIX)/app/$(APP_NAME)
|
|
|
|
|
2021-02-12 02:31:19 +00:00
|
|
|
package-via-docker: package-base
|
2024-06-24 14:28:50 +00:00
|
|
|
($(DOCKER_IMAGE_LS) | grep -q '$(DOCKER_REGISTRY)/$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(APP_SUFFIX)$(RACE)$$') || (\
|
2019-05-22 21:16:55 +00:00
|
|
|
$(MAKE) app-via-docker && \
|
2023-08-02 11:04:38 +00:00
|
|
|
$(DOCKER_BUILD) \
|
2019-12-11 21:06:53 +00:00
|
|
|
--build-arg src_binary=$(APP_NAME)$(APP_SUFFIX)-prod \
|
2020-03-27 19:18:32 +00:00
|
|
|
--build-arg base_image=$(BASE_IMAGE) \
|
2024-06-24 14:28:50 +00:00
|
|
|
--tag $(DOCKER_REGISTRY)/$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(APP_SUFFIX)$(RACE) \
|
2019-12-11 21:06:53 +00:00
|
|
|
-f app/$(APP_NAME)/deployment/Dockerfile bin)
|
2019-05-22 21:16:55 +00:00
|
|
|
|
2023-11-20 20:51:33 +00:00
|
|
|
publish-via-docker:
|
2024-06-24 14:28:50 +00:00
|
|
|
$(eval TARGET_PLATFORMS := $(subst $(COMMA), ,$(TARGET_PLATFORM)))
|
|
|
|
$(MAKE_PARALLEL) $(foreach PLATFORM,$(TARGET_PLATFORMS),app-via-docker-$(subst /,-,$(PLATFORM)))
|
2023-11-09 08:50:21 +00:00
|
|
|
$(DOCKER) buildx build \
|
2024-06-24 14:28:50 +00:00
|
|
|
--platform=$(TARGET_PLATFORM) \
|
2021-02-12 02:31:19 +00:00
|
|
|
--build-arg certs_image=$(CERTS_IMAGE) \
|
|
|
|
--build-arg root_image=$(ROOT_IMAGE) \
|
|
|
|
--build-arg APP_NAME=$(APP_NAME) \
|
2024-06-24 14:28:50 +00:00
|
|
|
--tag $(DOCKER_REGISTRY)/$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(RACE) \
|
|
|
|
--tag $(DOCKER_REGISTRY)/$(DOCKER_NAMESPACE)/$(APP_NAME):$(LATEST_TAG)$(RACE) \
|
2021-02-12 02:31:19 +00:00
|
|
|
-o type=image \
|
2023-08-29 14:29:14 +00:00
|
|
|
--provenance=false \
|
2024-06-24 14:28:50 +00:00
|
|
|
$(DOCKER_BUILD_OPTS) \
|
2021-02-12 02:31:19 +00:00
|
|
|
-f app/$(APP_NAME)/multiarch/Dockerfile \
|
|
|
|
--push \
|
|
|
|
bin
|
2024-06-24 14:28:50 +00:00
|
|
|
$(if $(findstring $(SKIP_SCRATCH_BUILD),true),, \
|
|
|
|
$(DOCKER) buildx build \
|
|
|
|
--platform=$(TARGET_PLATFORM) \
|
|
|
|
--build-arg certs_image=$(CERTS_IMAGE) \
|
|
|
|
--build-arg root_image=$(ROOT_IMAGE_SCRATCH) \
|
|
|
|
--build-arg APP_NAME=$(APP_NAME) \
|
|
|
|
--tag $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(RACE)-scratch \
|
|
|
|
--tag $(DOCKER_NAMESPACE)/$(APP_NAME):$(LATEST_TAG)$(RACE)-scratch \
|
|
|
|
-o type=image \
|
|
|
|
--provenance=false \
|
|
|
|
$(DOCKER_BUILD_OPTS) \
|
|
|
|
-f app/$(APP_NAME)/multiarch/Dockerfile \
|
|
|
|
--push \
|
|
|
|
bin)
|
|
|
|
cd bin && rm -rf $(foreach PLATFORM,$(TARGET_PLATFORMS),$(APP_NAME)-$(subst /,-,$(PLATFORM))-prod)
|
2019-05-22 21:16:55 +00:00
|
|
|
|
|
|
|
run-via-docker: package-via-docker
|
2023-11-09 08:50:21 +00:00
|
|
|
$(DOCKER_RUN) -it --rm \
|
2019-05-22 21:16:55 +00:00
|
|
|
--user $(shell id -u):$(shell id -g) \
|
|
|
|
--net host \
|
|
|
|
$(DOCKER_OPTS) \
|
2024-06-24 14:28:50 +00:00
|
|
|
$(DOCKER_REGISTRY)/$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(APP_SUFFIX)$(RACE) $(ARGS)
|
2019-12-11 21:06:53 +00:00
|
|
|
|
2022-07-13 13:44:39 +00:00
|
|
|
app-via-docker-goos-goarch:
|
|
|
|
APP_SUFFIX='-$(GOOS)-$(GOARCH)' \
|
2024-05-12 20:23:28 +00:00
|
|
|
DOCKER_OPTS='--env CGO_ENABLED=$(CGO_ENABLED) --env GOOS=$(GOOS) --env GOARCH=$(GOARCH) $(foreach v,$(EXTRA_DOCKER_ENVS),--env $(v))' \
|
2019-12-11 21:06:53 +00:00
|
|
|
$(MAKE) app-via-docker
|
|
|
|
|
2022-07-13 13:44:39 +00:00
|
|
|
app-via-docker-pure:
|
|
|
|
APP_SUFFIX='-pure' DOCKER_OPTS='--env CGO_ENABLED=0' $(MAKE) app-via-docker
|
2022-02-14 15:28:56 +00:00
|
|
|
|
2022-07-13 12:42:48 +00:00
|
|
|
app-via-docker-linux-amd64:
|
2024-05-12 20:23:28 +00:00
|
|
|
EXTRA_DOCKER_ENVS='CC=/opt/cross-builder/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc' \
|
2022-07-13 13:44:39 +00:00
|
|
|
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 $(MAKE) app-via-docker-goos-goarch
|
2022-07-13 12:42:48 +00:00
|
|
|
|
2022-07-13 13:44:39 +00:00
|
|
|
app-via-docker-linux-arm64:
|
2024-05-12 20:23:28 +00:00
|
|
|
EXTRA_DOCKER_ENVS='CC=/opt/cross-builder/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc' \
|
2024-04-23 10:12:10 +00:00
|
|
|
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 $(MAKE) app-via-docker-goos-goarch
|
2022-02-08 14:25:59 +00:00
|
|
|
|
2024-05-12 21:09:55 +00:00
|
|
|
app-via-docker-linux-arm:
|
|
|
|
EXTRA_DOCKER_ENVS='GOARM=5' \
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm $(MAKE) app-via-docker-goos-goarch
|
|
|
|
|
2022-07-13 13:44:39 +00:00
|
|
|
app-via-docker-linux-ppc64le:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le $(MAKE) app-via-docker-goos-goarch
|
2019-12-24 10:42:42 +00:00
|
|
|
|
2022-07-13 13:44:39 +00:00
|
|
|
app-via-docker-linux-386:
|
|
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=386 $(MAKE) app-via-docker-goos-goarch
|
2019-12-11 21:06:53 +00:00
|
|
|
|
2022-07-13 13:44:39 +00:00
|
|
|
app-via-docker-darwin-amd64:
|
|
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(MAKE) app-via-docker-goos-goarch
|
2019-12-11 21:06:53 +00:00
|
|
|
|
2022-07-13 13:44:39 +00:00
|
|
|
app-via-docker-darwin-arm64:
|
|
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(MAKE) app-via-docker-goos-goarch
|
2019-12-11 21:06:53 +00:00
|
|
|
|
2022-07-13 13:44:39 +00:00
|
|
|
app-via-docker-freebsd-amd64:
|
|
|
|
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 $(MAKE) app-via-docker-goos-goarch
|
2019-12-11 21:06:53 +00:00
|
|
|
|
2022-07-13 13:44:39 +00:00
|
|
|
app-via-docker-openbsd-amd64:
|
|
|
|
CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 $(MAKE) app-via-docker-goos-goarch
|
2019-12-11 21:06:53 +00:00
|
|
|
|
2021-03-16 18:49:07 +00:00
|
|
|
app-via-docker-windows-amd64:
|
2023-03-19 06:29:44 +00:00
|
|
|
APP_SUFFIX='-amd64' \
|
2022-07-13 13:44:39 +00:00
|
|
|
DOCKER_OPTS='--env CGO_ENABLED=0 --env GOOS=windows --env GOARCH=amd64' \
|
|
|
|
$(MAKE) app-via-docker-windows
|
2021-03-16 18:49:07 +00:00
|
|
|
|
2019-12-11 21:06:53 +00:00
|
|
|
package-via-docker-goarch:
|
|
|
|
APP_SUFFIX='-$(GOARCH)' \
|
2024-05-12 20:23:28 +00:00
|
|
|
DOCKER_OPTS='--env CGO_ENABLED=$(CGO_ENABLED) --env GOOS=linux --env GOARCH=$(GOARCH) $(foreach v,$(EXTRA_DOCKER_ENVS),--env $(v))' \
|
2019-12-11 21:06:53 +00:00
|
|
|
$(MAKE) package-via-docker
|
|
|
|
|
|
|
|
package-via-docker-pure:
|
|
|
|
APP_SUFFIX='-pure' DOCKER_OPTS='--env CGO_ENABLED=0' $(MAKE) package-via-docker
|
|
|
|
|
|
|
|
package-via-docker-amd64:
|
2024-05-12 20:23:28 +00:00
|
|
|
EXTRA_DOCKER_ENVS='CC=/opt/cross-builder/x86_64-linux-musl-cross/bin/x86_64-linux-musl-gcc' \
|
|
|
|
CO_ENABLED=1 GOARCH=amd64 $(MAKE) package-via-docker-goarch
|
2019-12-11 21:06:53 +00:00
|
|
|
|
|
|
|
package-via-docker-arm64:
|
2024-05-12 20:23:28 +00:00
|
|
|
EXTRA_DOCKER_ENVS='CC=/opt/cross-builder/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc' \
|
2024-04-24 16:29:32 +00:00
|
|
|
CGO_ENABLED=1 GOARCH=arm64 $(MAKE) package-via-docker-goarch
|
2019-12-11 21:06:53 +00:00
|
|
|
|
2024-05-12 21:09:55 +00:00
|
|
|
package-via-docker-arm:
|
|
|
|
EXTRA_DOCKER_ENVS='GOARM=5' \
|
|
|
|
CGO_ENABLED=0 GOARCH=arm $(MAKE) package-via-docker-goarch
|
|
|
|
|
2019-12-11 21:06:53 +00:00
|
|
|
package-via-docker-ppc64le:
|
2024-05-12 20:23:28 +00:00
|
|
|
CGO_ENABLED=0 GOARCH=ppc64le $(MAKE) package-via-docker-goarch
|
2019-12-11 21:06:53 +00:00
|
|
|
|
|
|
|
package-via-docker-386:
|
2024-05-12 20:23:28 +00:00
|
|
|
CGO_ENABLED=0 GOARCH=386 $(MAKE) package-via-docker-goarch
|
2019-05-22 21:16:55 +00:00
|
|
|
|
|
|
|
remove-docker-images:
|
2023-08-02 11:04:38 +00:00
|
|
|
docker image ls --format '{{.ID}}' | xargs docker image rm -f
|
2022-09-21 08:48:38 +00:00
|
|
|
|
|
|
|
docker-single-up:
|
2023-05-17 11:14:24 +00:00
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose.yml up -d
|
2022-09-21 08:48:38 +00:00
|
|
|
|
|
|
|
docker-single-down:
|
2023-05-17 11:14:24 +00:00
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose.yml down -v
|
2022-09-21 08:48:38 +00:00
|
|
|
|
2024-01-22 14:45:31 +00:00
|
|
|
docker-single-vm-datasource-up:
|
2024-01-22 15:05:44 +00:00
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose.yml -f deployment/docker/vm-datasource/docker-compose.yml up -d
|
2024-01-22 14:45:31 +00:00
|
|
|
|
|
|
|
docker-single-vm-datasource-down:
|
2024-01-22 15:05:44 +00:00
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose.yml -f deployment/docker/vm-datasource/docker-compose.yml down -v
|
2024-01-22 14:45:31 +00:00
|
|
|
|
2022-09-21 08:48:38 +00:00
|
|
|
docker-cluster-up:
|
2023-05-17 11:14:24 +00:00
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose-cluster.yml up -d
|
2022-09-21 08:48:38 +00:00
|
|
|
|
|
|
|
docker-cluster-down:
|
2023-05-17 11:14:24 +00:00
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose-cluster.yml down -v
|
2024-01-22 14:45:31 +00:00
|
|
|
|
|
|
|
docker-cluster-vm-datasource-up:
|
2024-01-22 15:05:44 +00:00
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose-cluster.yml -f deployment/docker/vm-datasource/docker-compose-cluster.yml up -d
|
2024-01-22 14:45:31 +00:00
|
|
|
|
|
|
|
docker-cluster-vm-datasource-down:
|
2024-01-22 15:05:44 +00:00
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose-cluster.yml -f deployment/docker/vm-datasource/docker-compose-cluster.yml down -v
|
2024-02-26 09:33:04 +00:00
|
|
|
|
|
|
|
docker-victorialogs-up:
|
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose-victorialogs.yml up -d
|
|
|
|
|
|
|
|
docker-victorialogs-down:
|
2024-03-06 19:04:09 +00:00
|
|
|
$(DOCKER_COMPOSE) -f deployment/docker/docker-compose-victorialogs.yml down -v
|