@@ -6,6 +6,7 @@ Q=$(if $V,,@)
66PREFIX? =
77SRC =$(shell find . -type f -name '* .go' -not -path "./vendor/* ")
88GOOS_OVERRIDE ?=
9+ OUTPUT_ROOT =output/
910
1011# Set shell to bash for `echo -e`
1112SHELL := /bin/bash
@@ -152,6 +153,70 @@ uninstall:
152153
153154.PHONY : install uninstall
154155
156+ # ########################################
157+ # Building Docker Image
158+ #
159+ # Builds a dockerfile for step by building a linux version of the step-cli and
160+ # then copying the specific binary when building the container.
161+ #
162+ # This ensures the container is as small as possible without having to deal
163+ # with getting access to private repositories inside the container during build
164+ # time.
165+ # ########################################
166+
167+ # XXX We put the output for the build in 'output' so we don't mess with how we
168+ # do rule overriding from the base Makefile (if you name it 'build' it messes up
169+ # the wildcarding).
170+ DOCKER_OUTPUT =$(OUTPUT_ROOT ) docker/
171+
172+ DOCKER_MAKE=V =$V GOOS_OVERRIDE='GOOS=linux GOARCH=amd64' PREFIX=$(1 ) make $(1 ) bin/$(2 )
173+ DOCKER_BUILD =$Q docker build -t smallstep/$(1 ) :latest -f docker/$(2 ) --build-arg BINPATH=$(DOCKER_OUTPUT ) bin/$(1 ) .
174+
175+ docker : docker-make docker/Dockerfile.step-ca
176+ $(call DOCKER_BUILD,step-ca,Dockerfile.step-ca)
177+
178+ docker-make :
179+ mkdir -p $(DOCKER_OUTPUT )
180+ $(call DOCKER_MAKE,$(DOCKER_OUTPUT ) ,step-ca)
181+
182+ .PHONY : docker docker-make
183+
184+ # ################################################
185+ # Releasing Docker Images
186+ #
187+ # Using the docker build infrastructure, this section is responsible for
188+ # logging into docker hub and pushing the built docker containers up with the
189+ # appropriate tags.
190+ # ################################################
191+
192+ DOCKER_TAG =docker tag smallstep/$(1 ) :latest smallstep/$(1 ) :$(2 )
193+ DOCKER_PUSH =docker push smallstep/$(1 ) :$(2 )
194+
195+ docker-tag :
196+ $(call DOCKER_TAG,step-ca,$(VERSION ) )
197+
198+ docker-push-tag : docker-tag
199+ $(call DOCKER_PUSH,step-ca,$(VERSION ) )
200+
201+ # Rely on DOCKER_USERNAME and DOCKER_PASSWORD being set inside the CI or
202+ # equivalent environment
203+ docker-login :
204+ $Q docker login -u=" $( DOCKER_USERNAME) " -p=" $( DOCKER_PASSWORD) "
205+
206+ .PHONY : docker-login docker-tag docker-push-tag
207+
208+ # ################################################
209+ # Targets for pushing the docker images
210+ # ################################################
211+
212+ # For all builds on the master branch, we actually build the container
213+ docker-master : docker
214+
215+ # For all builds on the master branch with an rc tag
216+ docker-release : docker-master docker-login docker-push-tag
217+
218+ .PHONY : docker-master docker-release
219+
155220# ########################################
156221# Debian
157222# ########################################
@@ -177,7 +242,6 @@ distclean: clean
177242# Build statically compiled step binary for various operating systems
178243# ################################################
179244
180- OUTPUT_ROOT =output/
181245BINARY_OUTPUT =$(OUTPUT_ROOT ) binary/
182246BUNDLE_MAKE=v =$v GOOS_OVERRIDE='GOOS=$(1 ) GOARCH=$(2 ) ' PREFIX=$(3 ) make $(3 ) bin/$(BINNAME )
183247RELEASE =./.travis-releases
@@ -234,7 +298,7 @@ artifacts-master:
234298artifacts-release : artifacts-tag
235299
236300# This command is called by travis directly *after* a successful build
237- artifacts : artifacts-$(PUSHTYPE )
301+ artifacts : artifacts-$(PUSHTYPE ) docker- $( PUSHTYPE )
238302
239303.PHONY : artifacts-master artifacts-release artifacts
240304
0 commit comments