瀏覽代碼

Adding compose build e2e test

Signed-off-by: Guillaume Tardif <[email protected]>
Guillaume Tardif 4 年之前
父節點
當前提交
c806b75940

+ 38 - 2
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")
 	})
 }

+ 9 - 0
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

+ 17 - 0
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

+ 10 - 0
tests/compose-e2e/fixtures/build-test/nginx-build/static/index.html

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

+ 1 - 1
tests/compose-e2e/fixtures/volume-test/nginx-build/Dockerfile

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

+ 1 - 1
tests/compose-e2e/fixtures/volume-test/static/index.html

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