Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 6262249

Browse files
authored
Merge pull request #58 from mat007/e2e-in-ci
Have CI build and run the e2e tests on each platform
2 parents 69d4ccd + f25c7b2 commit 6262249

File tree

4 files changed

+69
-42
lines changed

4 files changed

+69
-42
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ COPY . .
1313
FROM build AS bin-build
1414
ARG COMMIT
1515
ARG TAG
16-
RUN make COMMIT=${COMMIT} TAG=${TAG} bin-all
16+
RUN make COMMIT=${COMMIT} TAG=${TAG} bin-all e2e-all
1717

1818
FROM build AS test
1919
ARG COMMIT
2020
ARG TAG
21-
RUN make COMMIT=${COMMIT} TAG=${TAG} unit-test e2e-test
21+
RUN make COMMIT=${COMMIT} TAG=${TAG} unit-test

Jenkinsfile

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pipeline {
66
}
77

88
options {
9-
checkoutToSubdirectory('src/github.com/docker/lunchbox')
9+
skipDefaultCheckout(true)
1010
}
1111

1212
stages {
@@ -19,13 +19,16 @@ pipeline {
1919
script {
2020
try {
2121
checkout scm
22-
sh 'rm -f *.tar.gz'
22+
sh 'rm -rf *.tar.gz stash'
2323
sh 'docker image prune -f'
2424
sh 'make ci-lint'
2525
sh 'make ci-test'
2626
sh 'make ci-bin-all'
27-
sh 'ls *.tar.gz | xargs -i tar xf {}'
28-
stash name: "binaries", includes: "docker-app-*", excludes: "*.tar.gz"
27+
sh 'mkdir stash'
28+
sh 'ls *.tar.gz | xargs -i tar -xf {} -C stash'
29+
dir('stash') {
30+
stash name: 'e2e'
31+
}
2932
archiveArtifacts '*.tar.gz'
3033
} finally {
3134
def clean_images = /docker image ls --format "{{.ID}}\t{{.Tag}}" | grep $(git describe --always --dirty) | awk '{print $1}' | xargs docker image rm/
@@ -43,8 +46,10 @@ pipeline {
4346
}
4447
steps {
4548
dir('src/github.com/docker/lunchbox') {
46-
unstash "binaries"
47-
sh './docker-app-linux version'
49+
deleteDir()
50+
unstash 'e2e'
51+
sh 'ls -la'
52+
sh './docker-app-e2e-linux'
4853
}
4954
}
5055
}
@@ -54,8 +59,10 @@ pipeline {
5459
}
5560
steps {
5661
dir('src/github.com/docker/lunchbox') {
57-
unstash "binaries"
58-
sh './docker-app-darwin version'
62+
deleteDir()
63+
unstash 'e2e'
64+
sh 'ls -la'
65+
sh './docker-app-e2e-darwin'
5966
}
6067
}
6168
}
@@ -65,8 +72,10 @@ pipeline {
6572
}
6673
steps {
6774
dir('src/github.com/docker/lunchbox') {
68-
unstash "binaries"
69-
bat 'docker-app-windows.exe version'
75+
deleteDir()
76+
unstash "e2e"
77+
bat 'dir'
78+
bat 'docker-app-e2e-windows.exe'
7079
}
7180
}
7281
}

Makefile

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PKG_NAME := github.com/docker/lunchbox
22
BIN_NAME := docker-app
3+
E2E_NAME := $(BIN_NAME)-e2e
34

45
# Enable experimental features. "on" or "off"
56
EXPERIMENTAL := off
@@ -15,7 +16,6 @@ GO_VERSION := 1.10.1
1516
IMAGE_BUILD_ARGS := \
1617
--build-arg ALPINE_VERSION=$(ALPINE_VERSION) \
1718
--build-arg GO_VERSION=$(GO_VERSION) \
18-
--build-arg BIN_NAME=$(BIN_NAME) \
1919
--build-arg COMMIT=$(COMMIT) \
2020
--build-arg TAG=$(TAG)
2121

@@ -25,17 +25,21 @@ LDFLAGS := "-s -w \
2525
-X $(PKG_NAME)/internal.Experimental=$(EXPERIMENTAL)"
2626

2727
GO_BUILD := CGO_ENABLED=0 go build
28-
GO_TEST := go test
28+
GO_TEST := CGO_ENABLED=0 go test
2929

3030
#####################
3131
# Local Development #
3232
#####################
3333

34+
OS_LIST ?= darwin linux windows
35+
3436
EXEC_EXT :=
3537
ifeq ($(OS),Windows_NT)
3638
EXEC_EXT := .exe
3739
endif
3840

41+
PKG_PATH := /go/src/$(PKG_NAME)
42+
3943
all: bin test
4044

4145
check_go_env:
@@ -46,20 +50,23 @@ bin: check_go_env
4650
@echo "Building _build/$(BIN_NAME)$(EXEC_EXT)..."
4751
$(GO_BUILD) -ldflags=$(LDFLAGS) -i -o _build/$(BIN_NAME)$(EXEC_EXT)
4852

49-
OS_LIST ?= darwin linux windows
5053
bin-all: check_go_env
5154
@echo "Building for all platforms..."
52-
$(foreach OS, $(OS_LIST), GOOS=$(OS) $(GO_BUILD) -ldflags=$(LDFLAGS) -i -o _build/$(TAG)/$(BIN_NAME)-$(OS)$(if $(filter windows, $(OS)),.exe,) || exit 1;)
55+
$(foreach OS, $(OS_LIST), GOOS=$(OS) $(GO_BUILD) -ldflags=$(LDFLAGS) -i -o _build/$(BIN_NAME)-$(OS)$(if $(filter windows, $(OS)),.exe,) || exit 1;)
56+
57+
e2e-all: check_go_env
58+
@echo "Building for all platforms..."
59+
$(foreach OS, $(OS_LIST), GOOS=$(OS) $(GO_TEST) -c -i -o _build/$(E2E_NAME)-$(OS)$(if $(filter windows, $(OS)),.exe,) ./e2e || exit 1;)
5360

5461
release:
55-
gsutil cp -r _build/$(TAG) gs://docker_app
62+
gsutil cp -r _build gs://docker_app
5663

5764
test check: lint unit-test e2e-test
5865

5966
lint:
6067
@echo "Linting..."
6168
@tar -c Dockerfile.lint gometalinter.json | docker build -t $(IMAGE_NAME)-lint $(IMAGE_BUILD_ARGS) -f Dockerfile.lint - --target=lint-volume > /dev/null
62-
@docker run --rm -v $(dir $(realpath $(lastword $(MAKEFILE_LIST)))):/go/src/$(PKG_NAME):ro,cached $(IMAGE_NAME)-lint
69+
@docker run --rm -v $(dir $(realpath $(lastword $(MAKEFILE_LIST)))):$(PKG_PATH):ro,cached $(IMAGE_NAME)-lint
6370

6471
e2e-test: bin
6572
@echo "Running e2e tests..."
@@ -72,9 +79,9 @@ unit-test:
7279
clean:
7380
rm -Rf ./_build docker-app-*.tar.gz
7481

75-
######
76-
# CI #
77-
######
82+
##########################
83+
# Continuous Integration #
84+
##########################
7885

7986
ci-lint:
8087
@echo "Linting..."
@@ -87,7 +94,8 @@ ci-test:
8794

8895
ci-bin-all:
8996
docker build -t $(IMAGE_NAME)-bin-all:$(TAG) $(IMAGE_BUILD_ARGS) . --target=bin-build
90-
$(foreach OS, $(OS_LIST), docker run --rm $(IMAGE_NAME)-bin-all:$(TAG) tar -cz $(BIN_NAME)-$(OS)$(if $(filter windows, $(OS)),.exe,) -C /go/src/$(PKG_NAME)/_build/$(TAG)/ > $(BIN_NAME)-$(OS)-$(TAG).tar.gz || exit 1;)
97+
$(foreach OS, $(OS_LIST), docker run --rm $(IMAGE_NAME)-bin-all:$(TAG) tar -cz -C $(PKG_PATH)/_build $(BIN_NAME)-$(OS)$(if $(filter windows, $(OS)),.exe,) > $(BIN_NAME)-$(OS)-$(TAG).tar.gz || exit 1;)
98+
$(foreach OS, $(OS_LIST), docker run --rm $(IMAGE_NAME)-bin-all:$(TAG) /bin/sh -c "cp $(PKG_PATH)/_build/*-$(OS)* $(PKG_PATH)/e2e && cd $(PKG_PATH)/e2e && tar -cz * --exclude=*.go" > $(E2E_NAME)-$(OS)-$(TAG).tar.gz || exit 1;)
9199

92-
.PHONY: bin bin-all release test check lint e2e-test unit-test clean ci-lint ci-test ci-bin-all
100+
.PHONY: bin bin-all release test check lint e2e-test e2e-all unit-test clean ci-lint ci-test ci-bin-all ci-e2e-all
93101
.DEFAULT: all

e2e/binary_test.go

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,40 @@ func getBinary(t *testing.T) string {
2525
if dockerApp != "" {
2626
return dockerApp
2727
}
28-
dockerApp = os.Getenv("DOCKERAPP_BINARY")
29-
if dockerApp == "" {
30-
binName := "docker-app"
31-
if runtime.GOOS == "windows" {
32-
binName += ".exe"
33-
}
34-
locations := []string{".", "../_build"}
35-
for _, l := range locations {
36-
b := path.Join(l, binName)
37-
if _, err := os.Stat(b); err == nil {
38-
dockerApp = b
39-
break
40-
}
41-
}
42-
}
43-
if dockerApp == "" {
28+
binName := findBinary()
29+
if binName == "" {
4430
t.Error("cannot locate docker-app binary")
4531
}
46-
cmd := exec.Command(dockerApp, "version")
47-
_, err := cmd.CombinedOutput()
48-
assert.NilError(t, err, "failed to execute docker-app binary")
32+
cmd := exec.Command(binName, "version")
33+
err := cmd.Run()
34+
assert.NilError(t, err, "failed to execute %s", binName)
35+
dockerApp = binName
4936
return dockerApp
5037
}
5138

39+
func findBinary() string {
40+
binNames := []string{
41+
os.Getenv("DOCKERAPP_BINARY"),
42+
"./docker-app-" + runtime.GOOS + binExt(),
43+
"./docker-app" + binExt(),
44+
"../_build/docker-app-" + runtime.GOOS + binExt(),
45+
"../_build/docker_app" + binExt(),
46+
}
47+
for _, binName := range binNames {
48+
if _, err := os.Stat(binName); err == nil {
49+
return binName
50+
}
51+
}
52+
return ""
53+
}
54+
55+
func binExt() string {
56+
if runtime.GOOS == "windows" {
57+
return ".exe"
58+
}
59+
return ""
60+
}
61+
5262
func TestRenderBinary(t *testing.T) {
5363
getBinary(t)
5464
apps, err := ioutil.ReadDir("render")

0 commit comments

Comments
 (0)