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