Skip to content

Commit

Permalink
adding reproducible flag (#205)
Browse files Browse the repository at this point in the history
* adding reproducible test

* newer version of go-containerregistry

* new ImageOptions

* switch reproducible flag to default to false

* small fixes

* update dep
  • Loading branch information
sharifelgamal authored Jun 22, 2018
1 parent 4198901 commit a7c82cf
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
buildArgs multiArg
tarPath string
singleSnapshot bool
reproducible bool
)

func init() {
Expand All @@ -56,6 +57,7 @@ func init() {
RootCmd.PersistentFlags().BoolVarP(&force, "force", "", false, "Force building outside of a container")
RootCmd.PersistentFlags().StringVarP(&tarPath, "tarPath", "", "", "Path to save the image in as a tarball instead of pushing")
RootCmd.PersistentFlags().BoolVarP(&singleSnapshot, "single-snapshot", "", false, "Set this flag to take a single snapshot at the end of the build.")
RootCmd.PersistentFlags().BoolVarP(&reproducible, "reproducible", "", false, "Strip timestamps out of the image to make it reproducible")
}

var RootCmd = &cobra.Command{
Expand Down Expand Up @@ -87,6 +89,7 @@ var RootCmd = &cobra.Command{
SnapshotMode: snapshotMode,
Args: buildArgs,
SingleSnapshot: singleSnapshot,
Reproducible: reproducible,
})
if err != nil {
logrus.Error(err)
Expand Down
20 changes: 20 additions & 0 deletions integration/dockerfiles/Dockerfile_test_copy_reproducible
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM alpine:3.7
COPY context/foo foo
COPY context/foo /foodir/
COPY context/bar/b* bar/
COPY context/fo? /foo2
COPY context/bar/doesnotexist* context/foo hello
COPY ./context/empty /empty
COPY ./ dir/
COPY . newdir
COPY context/bar /baz/
COPY ["context/foo", "/tmp/foo" ]
COPY context/b* /baz/
COPY context/foo context/bar/ba? /test/
COPY context/arr[[]0].txt /mydir/
COPY context/bar/bat .

ENV contextenv ./context
COPY ${contextenv}/foo /tmp/foo2
COPY $contextenv/foo /tmp/foo3
COPY $contextenv/* /tmp/${contextenv}/
13 changes: 12 additions & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ func TestRun(t *testing.T) {
"Dockerfile_test_scratch": {"--single-snapshot"},
}

// TODO: remove test_user_run from this when https://github.com/GoogleContainerTools/container-diff/issues/237 is fixed
testsToIgnore := []string{"Dockerfile_test_user_run"}
bucketContextTests := []string{"Dockerfile_test_copy_bucket"}
reproducibleTests := []string{"Dockerfile_test_env"}

_, ex, _, _ := runtime.Caller(0)
cwd := filepath.Dir(ex)
Expand Down Expand Up @@ -161,6 +164,14 @@ func TestRun(t *testing.T) {
}
}

reproducibleFlag := ""
for _, d := range reproducibleTests {
if d == dockerfile {
reproducibleFlag = "--reproducible"
break
}
}

// build kaniko image
additionalFlags := append(buildArgs, additionalFlagsMap[dockerfile]...)
kanikoImage := strings.ToLower(testRepo + kanikoPrefix + dockerfile)
Expand All @@ -170,7 +181,7 @@ func TestRun(t *testing.T) {
"-v", cwd + ":/workspace",
executorImage,
"-f", path.Join(buildContextPath, dockerfilesPath, dockerfile),
"-d", kanikoImage,
"-d", kanikoImage, reproducibleFlag,
contextFlag, contextPath},
additionalFlags...)...,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerfile/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func Dependencies(index int, stages []instructions.Stage, buildArgs *BuildArgs)
if err != nil {
return nil, err
}
sourceImage, err = remote.Image(ref, auth, http.DefaultTransport)
sourceImage, err = remote.Image(ref, remote.WithAuth(auth), remote.WithTransport(http.DefaultTransport))
if err != nil {
return nil, err
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type KanikoBuildArgs struct {
SnapshotMode string
Args []string
SingleSnapshot bool
Reproducible bool
}

func DoBuild(k KanikoBuildArgs) (name.Reference, v1.Image, error) {
Expand Down Expand Up @@ -94,7 +95,7 @@ func DoBuild(k KanikoBuildArgs) (name.Reference, v1.Image, error) {
if err != nil {
return nil, nil, err
}
sourceImage, err = remote.Image(ref, auth, http.DefaultTransport)
sourceImage, err = remote.Image(ref, remote.WithAuth(auth), remote.WithTransport(http.DefaultTransport))
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -174,6 +175,14 @@ func DoBuild(k KanikoBuildArgs) (name.Reference, v1.Image, error) {
if err != nil {
return nil, nil, err
}

if k.Reproducible {
sourceImage, err = mutate.Canonical(sourceImage)
if err != nil {
return nil, nil, err
}
}

return ref, sourceImage, nil
}
if err := saveStageDependencies(index, stages, buildArgs.Clone()); err != nil {
Expand Down
165 changes: 142 additions & 23 deletions vendor/github.com/google/go-containerregistry/pkg/v1/mutate/mutate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a7c82cf

Please sign in to comment.