diff --git a/tests/compose-e2e/compose_test.go b/tests/compose-e2e/compose_test.go index 47ff71c31..72ce59d52 100644 --- a/tests/compose-e2e/compose_test.go +++ b/tests/compose-e2e/compose_test.go @@ -103,6 +103,42 @@ func TestLocalComposeUp(t *testing.T) { }) } +func TestLocalComposeBuild(t *testing.T) { + c := NewParallelE2eCLI(t, binDir) + + t.Run("build named and unnamed images", func(t *testing.T) { + //ensure local test run does not reuse previously build image + c.RunDockerOrExitError("rmi", "build-test_nginx") + c.RunDockerOrExitError("rmi", "custom-nginx") + + res := c.RunDockerCmd("compose", "build", "--workdir", "fixtures/build-test") + + res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) + c.RunDockerCmd("image", "inspect", "build-test_nginx") + c.RunDockerCmd("image", "inspect", "custom-nginx") + }) + + t.Run("build as part of up", func(t *testing.T) { + c.RunDockerOrExitError("rmi", "build-test_nginx") + c.RunDockerOrExitError("rmi", "custom-nginx") + + res := c.RunDockerCmd("compose", "up", "-d", "--workdir", "fixtures/build-test") + + res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"}) + + output := HTTPGetWithRetry(t, "http://localhost:8070", http.StatusOK, 2*time.Second, 20*time.Second) + assert.Assert(t, strings.Contains(output, "Hello from Nginx container")) + + c.RunDockerCmd("image", "inspect", "build-test_nginx") + c.RunDockerCmd("image", "inspect", "custom-nginx") + }) + + t.Run("cleanup build project", func(t *testing.T) { + c.RunDockerCmd("compose", "down", "--workdir", "fixtures/build-test") + c.RunDockerCmd("rmi", "build-test_nginx") + c.RunDockerCmd("rmi", "custom-nginx") + }) +} func TestLocalComposeVolume(t *testing.T) { c := NewParallelE2eCLI(t, binDir) @@ -127,7 +163,7 @@ func TestLocalComposeVolume(t *testing.T) { }) t.Run("cleanup volume project", func(t *testing.T) { - _ = c.RunDockerCmd("compose", "down", "--project-name", projectName) - _ = c.RunDockerCmd("volume", "rm", projectName+"_staticVol") + c.RunDockerCmd("compose", "down", "--project-name", projectName) + c.RunDockerCmd("volume", "rm", projectName+"_staticVol") }) } diff --git a/tests/compose-e2e/fixtures/build-test/docker-compose.yml b/tests/compose-e2e/fixtures/build-test/docker-compose.yml new file mode 100644 index 000000000..0e7f2c123 --- /dev/null +++ b/tests/compose-e2e/fixtures/build-test/docker-compose.yml @@ -0,0 +1,9 @@ +services: + nginx: + build: nginx-build + ports: + - 8070:80 + + nginx2: + build: nginx-build + image: custom-nginx diff --git a/tests/compose-e2e/fixtures/build-test/nginx-build/Dockerfile b/tests/compose-e2e/fixtures/build-test/nginx-build/Dockerfile new file mode 100644 index 000000000..766ec01e2 --- /dev/null +++ b/tests/compose-e2e/fixtures/build-test/nginx-build/Dockerfile @@ -0,0 +1,17 @@ +# Copyright 2020 Docker Compose CLI authors + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM nginx + +COPY static /usr/share/nginx/html diff --git a/tests/compose-e2e/fixtures/build-test/nginx-build/static/index.html b/tests/compose-e2e/fixtures/build-test/nginx-build/static/index.html new file mode 100644 index 000000000..63159b9e9 --- /dev/null +++ b/tests/compose-e2e/fixtures/build-test/nginx-build/static/index.html @@ -0,0 +1,10 @@ + + +
+ +