Skip to content

Commit e806acc

Browse files
authored
Merge pull request docker#9481 from glours/add-tags-to-build
add tags property to build section
2 parents 285a9c9 + a2770b6 commit e806acc

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

pkg/compose/build.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ func (s *composeService) toBuildOptions(project *types.Project, service types.Se
275275
sessionConfig = append(sessionConfig, p)
276276
}
277277

278+
if len(service.Build.Tags) > 0 {
279+
tags = append(tags, service.Build.Tags...)
280+
}
281+
278282
return build.Options{
279283
Inputs: build.Inputs{
280284
ContextPath: service.Build.Context,

pkg/e2e/compose_build_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,24 @@ func TestBuildSecrets(t *testing.T) {
181181
res.Assert(t, icmd.Success)
182182
})
183183
}
184+
185+
func TestBuildTags(t *testing.T) {
186+
c := NewParallelE2eCLI(t, binDir)
187+
188+
t.Run("build with tags", func(t *testing.T) {
189+
190+
// ensure local test run does not reuse previously build image
191+
c.RunDockerOrExitError("rmi", "build-test-tags")
192+
193+
c.RunDockerComposeCmd("--project-directory", "./fixtures/build-test/tags", "build", "--no-cache")
194+
195+
res := c.RunDockerCmd("image", "inspect", "build-test-tags")
196+
expectedOutput := `"RepoTags": [
197+
"docker/build-test-tags:1.0.0",
198+
"build-test-tags:latest",
199+
"other-image-name:v1.0.0"
200+
],
201+
`
202+
res.Assert(t, icmd.Expected{Out: expectedOutput})
203+
})
204+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2020 Docker Compose CLI authors
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM nginx:alpine
16+
17+
RUN echo "SUCCESS"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
nginx:
3+
image: build-test-tags
4+
build:
5+
context: .
6+
tags:
7+
- docker.io/docker/build-test-tags:1.0.0
8+
- other-image-name:v1.0.0
9+

0 commit comments

Comments
 (0)