From 9815a38a2c82e4d4586615d471fdc4248e9ff8d0 Mon Sep 17 00:00:00 2001 From: Carl Tashian Date: Wed, 12 Aug 2020 19:50:47 -0700 Subject: [PATCH] Fixes #344; also gets docker buildx working on both darwin & linux --- docker/Dockerfile.step-ca | 13 ++++++++++--- make/docker.mk | 28 ++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/docker/Dockerfile.step-ca b/docker/Dockerfile.step-ca index f9ba1ab4..5d8fdacd 100644 --- a/docker/Dockerfile.step-ca +++ b/docker/Dockerfile.step-ca @@ -1,12 +1,19 @@ +FROM golang:alpine AS builder + +RUN mkdir /src +ADD . /src + +RUN apk add --no-cache make git curl && \ + cd /src && \ + make V=1 bin/step-ca + FROM smallstep/step-cli:latest -ARG BINPATH="bin/step-ca" +COPY --from=builder /src/bin/step-ca /usr/local/bin/step-ca ENV CONFIGPATH="/home/step/config/ca.json" ENV PWDPATH="/home/step/secrets/password" -COPY $BINPATH "/usr/local/bin/step-ca" - USER root RUN apk add --no-cache libcap && setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/step-ca USER step diff --git a/make/docker.mk b/make/docker.mk index da41fd60..9e83ceef 100644 --- a/make/docker.mk +++ b/make/docker.mk @@ -6,18 +6,32 @@ # binary is copied to a new image that is optimized for size. ######################################### +# Testing: output images to out/ with -o out, like this: +# docker buildx build . --progress plain -t step-ca:master -f docker/Dockerfile --platform linux/amd64,linux/arm/v7,linux/386,linux/arm64 -o out + +ifeq (, $(shell which docker)) + DOCKER_CLIENT_OS := linux +else + DOCKER_CLIENT_OS := $(strip $(shell docker version -f '{{.Client.Os}}')) +endif + +DOCKER_PLATFORMS = linux/amd64,linux/386,linux/arm,linux/arm64 +DOCKER_IMAGE_NAME = smallstep/step-ca + docker-prepare: # Ensure, we can build for ARM architecture +ifeq (linux,$(DOCKER_CLIENT_OS)) [ -f /proc/sys/fs/binfmt_misc/qemu-arm ] || docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64 +endif # Register buildx builder mkdir -p $$HOME/.docker/cli-plugins - wget -O $$HOME/.docker/cli-plugins/docker-buildx https://github.com/docker/buildx/releases/download/v0.3.1/buildx-v0.3.1.linux-amd64 - chmod +x $$HOME/.docker/cli-plugins/docker-buildx + docker buildx >/dev/null || \ + wget -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 && \ + chmod +x $$HOME/.docker/cli-plugins/docker-buildx - $$HOME/.docker/cli-plugins/docker-buildx create --name mybuilder --platform amd64 --platform arm || true - $$HOME/.docker/cli-plugins/docker-buildx use mybuilder + docker buildx create --use --name mybuilder --platform="$(DOCKER_PLATFORMS)" || true .PHONY: docker-prepare @@ -39,13 +53,11 @@ docker-login: # Targets for different type of builds ################################################# -DOCKER_IMAGE_NAME = smallstep/step-ca -PLATFORMS = --platform amd64 --platform 386 --platform arm --platform arm64 - define DOCKER_BUILDX # $(1) -- Image Tag # $(2) -- Push (empty is no push | --push will push to dockerhub) - $$HOME/.docker/cli-plugins/docker-buildx build . --progress plain -t $(DOCKER_IMAGE_NAME):$(1) -f docker/Dockerfile.step-ca $(PLATFORMS) $(2) + docker buildx build . --progress plain -t $(DOCKER_IMAGE_NAME):$(1) -f docker/Dockerfile.step-ca --platform="$(DOCKER_PLATFORMS)" $(2) +DOCKER_IMAGE_NAME = smallstep/step-cli endef # For non-master builds don't build the docker containers.