mirror of
https://github.com/docker/compose.git
synced 2025-07-07 05:44:25 +02:00
Merge pull request #1381 from gtardif/fix_up_build
Fix compose up --build not forcing rebuild of present image
This commit is contained in:
commit
12ffdd1405
@ -69,11 +69,6 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.Image != "" {
|
|
||||||
if localImagePresent {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if service.Build != nil {
|
if service.Build != nil {
|
||||||
if localImagePresent && service.PullPolicy != types.PullPolicyBuild {
|
if localImagePresent && service.PullPolicy != types.PullPolicyBuild {
|
||||||
continue
|
continue
|
||||||
@ -82,6 +77,11 @@ func (s *composeService) ensureImagesExists(ctx context.Context, project *types.
|
|||||||
opts[imageName] = s.toBuildOptions(service, project.WorkingDir, imageName)
|
opts[imageName] = s.toBuildOptions(service, project.WorkingDir, imageName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if service.Image != "" {
|
||||||
|
if localImagePresent {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Buildx has no command to "just pull", see
|
// Buildx has no command to "just pull", see
|
||||||
// so we bake a temporary dockerfile that will just pull and export pulled image
|
// 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 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)
|
output := HTTPGetWithRetry(t, "http://localhost:8070", http.StatusOK, 2*time.Second, 20*time.Second)
|
||||||
assert.Assert(t, strings.Contains(output, "Hello from Nginx container"))
|
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) {
|
t.Run("no rebuild when up again", func(t *testing.T) {
|
||||||
res := c.RunDockerCmd("compose", "--project-directory", "fixtures/build-test", "up", "-d")
|
res := c.RunDockerCmd("compose", "--project-directory", "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) {
|
t.Run("cleanup build project", func(t *testing.T) {
|
||||||
|
@ -5,5 +5,5 @@ services:
|
|||||||
- 8070:80
|
- 8070:80
|
||||||
|
|
||||||
nginx2:
|
nginx2:
|
||||||
build: nginx-build
|
build: nginx-build2
|
||||||
image: custom-nginx
|
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…
x
Reference in New Issue
Block a user