Adding compose build e2e test

Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
Guillaume Tardif 2020-12-09 17:36:33 +01:00
parent a95a76291b
commit c806b75940
6 changed files with 76 additions and 4 deletions

View File

@ -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) { func TestLocalComposeVolume(t *testing.T) {
c := NewParallelE2eCLI(t, binDir) c := NewParallelE2eCLI(t, binDir)
@ -127,7 +163,7 @@ func TestLocalComposeVolume(t *testing.T) {
}) })
t.Run("cleanup volume project", func(t *testing.T) { t.Run("cleanup volume project", func(t *testing.T) {
_ = c.RunDockerCmd("compose", "down", "--project-name", projectName) c.RunDockerCmd("compose", "down", "--project-name", projectName)
_ = c.RunDockerCmd("volume", "rm", projectName+"_staticVol") c.RunDockerCmd("volume", "rm", projectName+"_staticVol")
}) })
} }

View File

@ -0,0 +1,9 @@
services:
nginx:
build: nginx-build
ports:
- 8070:80
nginx2:
build: nginx-build
image: custom-nginx

View File

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

View File

@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Docker Nginx</title>
</head>
<body>
<h2>Hello from Nginx container</h2>
</body>
</html>

View File

@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
FROM nginx FROM nginx

View File

@ -7,4 +7,4 @@
<body> <body>
<h2>Hello from Nginx container</h2> <h2>Hello from Nginx container</h2>
</body> </body>
</html> </html>