Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Commit

Permalink
Introduce --iidfile option
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Oct 22, 2019
1 parent 0c6905a commit 68360fb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
16 changes: 15 additions & 1 deletion e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package e2e

import (
"encoding/json"
"github.com/docker/app/internal/store"
"io/ioutil"
"os"
"path"
"strings"
"testing"
Expand All @@ -15,9 +17,12 @@ import (
func TestBuild(t *testing.T) {
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
cmd := info.configuredCmd
tmp := os.TempDir()
defer os.RemoveAll(tmp)

testDir := path.Join("testdata", "build")
cmd.Command = dockerCli.Command("app", "build", "--tag", "single:1.0.0", "-f", path.Join(testDir, "single.dockerapp"), testDir)
iidfile := path.Join(tmp, "iid")
cmd.Command = dockerCli.Command("app", "build", "--tag", "single:1.0.0", "--iidfile", iidfile, "-f", path.Join(testDir, "single.dockerapp"), testDir)
icmd.RunCmd(cmd).Assert(t, icmd.Success)

cfg := getDockerConfigDir(t, cmd)
Expand All @@ -34,6 +39,15 @@ func TestBuild(t *testing.T) {
cmd.Command = dockerCli.Command("inspect", ref)
icmd.RunCmd(cmd).Assert(t, icmd.Success)
}

_, err = os.Stat(iidfile)
assert.NilError(t, err)
bytes, err := ioutil.ReadFile(iidfile)
assert.NilError(t, err)
iid := string(bytes)
actualID, err := store.FromBundle(&bndl)
assert.NilError(t, err)
assert.Equal(t, iid, actualID)
})
}

Expand Down
25 changes: 19 additions & 6 deletions internal/commands/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/docker/app/internal/store"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -32,12 +33,13 @@ import (
)

type buildOptions struct {
noCache bool
progress string
pull bool
tag string
folder string
args []string
noCache bool
progress string
pull bool
tag string
folder string
imageIDFile string
args []string
}

func Cmd(dockerCli command.Cli) *cobra.Command {
Expand All @@ -63,6 +65,7 @@ func Cmd(dockerCli command.Cli) *cobra.Command {
flags.StringVarP(&opts.folder, "folder", "f", "", "Docker app folder containing application definition")
flags.BoolVar(&opts.pull, "pull", false, "Always attempt to pull a newer version of the image")
flags.StringArrayVar(&opts.args, "build-arg", []string{}, "Set build-time variables")
flags.StringVar(&opts.imageIDFile, "iidfile", "", "Write the app image ID to the file")

return cmd
}
Expand Down Expand Up @@ -138,6 +141,16 @@ func runBuild(dockerCli command.Cli, contextPath string, opt buildOptions) (refe
return nil, err
}

if opt.imageIDFile != "" {
id, err := store.FromBundle(bundle)
if err != nil {
return nil, err
}
if err = ioutil.WriteFile(opt.imageIDFile, []byte(id.String()), 0644); err != nil {
return nil, err
}
}

return packager.PersistInBundleStore(ref, bundle)
}

Expand Down

0 comments on commit 68360fb

Please sign in to comment.