2019-12-11 22:32:45 +01:00
|
|
|
# All these commands must run from repository root.
|
|
|
|
|
2019-12-11 22:06:53 +01:00
|
|
|
DOCKER_NAMESPACE := docker.io/victoriametrics
|
2020-02-26 21:15:33 +01:00
|
|
|
BUILDER_IMAGE := local/builder:go1.14.0
|
2019-11-29 17:24:39 +01:00
|
|
|
CERTS_IMAGE := local/certs:1.0.3
|
2019-05-22 23:16:55 +02:00
|
|
|
|
|
|
|
package-certs:
|
2019-12-11 22:06:53 +01:00
|
|
|
(docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -q '$(CERTS_IMAGE)$$') \
|
2019-05-22 23:16:55 +02:00
|
|
|
|| docker build -t $(CERTS_IMAGE) deployment/docker/certs
|
|
|
|
|
|
|
|
package-builder:
|
2019-12-11 22:06:53 +01:00
|
|
|
(docker image ls --format '{{.Repository}}:{{.Tag}}' | grep -q '$(BUILDER_IMAGE)$$') \
|
2019-05-22 23:16:55 +02:00
|
|
|
|| docker build -t $(BUILDER_IMAGE) deployment/docker/builder
|
|
|
|
|
|
|
|
app-via-docker: package-certs package-builder
|
|
|
|
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) \
|
2019-09-13 21:43:56 +02:00
|
|
|
go build $(RACE) -mod=vendor -trimpath -ldflags "-s -w -extldflags '-static' $(GO_BUILDINFO)" -tags 'netgo osusergo' \
|
|
|
|
-o bin/$(APP_NAME)$(APP_SUFFIX)-prod $(PKG_PREFIX)/app/$(APP_NAME)
|
2019-05-22 23:16:55 +02:00
|
|
|
|
|
|
|
package-via-docker:
|
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 \
|
|
|
|
--build-arg certs_image=$(CERTS_IMAGE) \
|
|
|
|
-t $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(APP_SUFFIX)$(RACE) \
|
|
|
|
-f app/$(APP_NAME)/deployment/Dockerfile bin)
|
2019-05-22 23:16:55 +02:00
|
|
|
|
2019-12-11 22:06:53 +01:00
|
|
|
package-manifest: \
|
|
|
|
package-via-docker-amd64 \
|
|
|
|
package-via-docker-arm \
|
|
|
|
package-via-docker-arm64 \
|
|
|
|
package-via-docker-ppc64le \
|
|
|
|
package-via-docker-386
|
|
|
|
$(MAKE) package-manifest-internal
|
|
|
|
|
|
|
|
package-manifest-internal:
|
|
|
|
docker push $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-amd64$(RACE)
|
|
|
|
docker push $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-arm$(RACE)
|
|
|
|
docker push $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-arm64$(RACE)
|
|
|
|
docker push $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-ppc64le$(RACE)
|
|
|
|
docker push $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-386$(RACE)
|
|
|
|
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(RACE) \
|
|
|
|
$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-amd64$(RACE) \
|
|
|
|
$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-arm$(RACE) \
|
|
|
|
$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-arm64$(RACE) \
|
|
|
|
$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-ppc64le$(RACE) \
|
|
|
|
$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-386$(RACE)
|
|
|
|
GOARCH=amd64 $(MAKE) package-manifest-annotate-goarch
|
|
|
|
GOARCH=arm $(MAKE) package-manifest-annotate-goarch
|
|
|
|
GOARCH=arm64 $(MAKE) package-manifest-annotate-goarch
|
|
|
|
GOARCH=ppc64le $(MAKE) package-manifest-annotate-goarch
|
|
|
|
GOARCH=386 $(MAKE) package-manifest-annotate-goarch
|
|
|
|
|
|
|
|
package-manifest-annotate-goarch:
|
|
|
|
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest annotate $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(RACE) \
|
|
|
|
$(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-$(GOARCH)$(RACE) --os linux --arch $(GOARCH)
|
|
|
|
|
|
|
|
publish-via-docker: package-manifest
|
|
|
|
docker tag $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-amd64$(RACE) $(DOCKER_NAMESPACE)/$(APP_NAME):latest-amd64$(RACE)
|
|
|
|
docker tag $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-arm$(RACE) $(DOCKER_NAMESPACE)/$(APP_NAME):latest-arm$(RACE)
|
|
|
|
docker tag $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-arm64$(RACE) $(DOCKER_NAMESPACE)/$(APP_NAME):latest-arm64$(RACE)
|
|
|
|
docker tag $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-ppc64le$(RACE) $(DOCKER_NAMESPACE)/$(APP_NAME):latest-ppc64le$(RACE)
|
|
|
|
docker tag $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)-386$(RACE) $(DOCKER_NAMESPACE)/$(APP_NAME):latest-386$(RACE)
|
|
|
|
PKG_TAG=latest $(MAKE) package-manifest-internal
|
|
|
|
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(DOCKER_NAMESPACE)/$(APP_NAME):$(PKG_TAG)$(RACE)
|
|
|
|
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(DOCKER_NAMESPACE)/$(APP_NAME):latest$(RACE)
|
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
|