Skip to content

Commit

Permalink
Fixed merge conflicts, support multistage builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Priya Wadhwa committed Apr 26, 2018
2 parents cf713fe + 904575d commit 48688df
Show file tree
Hide file tree
Showing 1,012 changed files with 5,589 additions and 141,665 deletions.
354 changes: 23 additions & 331 deletions Gopkg.lock

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
revision = "83389a148052d74ac602f5f1d62f86ff2f3c4aa5"
source = "github.com/docker/distribution"

[[constraint]]
name = "github.com/GoogleContainerTools/container-diff"
branch = "master"
source = "github.com/GoogleContainerTools/container-diff"

[[constraint]]
name = "github.com/docker/docker"
revision = "b1a1234c60cf87048814aa37da523b03a7b0d344"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test: out/executor
@ ./test.sh

.PHONY: integration-test
integration-test: out/executor
integration-test:
@ ./integration-test.sh

.PHONY: images
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ Please let us know if you have any feature requests or find any bugs!


- [Kaniko](#kaniko)
- [How does kaniko work?](#how-does-kaniko-work?)
- [How does kaniko work?](#how-does-kaniko-work)
- [Known Issues](#known-issues)
- [Development](#development)
- [kaniko Build Contexts](#kaniko-build-contexts)
- [Running kaniko in a Kubernetes cluster](#running-kaniko-in-a-kubernetes-cluster)
- [Running kaniko in Google Container Builder](#running-kaniko-in-google-container-builder)
- [Running kaniko locally](#running-kaniko-locally)
- [Pushing to Different Registries](#pushing-to-different-registries)
- [Debug Image](#debug-image)
- [Security](#security)
- [Comparison with Other Tools](#comparison-with-other-tools)
- [Community](#community)
Expand All @@ -40,6 +41,8 @@ The majority of Dockerfile commands can be executed with kaniko, but we're still

Multi-Stage Dockerfiles are also unsupported currently, but will be ready soon.

kaniko also does not support building Windows containers.

## Development
### kaniko Build Contexts
kaniko supports local directories and GCS buckets as build contexts. To specify a local directory, pass in the `--context` flag as an argument to the executor image.
Expand Down Expand Up @@ -143,6 +146,10 @@ kaniko uses Docker credential helpers to push images to a registry.

kaniko comes with support for GCR, but configuring another credential helper should allow pushing to a different registry.

### Debug Image

We provide `gcr.io/kaniko-project/executor:debug` as a a version of the executor image based off a Debian image.
This provides a shell and can be useful for debugging.

## Security

Expand Down
25 changes: 13 additions & 12 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ import (

"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/executor"
"github.com/GoogleContainerTools/kaniko/pkg/image"
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var (
dockerfilePath string
destination string
srcContext string
snapshotMode string
bucket string
dockerInsecureSkipTLSVerify bool
logLevel string
force bool
dockerfilePath string
destination string
srcContext string
snapshotMode string
bucket string
logLevel string
force bool
)

func init() {
Expand All @@ -48,7 +46,6 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&bucket, "bucket", "b", "", "Name of the GCS bucket from which to access build context as tarball.")
RootCmd.PersistentFlags().StringVarP(&destination, "destination", "d", "", "Registry the final image should be pushed to (ex: gcr.io/test/example:latest)")
RootCmd.PersistentFlags().StringVarP(&snapshotMode, "snapshotMode", "", "full", "Set this flag to change the file attributes inspected during snapshotting")
RootCmd.PersistentFlags().BoolVarP(&dockerInsecureSkipTLSVerify, "insecure-skip-tls-verify", "", false, "Push to insecure registry ignoring TLS verify")
RootCmd.PersistentFlags().StringVarP(&logLevel, "verbosity", "v", constants.DefaultLogLevel, "Log level (debug, info, warn, error, fatal, panic")
RootCmd.PersistentFlags().BoolVarP(&force, "force", "", false, "Force building outside of a container")
}
Expand All @@ -72,12 +69,16 @@ var RootCmd = &cobra.Command{
}
logrus.Warn("kaniko is being run outside of a container. This can have dangerous effects on your system")
}
buildImage, err := executor.DoBuild(dockerfilePath, srcContext, snapshotMode)
if err := os.Chdir("/"); err != nil {
logrus.Error(err)
os.Exit(1)
}
ref, image, err := executor.DoBuild(dockerfilePath, srcContext, snapshotMode)
if err != nil {
logrus.Error(err)
os.Exit(1)
}
if err := image.PushImage(buildImage, destination, dockerInsecureSkipTLSVerify); err != nil {
if err := executor.DoPush(ref, image, destination); err != nil {
logrus.Error(err)
os.Exit(1)
}
Expand Down
9 changes: 5 additions & 4 deletions deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
# Builds the static Go image to execute in a Kubernetes job

FROM scratch
ADD out/executor /kaniko/executor
ADD files/ca-certificates.crt /kaniko/ssl/certs/
ADD files/docker-credential-gcr /usr/local/bin/
ADD files/config.json /root/.docker/
COPY out/executor /kaniko/executor
COPY files/ca-certificates.crt /kaniko/ssl/certs/
COPY files/docker-credential-gcr /usr/local/bin/
COPY files/config.json /root/.docker/
RUN ["docker-credential-gcr", "config", "--token-source=env"]
ENV HOME /root
ENV USER /root
ENV PATH /usr/local/bin
ENV SSL_CERT_DIR=/kaniko/ssl/certs
ENTRYPOINT ["/kaniko/executor"]
25 changes: 25 additions & 0 deletions deploy/Dockerfile_debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2018 Google, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Builds the executor from debian

FROM gcr.io/google-appengine/debian9:latest
COPY out/executor /kaniko/executor
COPY files/ca-certificates.crt /kaniko/ssl/certs/
COPY files/docker-credential-gcr /usr/local/bin/
COPY files/config.json /root/.docker/
RUN ["docker-credential-gcr", "config", "--token-source=env"]
ENV HOME /root
ENV SSL_CERT_DIR=/kaniko/ssl/certs
ENTRYPOINT ["/kaniko/executor"]
16 changes: 11 additions & 5 deletions deploy/executor-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ steps:
path: "/usr/bin"
dir: go/src/github.com/GoogleContainerTools/kaniko
env: ["GOPATH=/workspace/go/"]
# Then, build kaniko with kaniko
- name: "gcr.io/kaniko-project/executor:latest"
args: ["--dockerfile=/workspace/deploy/Dockerfile",
"--context=/workspace/go/src/github.com/GoogleContainerTools/kaniko/",
"--destination=gcr.io/kaniko-project/executor:${COMMIT_SHA}"]
# First, build kaniko
- name: "gcr.io/cloud-builders/docker"
args: ["build", "-f", "deploy/Dockerfile",
"-t", "gcr.io/kaniko-project/executor:${COMMIT_SHA}", "."]
dir: go/src/github.com/GoogleContainerTools/kaniko
# Then, build kaniko:debug
- name: "gcr.io/cloud-builders/docker"
args: ["build", "-f", "deploy/Dockerfile_debug",
"-t", "gcr.io/kaniko-project/executor:debug-${COMMIT_SHA}", "."]
dir: go/src/github.com/GoogleContainerTools/kaniko
images: ["gcr.io/kaniko-project/executor:${COMMIT_SHA}", "gcr.io/kaniko-project/executor:debug-${COMMIT_SHA}"]
3 changes: 3 additions & 0 deletions integration_tests/dockerfiles/Dockerfile_test_mv_add
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM busybox
ADD context/tars /tmp/tars
RUN mv /tmp/tars /foo
6 changes: 3 additions & 3 deletions integration_tests/dockerfiles/Dockerfile_test_run
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

FROM gcr.io/google-appengine/debian9
RUN echo "hey" > /etc/foo
RUN apt-get update && apt-get install -y \
bzr \
cvs \
RUN echo "baz" > /etc/baz
RUN cp /etc/baz /etc/bar
RUN rm /etc/baz
4 changes: 0 additions & 4 deletions integration_tests/dockerfiles/Dockerfile_test_scratch

This file was deleted.

12 changes: 12 additions & 0 deletions integration_tests/dockerfiles/config_test_mv_add.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"Image1": "gcr.io/kaniko-test/docker-test-mv-add:latest",
"Image2": "gcr.io/kaniko-test/kaniko-test-mv-add:latest",
"DiffType": "File",
"Diff": {
"Adds": null,
"Dels": null,
"Mods": null
}
}
]
38 changes: 1 addition & 37 deletions integration_tests/dockerfiles/config_test_run.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,7 @@
"Diff": {
"Adds": null,
"Dels": null,
"Mods": [
{
"Name": "/var/log/dpkg.log",
"Size1": 57481,
"Size2": 57481
},
{
"Name": "/var/log/apt/term.log",
"Size1": 23671,
"Size2": 23671
},
{
"Name": "/var/cache/ldconfig/aux-cache",
"Size1": 8057,
"Size2": 8057
},
{
"Name": "/var/log/apt/history.log",
"Size1": 5661,
"Size2": 5661
},
{
"Name": "/var/log/alternatives.log",
"Size1": 2579,
"Size2": 2579
},
{
"Name": "/usr/lib/python2.7/dist-packages/keyrings/__init__.pyc",
"Size1": 140,
"Size2": 140
},
{
"Name": "/usr/lib/python2.7/dist-packages/lazr/__init__.pyc",
"Size1": 136,
"Size2": 136
}
]
"Mods": null
}
}
]
12 changes: 0 additions & 12 deletions integration_tests/dockerfiles/config_test_scratch.json

This file was deleted.

18 changes: 9 additions & 9 deletions integration_tests/integration_test_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ var fileTests = []struct {
kanikoContext: buildcontextPath,
repo: "test-add",
},
{
description: "test mv add",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_mv_add",
configPath: "/workspace/integration_tests/dockerfiles/config_test_mv_add.json",
dockerContext: buildcontextPath,
kanikoContext: buildcontextPath,
repo: "test-mv-add",
},
{
description: "test registry",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_registry",
Expand All @@ -131,14 +139,6 @@ var fileTests = []struct {
kanikoContext: buildcontextPath,
repo: "test-onbuild",
},
{
description: "test scratch",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_scratch",
configPath: "/workspace/integration_tests/dockerfiles/config_test_scratch.json",
dockerContext: buildcontextPath,
kanikoContext: buildcontextPath,
repo: "test-scratch",
},
{
description: "test multistage",
dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_multistage",
Expand Down Expand Up @@ -288,7 +288,7 @@ func main() {
}
compareOutputs := step{
Name: ubuntuImage,
Args: []string{"cmp", test.configPath, containerDiffOutputFile},
Args: []string{"cmp", "-b", test.configPath, containerDiffOutputFile},
}

y.Steps = append(y.Steps, dockerBuild, kaniko, pullKanikoImage, containerDiff, catContainerDiffOutput, compareOutputs)
Expand Down
Binary file added logo/Kaniko-Logo-Monochrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo/Kaniko-Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions logo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thank you @ggcarlosr for this awesome logo!
5 changes: 3 additions & 2 deletions pkg/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"path/filepath"
"strings"

"github.com/google/go-containerregistry/v1"

"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/containers/image/manifest"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/sirupsen/logrus"
)
Expand All @@ -40,7 +41,7 @@ type AddCommand struct {
// - If dest doesn't end with a slash, the filepath is inferred to be <dest>/<filename>
// 2. If <src> is a local tar archive:
// -If <src> is a local tar archive, it is unpacked at the dest, as 'tar -x' would
func (a *AddCommand) ExecuteCommand(config *manifest.Schema2Config) error {
func (a *AddCommand) ExecuteCommand(config *v1.Config) error {
srcs := a.cmd.SourcesAndDest[:len(a.cmd.SourcesAndDest)-1]
dest := a.cmd.SourcesAndDest[len(a.cmd.SourcesAndDest)-1]

Expand Down
7 changes: 4 additions & 3 deletions pkg/commands/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ limitations under the License.
package commands

import (
"github.com/containers/image/manifest"
"strings"

"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/v1"
"github.com/sirupsen/logrus"
"strings"
)

type CmdCommand struct {
Expand All @@ -29,7 +30,7 @@ type CmdCommand struct {

// ExecuteCommand executes the CMD command
// Argument handling is the same as RUN.
func (c *CmdCommand) ExecuteCommand(config *manifest.Schema2Config) error {
func (c *CmdCommand) ExecuteCommand(config *v1.Config) error {
logrus.Info("cmd: CMD")
var newCommand []string
if c.cmd.PrependShell {
Expand Down
12 changes: 6 additions & 6 deletions pkg/commands/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ package commands
import (
"testing"

"github.com/google/go-containerregistry/v1"

"github.com/GoogleContainerTools/kaniko/testutil"
"github.com/containers/image/manifest"
"github.com/containers/image/pkg/strslice"
"github.com/docker/docker/builder/dockerfile/instructions"
)

var cmdTests = []struct {
prependShell bool
cmdLine []string
expectedCmd strslice.StrSlice
expectedCmd []string
}{
{
prependShell: true,
cmdLine: []string{"echo", "cmd1"},
expectedCmd: strslice.StrSlice{"/bin/sh", "-c", "echo cmd1"},
expectedCmd: []string{"/bin/sh", "-c", "echo cmd1"},
},
{
prependShell: false,
cmdLine: []string{"echo", "cmd2"},
expectedCmd: strslice.StrSlice{"echo", "cmd2"},
expectedCmd: []string{"echo", "cmd2"},
},
}

func TestExecuteCmd(t *testing.T) {

cfg := &manifest.Schema2Config{
cfg := &v1.Config{
Cmd: nil,
}

Expand Down
Loading

0 comments on commit 48688df

Please sign in to comment.