mirror of
https://github.com/drone/drone-kaniko.git
synced 2026-06-14 05:12:27 +08:00
Compare commits
26 Commits
version_update
...
v1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| df81f82f84 | |||
| 43db3f2ccc | |||
| 71f15eb3f4 | |||
| 4612825d41 | |||
| 0933926fe2 | |||
| 658478d5ae | |||
| 9cca954ec6 | |||
| 3e4dad8cae | |||
| 69d5e73564 | |||
| b33681a9b9 | |||
| cdd1510210 | |||
| fa7726153d | |||
| 49309bfa42 | |||
| 428642719b | |||
| 33f15bdebe | |||
| 10df8f28b9 | |||
| 17072a25f1 | |||
| 26c93eccd1 | |||
| ee562a4a1b | |||
| e200b5c566 | |||
| 2c637d285e | |||
| 4be32f2451 | |||
| 5ba1a0ead7 | |||
| ef7bb68898 | |||
| 9a7b245d90 | |||
| 0d853fd119 |
+73
-1
@@ -14,30 +14,102 @@ steps:
|
|||||||
settings:
|
settings:
|
||||||
repo: plugins/kaniko
|
repo: plugins/kaniko
|
||||||
auto_tag: true
|
auto_tag: true
|
||||||
dockerfile: docker/gcr/Dockerfile.linux.amd64
|
auto_tag_suffix: linux-amd64
|
||||||
|
daemon_off: false
|
||||||
|
dockerfile: docker/docker/Dockerfile.linux.amd64
|
||||||
username:
|
username:
|
||||||
from_secret: docker_username
|
from_secret: docker_username
|
||||||
password:
|
password:
|
||||||
from_secret: docker_password
|
from_secret: docker_password
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
- name: gcr
|
- name: gcr
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
repo: plugins/kaniko-gcr
|
repo: plugins/kaniko-gcr
|
||||||
auto_tag: true
|
auto_tag: true
|
||||||
|
auto_tag_suffix: linux-amd64
|
||||||
|
daemon_off: false
|
||||||
dockerfile: docker/gcr/Dockerfile.linux.amd64
|
dockerfile: docker/gcr/Dockerfile.linux.amd64
|
||||||
username:
|
username:
|
||||||
from_secret: docker_username
|
from_secret: docker_username
|
||||||
password:
|
password:
|
||||||
from_secret: docker_password
|
from_secret: docker_password
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
- name: ecr
|
- name: ecr
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
repo: plugins/kaniko-ecr
|
repo: plugins/kaniko-ecr
|
||||||
auto_tag: true
|
auto_tag: true
|
||||||
|
auto_tag_suffix: linux-amd64
|
||||||
|
daemon_off: false
|
||||||
dockerfile: docker/ecr/Dockerfile.linux.amd64
|
dockerfile: docker/ecr/Dockerfile.linux.amd64
|
||||||
username:
|
username:
|
||||||
from_secret: docker_username
|
from_secret: docker_username
|
||||||
password:
|
password:
|
||||||
from_secret: docker_password
|
from_secret: docker_password
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: notifications-docker
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: manifest-docker
|
||||||
|
pull: always
|
||||||
|
image: plugins/manifest
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
ignore_missing: true
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
spec: docker/docker/manifest.tmpl
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
|
||||||
|
- name: manifest-gcr
|
||||||
|
pull: always
|
||||||
|
image: plugins/manifest
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
ignore_missing: true
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
spec: docker/gcr/manifest.tmpl
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
|
||||||
|
- name: manifest-ecr
|
||||||
|
pull: always
|
||||||
|
image: plugins/manifest
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
ignore_missing: true
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
spec: docker/ecr/manifest.tmpl
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- "refs/tags/**"
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- default
|
||||||
@@ -25,7 +25,7 @@ Build the Docker images with the following commands:
|
|||||||
docker build \
|
docker build \
|
||||||
--label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
|
--label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
|
||||||
--label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \
|
--label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \
|
||||||
--file docker/docker/Dockerfile.linux.amd64 --tag plugins/kaniko-docker .
|
--file docker/docker/Dockerfile.linux.amd64 --tag plugins/kaniko .
|
||||||
|
|
||||||
docker build \
|
docker build \
|
||||||
--label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
|
--label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
|
||||||
@@ -49,5 +49,5 @@ docker run --rm \
|
|||||||
-e PLUGIN_PASSWORD=bar \
|
-e PLUGIN_PASSWORD=bar \
|
||||||
-v $(pwd):/drone \
|
-v $(pwd):/drone \
|
||||||
-w /drone \
|
-w /drone \
|
||||||
plugins/kaniko-docker
|
plugins/kaniko:linux-amd64
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package artifact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
dockerArtifactV1 string = "docker/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RegistryTypeEnum string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Docker RegistryTypeEnum = "Docker"
|
||||||
|
ECR RegistryTypeEnum = "ECR"
|
||||||
|
GCR RegistryTypeEnum = "GCR"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Image struct {
|
||||||
|
Image string `json:"image"`
|
||||||
|
Digest string `json:"digest"`
|
||||||
|
}
|
||||||
|
Data struct {
|
||||||
|
RegistryType RegistryTypeEnum `json:"registryType"`
|
||||||
|
RegistryUrl string `json:"registryUrl"`
|
||||||
|
Images []Image `json:"images"`
|
||||||
|
}
|
||||||
|
DockerArtifact struct {
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
Data Data `json:"data"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func WritePluginArtifactFile(registryType RegistryTypeEnum, artifactFilePath, registryUrl, imageName, digest string, tags []string) error {
|
||||||
|
var images []Image
|
||||||
|
for _, tag := range tags {
|
||||||
|
images = append(images, Image{
|
||||||
|
Image: fmt.Sprintf("%s:%s", imageName, tag),
|
||||||
|
Digest: digest,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
data := Data{
|
||||||
|
RegistryType: registryType,
|
||||||
|
RegistryUrl: registryUrl,
|
||||||
|
Images: images,
|
||||||
|
}
|
||||||
|
|
||||||
|
dockerArtifact := DockerArtifact{
|
||||||
|
Kind: dockerArtifactV1,
|
||||||
|
Data: data,
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := json.MarshalIndent(dockerArtifact, "", "\t")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, fmt.Sprintf("failed to marshal output %+v", dockerArtifact))
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := filepath.Dir(artifactFilePath)
|
||||||
|
err = os.MkdirAll(dir, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, fmt.Sprintf("failed to create %s directory for artifact file", dir))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(artifactFilePath, b, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, fmt.Sprintf("failed to write artifact to artifact file %s", artifactFilePath))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"kind": "docker/v1",
|
||||||
|
"data": {
|
||||||
|
"registryType": "Docker",
|
||||||
|
"registryUrl": "https://index.docker.io/",
|
||||||
|
"images": [
|
||||||
|
{
|
||||||
|
"image": "image:a1",
|
||||||
|
"digest": "sha256:22332233"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"image": "image:latest",
|
||||||
|
"digest": "sha256:22332233"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package artifact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWritePluginArtifactFile(t *testing.T) {
|
||||||
|
|
||||||
|
testFile := t.TempDir() + "got.json"
|
||||||
|
|
||||||
|
err := WritePluginArtifactFile(Docker, testFile, "https://index.docker.io/", "image", "sha256:22332233", []string{"a1", "latest"})
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
gotBytes, err := ioutil.ReadFile(testFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
wantBytes, err := ioutil.ReadFile("./artifact.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
got := string(gotBytes)
|
||||||
|
want := string(wantBytes)
|
||||||
|
|
||||||
|
if got != want {
|
||||||
|
t.Logf("got:%s", got)
|
||||||
|
t.Logf("want:%s", want)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,12 +12,18 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
kaniko "github.com/drone/drone-kaniko"
|
kaniko "github.com/drone/drone-kaniko"
|
||||||
|
"github.com/drone/drone-kaniko/cmd/artifact"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Docker file path
|
// Docker file path
|
||||||
dockerPath string = "/kaniko/.docker"
|
dockerPath string = "/kaniko/.docker"
|
||||||
dockerConfigPath string = "/kaniko/.docker/config.json"
|
dockerConfigPath string = "/kaniko/.docker/config.json"
|
||||||
|
|
||||||
|
v1Registry string = "https://index.docker.io/v1/" // Default registry
|
||||||
|
v2Registry string = "https://index.docker.io/v2/" // v2 registry is not supported
|
||||||
|
|
||||||
|
defaultDigestFile string = "/kaniko/digest-file"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -78,7 +84,7 @@ func main() {
|
|||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "registry",
|
Name: "registry",
|
||||||
Usage: "docker registry",
|
Usage: "docker registry",
|
||||||
Value: "https://index.docker.io/v1/",
|
Value: v1Registry,
|
||||||
EnvVar: "PLUGIN_REGISTRY",
|
EnvVar: "PLUGIN_REGISTRY",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
@@ -91,6 +97,36 @@ func main() {
|
|||||||
Usage: "docker password",
|
Usage: "docker password",
|
||||||
EnvVar: "PLUGIN_PASSWORD",
|
EnvVar: "PLUGIN_PASSWORD",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "skip-tls-verify",
|
||||||
|
Usage: "Skip registry tls verify",
|
||||||
|
EnvVar: "PLUGIN_SKIP_TLS_VERIFY",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "snapshot-mode",
|
||||||
|
Usage: "Specify one of full, redo or time as snapshot mode",
|
||||||
|
EnvVar: "PLUGIN_SNAPSHOT_MODE",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "enable-cache",
|
||||||
|
Usage: "Set this flag to opt into caching with kaniko",
|
||||||
|
EnvVar: "PLUGIN_ENABLE_CACHE",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "cache-repo",
|
||||||
|
Usage: "Remote repository that will be used to store cached layers. enable-cache needs to be set to use this flag",
|
||||||
|
EnvVar: "PLUGIN_CACHE_REPO",
|
||||||
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "cache-ttl",
|
||||||
|
Usage: "Cache timeout in hours. Defaults to two weeks.",
|
||||||
|
EnvVar: "PLUGIN_CACHE_TTL",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "artifact-file",
|
||||||
|
Usage: "Artifact file location that will be generated by the plugin. This file will include information of docker images that are uploaded by the plugin.",
|
||||||
|
EnvVar: "PLUGIN_ARTIFACT_FILE",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
@@ -106,13 +142,26 @@ func run(c *cli.Context) error {
|
|||||||
|
|
||||||
plugin := kaniko.Plugin{
|
plugin := kaniko.Plugin{
|
||||||
Build: kaniko.Build{
|
Build: kaniko.Build{
|
||||||
Dockerfile: c.String("dockerfile"),
|
Dockerfile: c.String("dockerfile"),
|
||||||
Context: c.String("context"),
|
Context: c.String("context"),
|
||||||
Tags: c.StringSlice("tags"),
|
Tags: c.StringSlice("tags"),
|
||||||
Args: c.StringSlice("args"),
|
Args: c.StringSlice("args"),
|
||||||
Target: c.String("target"),
|
Target: c.String("target"),
|
||||||
Repo: c.String("repo"),
|
Repo: c.String("repo"),
|
||||||
Labels: c.StringSlice("custom-labels"),
|
Labels: c.StringSlice("custom-labels"),
|
||||||
|
SkipTlsVerify: c.Bool("skip-tls-verify"),
|
||||||
|
SnapshotMode: c.String("snapshot-mode"),
|
||||||
|
EnableCache: c.Bool("enable-cache"),
|
||||||
|
CacheRepo: c.String("cache-repo"),
|
||||||
|
CacheTTL: c.Int("cache-ttl"),
|
||||||
|
DigestFile: defaultDigestFile,
|
||||||
|
},
|
||||||
|
Artifact: kaniko.Artifact{
|
||||||
|
Tags: c.StringSlice("tags"),
|
||||||
|
Repo: c.String("repo"),
|
||||||
|
Registry: c.String("registry"),
|
||||||
|
ArtifactFile: c.String("artifact-file"),
|
||||||
|
RegistryType: artifact.Docker,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return plugin.Exec()
|
return plugin.Exec()
|
||||||
@@ -130,6 +179,12 @@ func createDockerCfgFile(username, password, registry string) error {
|
|||||||
return fmt.Errorf("Registry must be specified")
|
return fmt.Errorf("Registry must be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if registry == v2Registry {
|
||||||
|
fmt.Println("Docker v2 registry is not supported in kaniko. Refer issue: https://github.com/GoogleContainerTools/kaniko/issues/1209")
|
||||||
|
fmt.Printf("Using v1 registry instead: %s\n", v1Registry)
|
||||||
|
registry = v1Registry
|
||||||
|
}
|
||||||
|
|
||||||
err := os.MkdirAll(dockerPath, 0600)
|
err := os.MkdirAll(dockerPath, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, fmt.Sprintf("failed to create %s directory", dockerPath))
|
return errors.Wrap(err, fmt.Sprintf("failed to create %s directory", dockerPath))
|
||||||
|
|||||||
+61
-24
@@ -11,12 +11,15 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
kaniko "github.com/drone/drone-kaniko"
|
kaniko "github.com/drone/drone-kaniko"
|
||||||
|
"github.com/drone/drone-kaniko/cmd/artifact"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
accessKeyEnv string = "AWS_ACCESS_KEY_ID"
|
accessKeyEnv string = "AWS_ACCESS_KEY_ID"
|
||||||
secretKeyEnv string = "AWS_SECRET_ACCESS_KEY"
|
secretKeyEnv string = "AWS_SECRET_ACCESS_KEY"
|
||||||
dockerConfigPath string = "/kaniko/.docker/config.json"
|
dockerConfigPath string = "/kaniko/.docker/config.json"
|
||||||
|
|
||||||
|
defaultDigestFile string = "/kaniko/digest-file"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -89,6 +92,31 @@ func main() {
|
|||||||
Usage: "ECR secret key",
|
Usage: "ECR secret key",
|
||||||
EnvVar: "PLUGIN_SECRET_KEY",
|
EnvVar: "PLUGIN_SECRET_KEY",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "snapshot-mode",
|
||||||
|
Usage: "Specify one of full, redo or time as snapshot mode",
|
||||||
|
EnvVar: "PLUGIN_SNAPSHOT_MODE",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "enable-cache",
|
||||||
|
Usage: "Set this flag to opt into caching with kaniko",
|
||||||
|
EnvVar: "PLUGIN_ENABLE_CACHE",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "cache-repo",
|
||||||
|
Usage: "Remote repository that will be used to store cached layers. Cache repo should be present in specified registry. enable-cache needs to be set to use this flag",
|
||||||
|
EnvVar: "PLUGIN_CACHE_REPO",
|
||||||
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "cache-ttl",
|
||||||
|
Usage: "Cache timeout in hours. Defaults to two weeks.",
|
||||||
|
EnvVar: "PLUGIN_CACHE_TTL",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "artifact-file",
|
||||||
|
Usage: "Artifact file location that will be generated by the plugin. This file will include information of docker images that are uploaded by the plugin.",
|
||||||
|
EnvVar: "PLUGIN_ARTIFACT_FILE",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
@@ -104,41 +132,50 @@ func run(c *cli.Context) error {
|
|||||||
|
|
||||||
plugin := kaniko.Plugin{
|
plugin := kaniko.Plugin{
|
||||||
Build: kaniko.Build{
|
Build: kaniko.Build{
|
||||||
Dockerfile: c.String("dockerfile"),
|
Dockerfile: c.String("dockerfile"),
|
||||||
Context: c.String("context"),
|
Context: c.String("context"),
|
||||||
Tags: c.StringSlice("tags"),
|
Tags: c.StringSlice("tags"),
|
||||||
Args: c.StringSlice("args"),
|
Args: c.StringSlice("args"),
|
||||||
Target: c.String("target"),
|
Target: c.String("target"),
|
||||||
Repo: c.String("repo"),
|
Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")),
|
||||||
Labels: c.StringSlice("custom-labels"),
|
Labels: c.StringSlice("custom-labels"),
|
||||||
|
SnapshotMode: c.String("snapshot-mode"),
|
||||||
|
EnableCache: c.Bool("enable-cache"),
|
||||||
|
CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")),
|
||||||
|
CacheTTL: c.Int("cache-ttl"),
|
||||||
|
DigestFile: defaultDigestFile,
|
||||||
|
},
|
||||||
|
Artifact: kaniko.Artifact{
|
||||||
|
Tags: c.StringSlice("tags"),
|
||||||
|
Repo: c.String("repo"),
|
||||||
|
Registry: c.String("registry"),
|
||||||
|
ArtifactFile: c.String("artifact-file"),
|
||||||
|
RegistryType: artifact.ECR,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return plugin.Exec()
|
return plugin.Exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupECRAuth(accessKey, secretKey, registry string) error {
|
func setupECRAuth(accessKey, secretKey, registry string) error {
|
||||||
if accessKey == "" {
|
|
||||||
return fmt.Errorf("Access key must be specified")
|
|
||||||
}
|
|
||||||
if secretKey == "" {
|
|
||||||
return fmt.Errorf("Secret key must be specified")
|
|
||||||
}
|
|
||||||
if registry == "" {
|
if registry == "" {
|
||||||
return fmt.Errorf("Registry must be specified")
|
return fmt.Errorf("registry must be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.Setenv(accessKeyEnv, accessKey)
|
// If IAM role is used, access key & secret key are not required
|
||||||
if err != nil {
|
if accessKey != "" && secretKey != "" {
|
||||||
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", accessKeyEnv))
|
err := os.Setenv(accessKeyEnv, accessKey)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", accessKeyEnv))
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Setenv(secretKeyEnv, secretKey)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", secretKeyEnv))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Setenv(secretKeyEnv, secretKey)
|
jsonBytes := []byte(fmt.Sprintf(`{"credStore": "ecr-login", "credHelpers": {"public.ecr.aws": "ecr-login", "%s": "ecr-login"}}`, registry))
|
||||||
if err != nil {
|
err := ioutil.WriteFile(dockerConfigPath, jsonBytes, 0644)
|
||||||
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", secretKeyEnv))
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonBytes := []byte(fmt.Sprintf(`{"credStore": "ecr-login", "credHelpers": {"%s": "ecr-login"}}`, registry))
|
|
||||||
err = ioutil.WriteFile(dockerConfigPath, jsonBytes, 0644)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to create docker config file")
|
return errors.Wrap(err, "failed to create docker config file")
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-8
@@ -11,12 +11,15 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
kaniko "github.com/drone/drone-kaniko"
|
kaniko "github.com/drone/drone-kaniko"
|
||||||
|
"github.com/drone/drone-kaniko/cmd/artifact"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// GCR JSON key file path
|
// GCR JSON key file path
|
||||||
gcrKeyPath string = "/kaniko/gcr.json"
|
gcrKeyPath string = "/kaniko/config.json"
|
||||||
gcrEnvVariable string = "GOOGLE_APPLICATION_CREDENTIALS"
|
gcrEnvVariable string = "GOOGLE_APPLICATION_CREDENTIALS"
|
||||||
|
|
||||||
|
defaultDigestFile string = "/kaniko/digest-file"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -85,6 +88,31 @@ func main() {
|
|||||||
Usage: "docker username",
|
Usage: "docker username",
|
||||||
EnvVar: "PLUGIN_JSON_KEY",
|
EnvVar: "PLUGIN_JSON_KEY",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "snapshot-mode",
|
||||||
|
Usage: "Specify one of full, redo or time as snapshot mode",
|
||||||
|
EnvVar: "PLUGIN_SNAPSHOT_MODE",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "enable-cache",
|
||||||
|
Usage: "Set this flag to opt into caching with kaniko",
|
||||||
|
EnvVar: "PLUGIN_ENABLE_CACHE",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "cache-repo",
|
||||||
|
Usage: "Remote repository that will be used to store cached layers. Cache repo should be present in specified registry. enable-cache needs to be set to use this flag",
|
||||||
|
EnvVar: "PLUGIN_CACHE_REPO",
|
||||||
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "cache-ttl",
|
||||||
|
Usage: "Cache timeout in hours. Defaults to two weeks.",
|
||||||
|
EnvVar: "PLUGIN_CACHE_TTL",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "artifact-file",
|
||||||
|
Usage: "Artifact file location that will be generated by the plugin. This file will include information of docker images that are uploaded by the plugin.",
|
||||||
|
EnvVar: "PLUGIN_ARTIFACT_FILE",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
@@ -104,13 +132,25 @@ func run(c *cli.Context) error {
|
|||||||
|
|
||||||
plugin := kaniko.Plugin{
|
plugin := kaniko.Plugin{
|
||||||
Build: kaniko.Build{
|
Build: kaniko.Build{
|
||||||
Dockerfile: c.String("dockerfile"),
|
Dockerfile: c.String("dockerfile"),
|
||||||
Context: c.String("context"),
|
Context: c.String("context"),
|
||||||
Tags: c.StringSlice("tags"),
|
Tags: c.StringSlice("tags"),
|
||||||
Args: c.StringSlice("args"),
|
Args: c.StringSlice("args"),
|
||||||
Target: c.String("target"),
|
Target: c.String("target"),
|
||||||
Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")),
|
Repo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("repo")),
|
||||||
Labels: c.StringSlice("custom-labels"),
|
Labels: c.StringSlice("custom-labels"),
|
||||||
|
SnapshotMode: c.String("snapshot-mode"),
|
||||||
|
EnableCache: c.Bool("enable-cache"),
|
||||||
|
CacheRepo: fmt.Sprintf("%s/%s", c.String("registry"), c.String("cache-repo")),
|
||||||
|
CacheTTL: c.Int("cache-ttl"),
|
||||||
|
DigestFile: defaultDigestFile,
|
||||||
|
},
|
||||||
|
Artifact: kaniko.Artifact{
|
||||||
|
Tags: c.StringSlice("tags"),
|
||||||
|
Repo: c.String("repo"),
|
||||||
|
Registry: c.String("registry"),
|
||||||
|
ArtifactFile: c.String("artifact-file"),
|
||||||
|
RegistryType: artifact.GCR,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return plugin.Exec()
|
return plugin.Exec()
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:amd64-v1.3.0
|
FROM gcr.io/kaniko-project/executor:v1.5.2
|
||||||
|
|
||||||
ENV HOME /root
|
|
||||||
ENV USER root
|
|
||||||
|
|
||||||
ADD release/linux/amd64/kaniko-docker /kaniko/
|
ADD release/linux/amd64/kaniko-docker /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-docker"]
|
ENTRYPOINT ["/kaniko/kaniko-docker"]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:arm64-v1.3.0
|
FROM gcr.io/kaniko-project/executor:arm64-v1.5.2
|
||||||
|
|
||||||
ENV HOME /root
|
ENV HOME /root
|
||||||
ENV USER root
|
ENV USER root
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:amd64-v1.3.0
|
FROM gcr.io/kaniko-project/executor:v1.5.2
|
||||||
|
|
||||||
ENV HOME /root
|
|
||||||
ENV USER root
|
|
||||||
|
|
||||||
ADD release/linux/amd64/kaniko-ecr /kaniko/
|
ADD release/linux/amd64/kaniko-ecr /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-ecr"]
|
ENTRYPOINT ["/kaniko/kaniko-ecr"]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:arm64-v1.3.0
|
FROM gcr.io/kaniko-project/executor:arm64-v1.5.2
|
||||||
|
|
||||||
ENV HOME /root
|
ENV HOME /root
|
||||||
ENV USER root
|
ENV USER root
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:amd64-v1.3.0
|
FROM gcr.io/kaniko-project/executor:v1.5.2
|
||||||
|
|
||||||
ENV HOME /root
|
|
||||||
ENV USER root
|
|
||||||
|
|
||||||
ADD release/linux/amd64/kaniko-gcr /kaniko/
|
ADD release/linux/amd64/kaniko-gcr /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-gcr"]
|
ENTRYPOINT ["/kaniko/kaniko-gcr"]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:arm64-v1.3.0
|
FROM gcr.io/kaniko-project/executor:arm64-v1.5.2
|
||||||
|
|
||||||
ENV HOME /root
|
ENV HOME /root
|
||||||
ENV USER root
|
ENV USER root
|
||||||
|
|||||||
@@ -2,26 +2,45 @@ package kaniko
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/drone/drone-kaniko/cmd/artifact"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Build defines Docker build parameters.
|
// Build defines Docker build parameters.
|
||||||
Build struct {
|
Build struct {
|
||||||
Dockerfile string // Docker build Dockerfile
|
Dockerfile string // Docker build Dockerfile
|
||||||
Context string // Docker build context
|
Context string // Docker build context
|
||||||
Tags []string // Docker build tags
|
Tags []string // Docker build tags
|
||||||
Args []string // Docker build args
|
Args []string // Docker build args
|
||||||
Target string // Docker build target
|
Target string // Docker build target
|
||||||
Repo string // Docker build repository
|
Repo string // Docker build repository
|
||||||
Labels []string // Label map
|
Labels []string // Label map
|
||||||
|
SkipTlsVerify bool // Docker skip tls certificate verify for registry
|
||||||
|
SnapshotMode string // Kaniko snapshot mode
|
||||||
|
EnableCache bool // Whether to enable kaniko cache
|
||||||
|
CacheRepo string // Remote repository that will be used to store cached layers
|
||||||
|
CacheTTL int // Cache timeout in hours
|
||||||
|
DigestFile string // Digest file location
|
||||||
|
}
|
||||||
|
// Artifact defines content of artifact file
|
||||||
|
Artifact struct {
|
||||||
|
Tags []string // Docker artifact tags
|
||||||
|
Repo string // Docker artifact repository
|
||||||
|
Registry string // Docker artifact registry
|
||||||
|
RegistryType artifact.RegistryTypeEnum // Rocker artifact registry type
|
||||||
|
ArtifactFile string // Artifact file location
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Plugin defines the Docker plugin parameters.
|
// Plugin defines the Docker plugin parameters.
|
||||||
Plugin struct {
|
Plugin struct {
|
||||||
Build Build // Docker build configuration
|
Build Build // Docker build configuration
|
||||||
|
Artifact Artifact // Artifact file content
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,6 +50,10 @@ func (p Plugin) Exec() error {
|
|||||||
return fmt.Errorf("repository name to publish image must be specified")
|
return fmt.Errorf("repository name to publish image must be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(p.Build.Dockerfile); os.IsNotExist(err) {
|
||||||
|
return fmt.Errorf("dockerfile does not exist at path: %s", p.Build.Dockerfile)
|
||||||
|
}
|
||||||
|
|
||||||
cmdArgs := []string{
|
cmdArgs := []string{
|
||||||
fmt.Sprintf("--dockerfile=%s", p.Build.Dockerfile),
|
fmt.Sprintf("--dockerfile=%s", p.Build.Dockerfile),
|
||||||
fmt.Sprintf("--context=dir://%s", p.Build.Context),
|
fmt.Sprintf("--context=dir://%s", p.Build.Context),
|
||||||
@@ -46,20 +69,59 @@ func (p Plugin) Exec() error {
|
|||||||
}
|
}
|
||||||
// Set the labels
|
// Set the labels
|
||||||
for _, label := range p.Build.Labels {
|
for _, label := range p.Build.Labels {
|
||||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--label %s", label))
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--label=%s", label))
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Build.Target != "" {
|
if p.Build.Target != "" {
|
||||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--target=%s", p.Build.Target))
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--target=%s", p.Build.Target))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.Build.SkipTlsVerify {
|
||||||
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--skip-tls-verify=true"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Build.SnapshotMode != "" {
|
||||||
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--snapshotMode=%s", p.Build.SnapshotMode))
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Build.EnableCache == true {
|
||||||
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--cache=true"))
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Build.CacheRepo != "" {
|
||||||
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--cache-repo=%s", p.Build.CacheRepo))
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Build.CacheTTL != 0 {
|
||||||
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--cache-ttl=%d", p.Build.CacheTTL))
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Build.DigestFile != "" {
|
||||||
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--digest-file=%s", p.Build.DigestFile))
|
||||||
|
}
|
||||||
|
|
||||||
cmd := exec.Command("/kaniko/executor", cmdArgs...)
|
cmd := exec.Command("/kaniko/executor", cmdArgs...)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
trace(cmd)
|
trace(cmd)
|
||||||
|
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Build.DigestFile != "" && p.Artifact.ArtifactFile != "" {
|
||||||
|
content, err := ioutil.ReadFile(p.Build.DigestFile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to read digest file contents at path: %s with error: %s\n", p.Build.DigestFile, err)
|
||||||
|
}
|
||||||
|
err = artifact.WritePluginArtifactFile(p.Artifact.RegistryType, p.Artifact.ArtifactFile, p.Artifact.Registry, p.Artifact.Repo, string(content), p.Artifact.Tags)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "failed to write plugin artifact file at path: %s with error: %s\n", p.Artifact.ArtifactFile, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// trace writes each command to stdout with the command wrapped in an xml
|
// trace writes each command to stdout with the command wrapped in an xml
|
||||||
|
|||||||
+9
-9
@@ -10,14 +10,14 @@ set -e
|
|||||||
set -x
|
set -x
|
||||||
|
|
||||||
# linux
|
# linux
|
||||||
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/kaniko-gcr
|
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/kaniko-gcr ./cmd/kaniko-gcr
|
||||||
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/kaniko-ecr
|
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/kaniko-ecr ./cmd/kaniko-ecr
|
||||||
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/kaniko-docker
|
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/kaniko-docker ./cmd/kaniko-docker
|
||||||
|
|
||||||
GOOS=linux GOARCH=arm64 go build -o release/linux/arm64/kaniko-gcr
|
GOOS=linux GOARCH=arm64 go build -o release/linux/arm64/kaniko-gcr ./cmd/kaniko-gcr
|
||||||
GOOS=linux GOARCH=arm64 go build -o release/linux/arm64/kaniko-ecr
|
GOOS=linux GOARCH=arm64 go build -o release/linux/arm64/kaniko-ecr ./cmd/kaniko-ecr
|
||||||
GOOS=linux GOARCH=arm64 go build -o release/linux/arm64/kaniko-docker
|
GOOS=linux GOARCH=arm64 go build -o release/linux/arm64/kaniko-docker ./cmd/kaniko-docker
|
||||||
|
|
||||||
GOOS=linux GOARCH=arm go build -o release/linux/arm/kaniko-gcr
|
GOOS=linux GOARCH=arm go build -o release/linux/arm/kaniko-gcr ./cmd/kaniko-gcr
|
||||||
GOOS=linux GOARCH=arm go build -o release/linux/arm/kaniko-ecr
|
GOOS=linux GOARCH=arm go build -o release/linux/arm/kaniko-ecr ./cmd/kaniko-ecr
|
||||||
GOOS=linux GOARCH=arm go build -o release/linux/arm/kaniko-docker
|
GOOS=linux GOARCH=arm go build -o release/linux/arm/kaniko-docker ./cmd/kaniko-docker
|
||||||
|
|||||||
Regular → Executable
+3
-3
@@ -14,9 +14,9 @@ set -e
|
|||||||
set -x
|
set -x
|
||||||
|
|
||||||
# build the binary
|
# build the binary
|
||||||
go build -o release/linux/amd64/kaniko-gcr
|
go build -o release/linux/amd64/kaniko-gcr ./cmd/kaniko-gcr
|
||||||
go build -o release/linux/amd64/kaniko-ecr
|
go build -o release/linux/amd64/kaniko-ecr ./cmd/kaniko-ecr
|
||||||
go build -o release/linux/amd64/kaniko-docker
|
go build -o release/linux/amd64/kaniko-docker ./cmd/kaniko-docker
|
||||||
|
|
||||||
# build the docker image
|
# build the docker image
|
||||||
docker build -f docker/gcr/Dockerfile.linux.amd64 -t plugins/kaniko-gcr .
|
docker build -f docker/gcr/Dockerfile.linux.amd64 -t plugins/kaniko-gcr .
|
||||||
|
|||||||
Reference in New Issue
Block a user