@@ -10,20 +10,18 @@ import (
1010
1111 "github.com/docker/app/internal"
1212 "github.com/docker/app/types"
13+ "github.com/docker/cli/cli/command"
1314 "github.com/docker/docker/pkg/archive"
1415 "github.com/pkg/errors"
1516)
1617
1718const (
18- // CNABBaseImageName is the name of the base invocation image.
19- CNABBaseImageName = "docker/cnab-app-base"
19+ // DefaultCNABBaseImageName is the name of the default base invocation image.
20+ DefaultCNABBaseImageName = "docker/cnab-app-base"
2021
2122 dockerIgnore = "Dockerfile"
2223)
2324
24- var dockerFile = `FROM ` + CNABBaseImageName + `:` + internal .Version + `
25- COPY . .`
26-
2725func tarAdd (tarout * tar.Writer , path , file string ) error {
2826 payload , err := ioutil .ReadFile (file )
2927 if err != nil {
@@ -48,7 +46,7 @@ func tarAddBytes(tarout *tar.Writer, path string, payload []byte) error {
4846}
4947
5048// PackInvocationImageContext creates a Docker build context for building a CNAB invocation image
51- func PackInvocationImageContext (app * types.App , target io.Writer ) error {
49+ func PackInvocationImageContext (cli command. Cli , app * types.App , target io.Writer ) error {
5250 tarout := tar .NewWriter (target )
5351 defer tarout .Close ()
5452 prefix := fmt .Sprintf ("%s%s/" , app .Metadata ().Name , internal .AppExtension )
@@ -58,7 +56,7 @@ func PackInvocationImageContext(app *types.App, target io.Writer) error {
5856 if len (app .ParametersRaw ()) != 1 {
5957 return errors .New ("app should have one and only one parameters file" )
6058 }
61- if err := tarAddBytes (tarout , "Dockerfile" , []byte (dockerFile )); err != nil {
59+ if err := tarAddBytes (tarout , "Dockerfile" , []byte (dockerFile ( cli ) )); err != nil {
6260 return errors .Wrap (err , "failed to add Dockerfile to the invocation image build context" )
6361 }
6462 if err := tarAddBytes (tarout , ".dockerignore" , []byte (dockerIgnore )); err != nil {
@@ -148,3 +146,18 @@ func Unpack(appname, targetDir string) error {
148146 NoLchown : true ,
149147 })
150148}
149+
150+ // BaseInvocationImage returns the name and tag of the CNAB base invocation image
151+ func BaseInvocationImage (cli command.Cli ) string {
152+ img := DefaultCNABBaseImageName + `:` + internal .Version
153+ if cfg := cli .ConfigFile (); cfg != nil {
154+ if v , ok := cfg .PluginConfig ("app" , "base-invocation-image" ); ok {
155+ return v
156+ }
157+ }
158+ return img
159+ }
160+
161+ func dockerFile (cli command.Cli ) string {
162+ return fmt .Sprintf ("FROM %s\n COPY . ." , BaseInvocationImage (cli ))
163+ }
0 commit comments