Skip to content
Permalink
Browse files

feat(Makefile): build using dockefile and slim image size (#215)

  • Loading branch information...
Joshua-Anderson committed Sep 6, 2016
1 parent 5935566 commit eefb125151128e6122f94d2ee09c7b81db88d392
Showing with 14 additions and 24 deletions.
  1. +2 −0 .dockerignore
  2. +6 −2 Jenkinsfile
  3. +6 −22 Makefile
@@ -1,2 +1,4 @@
Dockerfile
vendor
_dist
.git
@@ -2,6 +2,7 @@ def windows = 'windows'
def linux = 'linux'
def git_commit = ''
def git_branch = ''
def git_tag = ''

def getBasePath = { String filepath ->
def filename = filepath.lastIndexOf(File.separator)
@@ -53,6 +54,7 @@ node(linux) {

git_branch = sh(returnStdout: true, script: 'git describe --all').trim()
git_commit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
git_tag = sh(returnStdout: true, script: 'git describe --abbrev=0 --tags').trim()

if (git_branch != "remotes/origin/master") {
// Determine actual PR commit, if necessary
@@ -150,6 +152,8 @@ def mktmp = {
return tmp
}

def version_flags = "-e REVISION=${git_commit.take(7)} -e GIT_TAG=${git_tag}"

parallel(
revision: {
node(linux) {
@@ -162,7 +166,7 @@ parallel(

def tmp_dir = mktmp()
def dist_dir = "-e DIST_DIR=/upload -v ${tmp_dir}:/upload"
sh "docker run ${flags} -e REVISION=${git_commit.take(7)} ${dist_dir} --rm ${test_image} make build-revision"
sh "docker run ${flags} ${version_flags} ${dist_dir} --rm ${test_image} make build-revision"

if (git_branch == "remotes/origin/master") {
upload_artifacts(dist_dir, '6029cf4e-eaa3-4a8e-9dc7-744d118ebe6a', master_gcs_bucket, true)
@@ -178,7 +182,7 @@ parallel(
if (git_branch == "remotes/origin/master") {
def tmp_dir = mktmp()
def dist_dir = "-e DIST_DIR=/upload -v ${tmp_dir}:/upload"
sh "docker run ${dist_dir} --rm ${test_image} make build-latest"
sh "docker run ${dist_dir} --rm ${test_image} ${version_flags} make build-latest"

upload_artifacts(dist_dir, '6029cf4e-eaa3-4a8e-9dc7-744d118ebe6a', master_gcs_bucket, false)
sh "docker run ${dist_dir} --rm ${test_image} sh -c 'rm -rf /upload/*'"
@@ -9,7 +9,7 @@ else
endif

# The latest git tag on branch
GIT_TAG := $(shell git describe --abbrev=0 --tags)
GIT_TAG ?= $(shell git describe --abbrev=0 --tags)
REVISION ?= $(shell git rev-parse --short HEAD)

REGISTRY ?= quay.io/
@@ -19,15 +19,8 @@ IMAGE := ${REGISTRY}${IMAGE_PREFIX}/workflow-cli-dev:${REVISION}
BUILD_OS ?=linux darwin windows
BUILD_ARCH ?=amd64 386

DEV_ENV_IMAGE := quay.io/deis/go-dev:0.16.0
DEV_ENV_WORK_DIR := /go/src/${repo_path}
DEV_ENV_PREFIX := docker run --rm -e CGO_ENABLED=0 -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR}
DEV_ENV_PREFIX_CGO_ENABLED := docker run --rm -e CGO_ENABLED=1 -v ${CURDIR}:${DEV_ENV_WORK_DIR} -w ${DEV_ENV_WORK_DIR}
DEV_ENV_CMD := ${DEV_ENV_PREFIX} ${DEV_ENV_IMAGE}
DIST_DIR ?= _dist

GOTEST = go test --race

define check-static-binary
if file $(1) | egrep -q "(statically linked|Mach-O)"; then \
echo -n ""; \
@@ -37,14 +30,11 @@ define check-static-binary
fi
endef

bootstrap:
${DEV_ENV_CMD} glide install

glideup:
${DEV_ENV_CMD} glide up

build: binary-build
@$(call check-static-binary,deis)
build: build-test-image
$(eval GO_LDFLAGS= -ldflags '-X ${repo_path}/version.Version=dev-${REVISION}')
docker run --rm -e GOOS=${GOOS} -v ${CURDIR}/_dist:/out ${IMAGE} go build -a -installsuffix cgo ${GO_LDFLAGS} -o /out/deis .
@$(call check-static-binary,_dist/deis)
@echo "${GOOS} binary written to _dist/deis"

# This is supposed to be run within a docker container
build-latest:
@@ -63,12 +53,6 @@ build-tag:

build-all: build-latest build-revision

binary-build:
$(eval GO_LDFLAGS= -ldflags '-X ${repo_path}/version.Version=dev-${REVISION}')
${DEV_ENV_PREFIX} -e GOOS=${GOOS} ${DEV_ENV_IMAGE} go build -a -installsuffix cgo ${GO_LDFLAGS} -o deis .

dist: build-all

install:
cp deis $$GOPATH/bin

0 comments on commit eefb125

Please sign in to comment.
You can’t perform that action at this time.