mirror of https://github.com/docker/compose.git
Fix compose up --build not forcing rebuild of present image
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
parent
e254c26b88
commit
8b6e356af4
|
@ -65,11 +65,6 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
|
|||
return err
|
||||
}
|
||||
|
||||
if service.Image != "" {
|
||||
if localImagePresent {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if service.Build != nil {
|
||||
if localImagePresent && service.PullPolicy != types.PullPolicyBuild {
|
||||
continue
|
||||
|
@ -78,6 +73,11 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
|
|||
opts[imageName] = s.toBuildOptions(service, project.WorkingDir, imageName)
|
||||
continue
|
||||
}
|
||||
if service.Image != "" {
|
||||
if localImagePresent {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Buildx has no command to "just pull", see
|
||||
// so we bake a temporary dockerfile that will just pull and export pulled image
|
||||
|
|
|
@ -53,6 +53,7 @@ func TestLocalComposeBuild(t *testing.T) {
|
|||
})
|
||||
|
||||
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
|
||||
res.Assert(t, icmd.Expected{Out: "COPY static2 /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"))
|
||||
|
@ -64,7 +65,14 @@ func TestLocalComposeBuild(t *testing.T) {
|
|||
t.Run("no rebuild when up again", func(t *testing.T) {
|
||||
res := c.RunDockerCmd("compose", "--workdir", "fixtures/build-test", "up", "-d")
|
||||
|
||||
assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static /usr/share/nginx/html"), res.Stdout())
|
||||
assert.Assert(t, !strings.Contains(res.Stdout(), "COPY static"), res.Stdout())
|
||||
})
|
||||
|
||||
t.Run("rebuild when up --build", func(t *testing.T) {
|
||||
res := c.RunDockerCmd("compose", "--workdir", "fixtures/build-test", "up", "-d", "--build")
|
||||
|
||||
res.Assert(t, icmd.Expected{Out: "COPY static /usr/share/nginx/html"})
|
||||
res.Assert(t, icmd.Expected{Out: "COPY static2 /usr/share/nginx/html"})
|
||||
})
|
||||
|
||||
t.Run("cleanup build project", func(t *testing.T) {
|
||||
|
|
|
@ -5,5 +5,5 @@ services:
|
|||
- 8070:80
|
||||
|
||||
nginx2:
|
||||
build: nginx-build
|
||||
build: nginx-build2
|
||||
image: custom-nginx
|
||||
|
|
|
@ -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 static2 /usr/share/nginx/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>
|
Loading…
Reference in New Issue