Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = logoutLocalRegistry()
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"]