Add e2e test for building from private reg

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>
This commit is contained in:
Nick Adcock 2020-03-20 13:50:15 +00:00
Родитель 5ebd304927
Коммит cd2d03d9e9
5 изменённых файлов: 71 добавлений и 22 удалений

Просмотреть файл

@ -8,31 +8,12 @@ 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()
err = runActionsCommand("build-push", envFile)
assert.NilError(t, err)
defer removeLocalRegistry()
err = loginLocalRegistry()
assert.NilError(t, err)
err = runActionsCommand("build-push", "testdata/build_push_tests/build_push.env")
assert.NilError(t, err)
for _, tag := range tags {
assertBuildPushImages(t, tag, tags, labels)
}
err = removeImages(tags)
assert.NilError(t, err)
@ -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)
@ -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()
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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
e2e/testdata/build_push_tests/build_push_from_registry.env поставляемый Normal file
Просмотреть файл

@ -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
e2e/testdata/build_push_tests/fromreg.Dockerfile поставляемый Normal file
Просмотреть файл

@ -0,0 +1,3 @@
FROM localhost:5000/org/base:build-push-test
ENTRYPOINT ["echo", "hello-world build-push-from-registry"]