Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 163c9e0

Browse files
committed
introduce --no-resolve-image
Aligned with docker service create --no-resolve-image Prevent image freeze during the build Usefull for offline builds, as well as for our e2e tests :P Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 8a1a9f0 commit 163c9e0

File tree

4 files changed

+25
-26
lines changed

4 files changed

+25
-26
lines changed

e2e/commands_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func TestInspectApp(t *testing.T) {
165165
})
166166

167167
contextPath := filepath.Join("testdata", "simple")
168-
cmd.Command = dockerCli.Command("app", "build", "--tag", "simple-app:1.0.0", contextPath)
168+
cmd.Command = dockerCli.Command("app", "build", "--tag", "simple-app:1.0.0", "--no-resolve-image", contextPath)
169169
cmd.Dir = ""
170170
icmd.RunCmd(cmd).Assert(t, icmd.Success)
171171

e2e/testdata/expected-json-render.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"resources": {},
1818
"placement": {}
1919
},
20-
"image": "python:3.6@sha256:52f872eae9755743c9494e0e3cf02a47d34b42032cab1e5ab777b30c3665d5f1",
20+
"image": "python:3.6",
2121
"networks": {
2222
"back": null,
2323
"front": {
@@ -35,7 +35,7 @@
3535
"resources": {},
3636
"placement": {}
3737
},
38-
"image": "postgres:9.3@sha256:3cd40afb5803762170a1149ade6962fe24d405b3ccf2fe499ff1428635520a17",
38+
"image": "postgres:9.3",
3939
"networks": {
4040
"back": null
4141
}
@@ -47,7 +47,7 @@
4747
"resources": {},
4848
"placement": {}
4949
},
50-
"image": "nginx:latest@sha256:922c815aa4df050d4df476e92daed4231f466acc8ee90e0e774951b0fd7195a4",
50+
"image": "nginx:latest",
5151
"networks": {
5252
"front": null
5353
},

e2e/testdata/expected-yaml-render.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
version: "3.6"
22
services:
33
api:
4-
image: python:3.6@sha256:52f872eae9755743c9494e0e3cf02a47d34b42032cab1e5ab777b30c3665d5f1
4+
image: python:3.6
55
networks:
66
back: null
77
front:
88
aliases:
99
- api.example.com
1010
- example.com
1111
db:
12-
image: postgres:9.3@sha256:3cd40afb5803762170a1149ade6962fe24d405b3ccf2fe499ff1428635520a17
12+
image: postgres:9.3
1313
networks:
1414
back: null
1515
web:
16-
image: nginx:latest@sha256:922c815aa4df050d4df476e92daed4231f466acc8ee90e0e774951b0fd7195a4
16+
image: nginx:latest
1717
networks:
1818
front: null
1919
ports:

internal/commands/build/build.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"errors"
87
"fmt"
98
"io/ioutil"
109
"os"
1110
"path/filepath"
1211
"strconv"
1312
"strings"
1413

15-
errors2 "github.com/pkg/errors"
16-
17-
"github.com/docker/app/internal"
18-
"github.com/docker/cnab-to-oci/remotes"
19-
2014
"github.com/deislabs/cnab-go/bundle"
2115
cnab "github.com/deislabs/cnab-go/driver"
16+
"github.com/docker/app/internal"
2217
"github.com/docker/app/internal/packager"
2318
"github.com/docker/app/types"
2419
"github.com/docker/buildx/build"
@@ -27,24 +22,27 @@ import (
2722
"github.com/docker/buildx/util/progress"
2823
"github.com/docker/cli/cli"
2924
"github.com/docker/cli/cli/command"
25+
"github.com/docker/cnab-to-oci/remotes"
3026
"github.com/docker/distribution/reference"
3127
"github.com/moby/buildkit/client"
3228
"github.com/moby/buildkit/session"
3329
"github.com/moby/buildkit/session/auth/authprovider"
3430
"github.com/moby/buildkit/util/appcontext"
31+
"github.com/pkg/errors"
3532
"github.com/sirupsen/logrus"
3633
"github.com/spf13/cobra"
3734
)
3835

3936
type buildOptions struct {
40-
noCache bool
41-
progress string
42-
pull bool
43-
tag string
44-
folder string
45-
imageIDFile string
46-
args []string
47-
quiet bool
37+
noCache bool
38+
progress string
39+
pull bool
40+
tag string
41+
folder string
42+
imageIDFile string
43+
args []string
44+
quiet bool
45+
noResolveImage bool
4846
}
4947

5048
func Cmd(dockerCli command.Cli) *cobra.Command {
@@ -63,6 +61,7 @@ $ docker app build . -f myapp.dockerapp -t myrepo/myapp:1.0.0`,
6361
flags := cmd.Flags()
6462
flags.BoolVar(&opts.noCache, "no-cache", false, "Do not use cache when building the App image")
6563
flags.StringVar(&opts.progress, "progress", "auto", "Set type of progress output (auto, plain, tty). Use plain to show container output")
64+
flags.BoolVar(&opts.noResolveImage, "no-resolve-image", false, "Do not query the registry to resolve image digest")
6665
flags.StringVarP(&opts.tag, "tag", "t", "", "App image tag, optionally in the 'repo:tag' format")
6766
flags.StringVarP(&opts.folder, "folder", "f", "", "App definition as a .dockerapp directory")
6867
flags.BoolVar(&opts.pull, "pull", false, "Always attempt to pull a newer version of the App image")
@@ -196,22 +195,22 @@ func buildImageUsingBuildx(app *types.App, contextPath string, opt buildOptions,
196195
func fixServiceImageReferences(ctx context.Context, dockerCli command.Cli, bundle *bundle.Bundle, pulledServices []ServiceConfig) error {
197196
insecureRegistries, err := internal.InsecureRegistriesFromEngine(dockerCli)
198197
if err != nil {
199-
return errors2.Wrapf(err, "could not retrieve insecure registries")
198+
return errors.Wrapf(err, "could not retrieve insecure registries")
200199
}
201200
resolver := remotes.CreateResolver(dockerCli.ConfigFile(), insecureRegistries...)
202201
for _, service := range pulledServices {
203202
image := bundle.Images[service.Name]
204203
ref, err := reference.ParseNormalizedNamed(*service.Image)
205204
if err != nil {
206-
return errors2.Wrapf(err, "could not resolve image %s", *service.Image)
205+
return errors.Wrapf(err, "could not resolve image %s", *service.Image)
207206
}
208207
_, desc, err := resolver.Resolve(ctx, ref.String())
209208
if err != nil {
210-
return errors2.Wrapf(err, "could not resolve image %s", ref.Name())
209+
return errors.Wrapf(err, "could not resolve image %s", ref.Name())
211210
}
212211
canonical, err := reference.WithDigest(ref, desc.Digest)
213212
if err != nil {
214-
return errors2.Wrapf(err, "could not resolve image %s", ref.Name())
213+
return errors.Wrapf(err, "could not resolve image %s", ref.Name())
215214
}
216215
image.Image = canonical.String()
217216
bundle.Images[service.Name] = image
@@ -251,7 +250,7 @@ func checkMinimalEngineVersion(dockerCli command.Cli) error {
251250
return err
252251
}
253252
if majorVersion < 19 {
254-
return errors.New("'build' require docker engine 19.03 or later")
253+
return fmt.Errorf("'build' require docker engine 19.03 or later")
255254
}
256255
return nil
257256
}

0 commit comments

Comments
 (0)