2019-05-22 23:23:23 +02:00
|
|
|
# All these commands must run from repository root.
|
|
|
|
|
2020-04-20 00:09:52 +02:00
|
|
|
DOCKER_NAMESPACE := victoriametrics
|
|
|
|
|
2021-02-03 02:34:19 +01:00
|
|
|
ROOT_IMAGE ?= alpine:3.13.1
|
|
|
|
CERTS_IMAGE := alpine:3.13.1
|
2021-02-17 14:17:38 +01:00
|
|
|
GO_BUILDER_IMAGE := golang:1.16.0
|
2020-04-20 00:09:52 +02:00
|
|
|
BUILDER_IMAGE := local/builder:2.0.0-$(shell echo $(GO_BUILDER_IMAGE) | tr : _)
|
2021-02-12 03:50:35 +01:00
|
|
|
BASE_IMAGE := local/base:1.1.3-$(shell echo $(ROOT_IMAGE) | tr : _)-$(shell echo $(CERTS_IMAGE) | tr : _)
|
2019-05-22 23:16:55 +02:00
|
|
|
|
2020-03-27 20:18:32 +01:00
|
|
|
package-base:
|
|
|
|
(docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -q '$(BASE_IMAGE)$$') \
|
2021-02-16 16:42:24 +01:00
|
|
|
|| 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:
|
2019-12-11 22:06:53 +01:00
|
|
|
(docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -q '$(BUILDER_IMAGE)$$') \
|
2021-02-16 16:42:24 +01:00
|
|
|
|| 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
|
|
|
|
docker run --rm \
|
|
|
|
--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-05-26 22:19:34 +02:00
|
|
|
--env GO111MODULE=on \
|
2019-07-23 18:54:50 +02:00
|
|
|
$(DOCKER_OPTS) \
|
2019-05-22 23:16:55 +02:00
|
|
|
$(BUILDER_IMAGE) \
|
2020-05-12 13:17:40 +02:00
|
|
|
go build $(RACE) -mod=vendor -trimpath \
|
2020-05-20 00:21:46 +02:00
|
|
|
-ldflags "-extldflags '-static' $(GO_BUILDINFO)" \
|
2021-02-14 23:50:06 +01:00
|
|
|
-tags 'netgo osusergo nethttpomithttp2' \
|
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-02-12 03:31:19 +01:00
|
|
|
package-via-docker: package-base
|
2019-12-11 22:06:53 +01:00
|
|
|
(docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -q '$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(APP_SUFFIX)$(RACE)$$') || (\
|
2019-05-22 23:16:55 +02:00
|
|
|
$(MAKE) app-via-docker && \
|
2019-12-11 22:06:53 +01:00
|
|
|
docker build \
|
|
|
|
--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
|
|
|
|
2021-02-12 03:31:19 +01:00
|
|
|
publish-via-docker: \
|
|
|
|
app-via-docker-amd64 \
|
|
|
|
app-via-docker-arm \
|
|
|
|
app-via-docker-arm64 \
|
|
|
|
app-via-docker-ppc64le \
|
|
|
|
app-via-docker-386
|
|
|
|
docker buildx build \
|
|
|
|
--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) \
|
|
|
|
--tag $(DOCKER_NAMESPACE)/$(APP_NAME):latest$(RACE) \
|
2021-02-12 03:31:19 +01:00
|
|
|
-o type=image \
|
|
|
|
-f app/$(APP_NAME)/multiarch/Dockerfile \
|
|
|
|
--push \
|
|
|
|
bin
|
2019-05-22 23:16:55 +02:00
|
|
|
|
|
|
|
run-via-docker: package-via-docker
|
|
|
|
docker run -it --rm \
|
|
|
|
--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)
|
|
|
|
|
|
|
|
app-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) app-via-docker
|
|
|
|
|
2019-12-24 11:42:42 +01:00
|
|
|
app-via-docker-goarch-cgo:
|
|
|
|
CGO_ENABLED=1 $(MAKE) app-via-docker-goarch
|
|
|
|
|
|
|
|
app-via-docker-goarch-nocgo:
|
|
|
|
CGO_ENABLED=0 $(MAKE) app-via-docker-goarch
|
|
|
|
|
2019-12-11 22:06:53 +01:00
|
|
|
app-via-docker-pure:
|
|
|
|
APP_SUFFIX='-pure' DOCKER_OPTS='--env CGO_ENABLED=0' $(MAKE) app-via-docker
|
|
|
|
|
|
|
|
app-via-docker-amd64:
|
2019-12-24 11:42:42 +01:00
|
|
|
GOARCH=amd64 $(MAKE) app-via-docker-goarch-cgo
|
2019-12-11 22:06:53 +01:00
|
|
|
|
|
|
|
app-via-docker-arm:
|
2019-12-24 11:42:42 +01:00
|
|
|
GOARCH=arm $(MAKE) app-via-docker-goarch-nocgo
|
2019-12-11 22:06:53 +01:00
|
|
|
|
|
|
|
app-via-docker-arm64:
|
2019-12-24 11:42:42 +01:00
|
|
|
GOARCH=arm64 $(MAKE) app-via-docker-goarch-nocgo
|
2019-12-11 22:06:53 +01:00
|
|
|
|
|
|
|
app-via-docker-ppc64le:
|
2019-12-24 11:42:42 +01:00
|
|
|
GOARCH=ppc64le $(MAKE) app-via-docker-goarch-nocgo
|
2019-12-11 22:06:53 +01:00
|
|
|
|
|
|
|
app-via-docker-386:
|
2019-12-24 11:42:42 +01:00
|
|
|
GOARCH=386 $(MAKE) app-via-docker-goarch-nocgo
|
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
|
|
|
|
|
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:
|
2019-12-24 11:42:42 +01:00
|
|
|
GOARCH=arm64 $(MAKE) package-via-docker-goarch-nocgo
|
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:
|
|
|
|
docker image ls --format '{{.Repository}}\t{{.ID}}' | grep $(DOCKER_NAMESPACE)/ | grep -v /builder | awk '{print $$2}' | xargs docker image rm -f
|