Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit 468bbd1

Browse files
authored
Merge pull request #16 from docker/login-before-build
Add e2e test for building from private registry
2 parents fa7d6ce + cd2d03d commit 468bbd1

File tree

5 files changed

+71
-22
lines changed

5 files changed

+71
-22
lines changed

e2e/build_push_test.go

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,13 @@ import (
88
"gotest.tools/v3/assert"
99
)
1010

11-
func TestBuildPush(t *testing.T) {
12-
tags := []string{
13-
"localhost:5000/my-repository:build-push-tag1",
14-
"localhost:5000/my-repository:build-push-test",
15-
}
16-
labels := map[string]string{
17-
"a": "a1",
18-
}
11+
func testBuildPush(t *testing.T, envFile string, tags []string, labels map[string]string) {
1912
err := removeImages(tags)
2013
assert.NilError(t, err)
21-
defer removeImages(tags)
22-
23-
err = setupLocalRegistry()
24-
assert.NilError(t, err)
25-
defer removeLocalRegistry()
26-
27-
err = loginLocalRegistry()
28-
assert.NilError(t, err)
2914

30-
err = runActionsCommand("build-push", "testdata/build_push_tests/build_push.env")
15+
err = runActionsCommand("build-push", envFile)
3116
assert.NilError(t, err)
3217

33-
for _, tag := range tags {
34-
assertBuildPushImages(t, tag, tags, labels)
35-
}
36-
3718
err = removeImages(tags)
3819
assert.NilError(t, err)
3920

@@ -47,6 +28,47 @@ func TestBuildPush(t *testing.T) {
4728
}
4829
}
4930

31+
func TestBuildPush(t *testing.T) {
32+
err := setupLocalRegistry()
33+
assert.NilError(t, err)
34+
defer removeLocalRegistry()
35+
36+
err = ensureLocalRegistryAlive()
37+
assert.NilError(t, err)
38+
39+
// Build and push base image
40+
baseTags := []string{
41+
"localhost:5000/org/base:build-push-tag1",
42+
"localhost:5000/org/base:build-push-test",
43+
}
44+
defer removeImages(baseTags)
45+
testBuildPush(
46+
t,
47+
"testdata/build_push_tests/build_push.env",
48+
baseTags,
49+
map[string]string{
50+
"a": "a1",
51+
},
52+
)
53+
54+
err = logoutLocalRegistry()
55+
assert.NilError(t, err)
56+
57+
// Build and push image using base image from local registry
58+
testBuildPush(
59+
t,
60+
"testdata/build_push_tests/build_push_from_registry.env",
61+
[]string{
62+
"localhost:5000/org/repo:build-push-reg-tag1",
63+
"localhost:5000/org/repo:build-push-reg-test",
64+
},
65+
map[string]string{
66+
"a": "a1",
67+
"b": "b1",
68+
},
69+
)
70+
}
71+
5072
func assertBuildPushImages(t *testing.T, image string, expectedTags []string, expectedLabels map[string]string) {
5173
inspect, err := inspectImage(image)
5274
assert.NilError(t, err)
@@ -57,3 +79,15 @@ func assertBuildPushImages(t *testing.T, image string, expectedTags []string, ex
5779
assert.DeepEqual(t, expectedTags, repoTags)
5880
assert.DeepEqual(t, expectedLabels, inspect.Config.Labels)
5981
}
82+
83+
func ensureLocalRegistryAlive() error {
84+
if err := loginLocalRegistry(); err != nil {
85+
return err
86+
}
87+
88+
return logoutLocalRegistry()
89+
}
90+
91+
func logoutLocalRegistry() error {
92+
return exec.Command("docker", "logout", "localhost:5000").Run()
93+
}

e2e/login_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestLogin(t *testing.T) {
1818
}
1919

2020
func loginLocalRegistry() error {
21+
// Polls as registry takes a moment to start up
2122
return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
2223
err := runActionsCommand("login", "testdata/login_test.env")
2324
return err == nil, err

e2e/testdata/build_push_tests/build_push.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ INPUT_LABELS=a=a1
66
INPUT_REGISTRY=localhost:5000
77
INPUT_USERNAME=my_user
88
INPUT_PASSWORD=my_password
9-
INPUT_REPOSITORY=my-repository
9+
INPUT_REPOSITORY=org/base
1010
INPUT_PUSH=true
1111
GITHUB_REF=refs/tags/build-push-tag1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
INPUT_PATH=./testdata/build_push_tests
2+
INPUT_DOCKERFILE=./testdata/build_push_tests/fromreg.Dockerfile
3+
INPUT_TAG_WITH_REF=true
4+
INPUT_TAGS=build-push-reg-test
5+
INPUT_LABELS=b=b1
6+
INPUT_REGISTRY=localhost:5000
7+
INPUT_USERNAME=my_user
8+
INPUT_PASSWORD=my_password
9+
INPUT_REPOSITORY=org/repo
10+
INPUT_PUSH=true
11+
GITHUB_REF=refs/tags/build-push-reg-tag1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM localhost:5000/org/base:build-push-test
2+
3+
ENTRYPOINT ["echo", "hello-world build-push-from-registry"]

0 commit comments

Comments
 (0)