Skip to content

Commit eefb125

Browse files
feat(Makefile): build using dockefile and slim image size (#215)
1 parent 5935566 commit eefb125

3 files changed

Lines changed: 14 additions & 24 deletions

File tree

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Dockerfile
22
vendor
3+
_dist
4+
.git

Jenkinsfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ def windows = 'windows'
22
def linux = 'linux'
33
def git_commit = ''
44
def git_branch = ''
5+
def git_tag = ''
56

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

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

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

155+
def version_flags = "-e REVISION=${git_commit.take(7)} -e GIT_TAG=${git_tag}"
156+
153157
parallel(
154158
revision: {
155159
node(linux) {
@@ -162,7 +166,7 @@ parallel(
162166

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

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

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

Makefile

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else
99
endif
1010

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

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

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

29-
GOTEST = go test --race
30-
3124
define check-static-binary
3225
if file $(1) | egrep -q "(statically linked|Mach-O)"; then \
3326
echo -n ""; \
@@ -37,14 +30,11 @@ define check-static-binary
3730
fi
3831
endef
3932

40-
bootstrap:
41-
${DEV_ENV_CMD} glide install
42-
43-
glideup:
44-
${DEV_ENV_CMD} glide up
45-
46-
build: binary-build
47-
@$(call check-static-binary,deis)
33+
build: build-test-image
34+
$(eval GO_LDFLAGS= -ldflags '-X ${repo_path}/version.Version=dev-${REVISION}')
35+
docker run --rm -e GOOS=${GOOS} -v ${CURDIR}/_dist:/out ${IMAGE} go build -a -installsuffix cgo ${GO_LDFLAGS} -o /out/deis .
36+
@$(call check-static-binary,_dist/deis)
37+
@echo "${GOOS} binary written to _dist/deis"
4838

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

6454
build-all: build-latest build-revision
6555

66-
binary-build:
67-
$(eval GO_LDFLAGS= -ldflags '-X ${repo_path}/version.Version=dev-${REVISION}')
68-
${DEV_ENV_PREFIX} -e GOOS=${GOOS} ${DEV_ENV_IMAGE} go build -a -installsuffix cgo ${GO_LDFLAGS} -o deis .
69-
70-
dist: build-all
71-
7256
install:
7357
cp deis $$GOPATH/bin
7458

0 commit comments

Comments
 (0)