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

Commit

Permalink
Add e2e test for building from private reg
Browse files Browse the repository at this point in the history
Updates the e2e test for building from a private registry during
build-push. First build and push a base image and remove it locally then
build and push an image based on it.

Signed-off-by: Nick Adcock <nick.adcock@docker.com>
  • Loading branch information
zappy-shu committed Mar 20, 2020
1 parent 5ebd304 commit cdab64c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 22 deletions.
76 changes: 55 additions & 21 deletions e2e/build_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,13 @@ import (
"gotest.tools/v3/assert"
)

func TestBuildPush(t *testing.T) {
tags := []string{
"localhost:5000/my-repository:build-push-tag1",
"localhost:5000/my-repository:build-push-test",
}
labels := map[string]string{
"a": "a1",
}
func testBuildPush(t *testing.T, envFile string, tags []string, labels map[string]string) {
err := removeImages(tags)
assert.NilError(t, err)
defer removeImages(tags)

err = setupLocalRegistry()
assert.NilError(t, err)
defer removeLocalRegistry()

err = loginLocalRegistry()
assert.NilError(t, err)

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

for _, tag := range tags {
assertBuildPushImages(t, tag, tags, labels)
}

err = removeImages(tags)
assert.NilError(t, err)

Expand All @@ -47,6 +28,47 @@ func TestBuildPush(t *testing.T) {
}
}

func TestBuildPush(t *testing.T) {
err := setupLocalRegistry()
assert.NilError(t, err)
defer removeLocalRegistry()

err = ensureLocalRegistryAlive()
assert.NilError(t, err)

// Build and push base image
baseTags := []string{
"localhost:5000/org/base:build-push-tag1",
"localhost:5000/org/base:build-push-test",
}
defer removeImages(baseTags)
testBuildPush(
t,
"testdata/build_push_tests/build_push.env",
baseTags,
map[string]string{
"a": "a1",
},
)

err = exec.Command("docker", "logout", "localhost:5000").Run()
assert.NilError(t, err)

// Build and push image using base image from local registry
testBuildPush(
t,
"testdata/build_push_tests/build_push_from_registry.env",
[]string{
"localhost:5000/org/repo:build-push-reg-tag1",
"localhost:5000/org/repo:build-push-reg-test",
},
map[string]string{
"a": "a1",
"b": "b1",
},
)
}

func assertBuildPushImages(t *testing.T, image string, expectedTags []string, expectedLabels map[string]string) {
inspect, err := inspectImage(image)
assert.NilError(t, err)
Expand All @@ -57,3 +79,15 @@ func assertBuildPushImages(t *testing.T, image string, expectedTags []string, ex
assert.DeepEqual(t, expectedTags, repoTags)
assert.DeepEqual(t, expectedLabels, inspect.Config.Labels)
}

func ensureLocalRegistryAlive() error {
if err := loginLocalRegistry(); err != nil {
return err
}

return logoutLocalRegistry()
}

func logoutLocalRegistry() error {
return exec.Command("docker", "logout", "localhost:5000").Run()
}
1 change: 1 addition & 0 deletions e2e/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestLogin(t *testing.T) {
}

func loginLocalRegistry() error {
// Polls as registry takes a moment to start up
return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
err := runActionsCommand("login", "testdata/login_test.env")
return err == nil, err
Expand Down
2 changes: 1 addition & 1 deletion e2e/testdata/build_push_tests/build_push.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ INPUT_LABELS=a=a1
INPUT_REGISTRY=localhost:5000
INPUT_USERNAME=my_user
INPUT_PASSWORD=my_password
INPUT_REPOSITORY=my-repository
INPUT_REPOSITORY=org/base
INPUT_PUSH=true
GITHUB_REF=refs/tags/build-push-tag1
11 changes: 11 additions & 0 deletions e2e/testdata/build_push_tests/build_push_from_registry.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
INPUT_PATH=./testdata/build_push_tests
INPUT_DOCKERFILE=./testdata/build_push_tests/fromreg.Dockerfile
INPUT_TAG_WITH_REF=true
INPUT_TAGS=build-push-reg-test
INPUT_LABELS=b=b1
INPUT_REGISTRY=localhost:5000
INPUT_USERNAME=my_user
INPUT_PASSWORD=my_password
INPUT_REPOSITORY=org/repo
INPUT_PUSH=true
GITHUB_REF=refs/tags/build-push-reg-tag1
3 changes: 3 additions & 0 deletions e2e/testdata/build_push_tests/fromreg.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM localhost:5000/org/base:build-push-test

ENTRYPOINT ["echo", "hello-world build-push-from-registry"]

0 comments on commit cdab64c

Please sign in to comment.