Debian Codegraph @

make/docker.mk

raw symbols SCIP
1 #########################################
2 # Building Docker Image
3 #
4 # This uses a multi-stage build file. The first stage is a builder (that might
5 # be large in size). After the build has succeeded, the statically linked
6 # binary is copied to a new image that is optimized for size.
7 #########################################
8
9 ifeq (, $(shell which docker))
10 DOCKER_CLIENT_OS := linux
11 else
12 DOCKER_CLIENT_OS := $(strip $(shell docker version -f '{{.Client.Os}}' 2>/dev/null))
13 endif
14
15 DOCKER_PLATFORMS = linux/amd64,linux/386,linux/arm,linux/arm64
16 DOCKER_IMAGE_NAME = smallstep/step-cli
17
18 docker-prepare:
19 # Ensure, we can build for ARM architecture
20 ifeq (linux,$(DOCKER_CLIENT_OS))
21 [ -f /proc/sys/fs/binfmt_misc/qemu-arm ] || docker run --rm --privileged linuxkit/binfmt:v0.8-amd64
22 endif
23
24 # Register buildx builder
25 mkdir -p $$HOME/.docker/cli-plugins
26
27 test -f $$HOME/.docker/cli-plugins/docker-buildx || \
28 (wget -q -O $$HOME/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.$(DOCKER_CLIENT_OS)-amd64 && \
29 chmod +x $$HOME/.docker/cli-plugins/docker-buildx)
30
31 docker buildx create --use --name mybuilder --platform="$(DOCKER_PLATFORMS)" || true
32
33 .PHONY: docker-prepare
34
35 #################################################
36 # Releasing Docker Images
37 #
38 # Using the docker build infrastructure, this section is responsible for
39 # logging into docker hub.
40 #################################################
41
42 # Rely on DOCKER_USERNAME and DOCKER_PASSWORD being set inside the CI or
43 # equivalent environment
44 docker-login:
45 $Q echo "$(DOCKER_PASSWORD)" | docker login -u="$(DOCKER_USERNAME)" --password-stdin
46
47 .PHONY: docker-login
48
49 #################################################
50 # Targets for different type of builds
51 #################################################
52
53
54 define DOCKER_BUILDX
55 # $(1) -- Image Tag
56 # $(2) -- Push (empty is no push | --push will push to dockerhub)
57 docker buildx build . --progress plain -t $(DOCKER_IMAGE_NAME):$(1) -f docker/Dockerfile --platform="$(DOCKER_PLATFORMS)" $(2)
58 endef
59
60 # For non-master builds don't build the docker containers.
61 docker-branch:
62
63 # For master builds don't build the docker containers. Only build for releases.
64 docker-master:
65
66 # For all builds with a release candidate tag build and push the containers.
67 docker-release-candidate: docker-prepare docker-login
68 $(call DOCKER_BUILDX,$(VERSION),--push)
69
70 # For all builds with a release tag build and push the containers.
71 docker-release: docker-prepare docker-login
72 $(call DOCKER_BUILDX,latest,--push)
73 $(call DOCKER_BUILDX,$(VERSION),--push)
74
75 .PHONY: docker-branch docker-master docker-release-candidate docker-release