Compare commits

...

30 Commits

Author SHA1 Message Date
Karl Trygve Kalleberg 0dee97e338 Expose tar_path command line option from Kaniko (#78) 2023-04-03 09:47:53 +01:00
Raghav ed6f3c5bf4 Add output variable support (#77)
* add digest as output variable for kaniko plugin
2023-03-16 10:03:59 +00:00
Raghav 4893b5b945 add support for docker complaint registries for base image (#74) 2023-02-23 11:38:53 +05:30
Soumyajit Das 447ee28867 fix: [CI-6505]: Upgrade kanoko version for all (#71) 2023-01-17 13:00:11 +05:30
Soumyajit Das 9c90e58a2d fix: [CI-6412]: Error message Refinement (#70) 2023-01-04 11:13:01 +05:30
Shubham Agrawal d998c00a4b Add v1.9.1 kaniko image support (#69) 2022-12-02 15:43:35 +05:30
Aman Singh 2f55e25020 Merge pull request #68 from drone/aman/rename-config
fixed config-name for PLUGIN_CONFIG
2022-11-10 12:28:26 +05:30
Aman Singh f3544ce6ee renamed docker config 2022-11-09 18:02:22 +05:30
Aman Singh e4cd992d8d renamed docker config 2022-11-08 16:21:45 +05:30
Aman Singh d457df687d renamed docker config 2022-11-08 15:05:26 +05:30
Aman Singh 4820b6af00 renamed docker config 2022-11-08 15:01:52 +05:30
Aman Singh 3717723366 fixed config-name for PLUGIN_CONFIG 2022-11-08 12:32:12 +05:30
Aman Singh be3bf8ad1e Merge pull request #67 from drone/aman/fix-config
added config for providing docker config
2022-11-07 17:12:56 +05:30
Aman Singh 15255d3520 added comments 2022-11-07 17:07:26 +05:30
Aman Singh 6ba0eb58c3 added config for providing docker config 2022-11-07 14:21:40 +05:30
Aman Singh 17e907c7cf Merge pull request #66 from drone/aman/fix-docker-plugin
Added option to use overriden docker config
2022-11-04 19:57:58 +05:30
Aman Singh 190fbefe91 config override 2022-11-04 19:50:04 +05:30
Aman Singh 48f6e72954 config override 2022-11-04 19:49:25 +05:30
Aman Singh 1bee1629c2 added option to use overriden docker config 2022-11-04 19:48:03 +05:30
Kyle Lemons 2d0315e6bb Add beta testcase for clarity, coverage, and regression prevention (#64) 2022-11-03 19:05:06 +05:30
Aman Singh 34cfbdfbd5 Merge pull request #65 from aman-harness/aman/acr-artifact
fixed public url in code for acr
2022-11-03 16:53:33 +05:30
Aman Singh d11c254840 fixed test 2022-11-02 17:12:34 +05:30
Aman Singh 7d751135b1 fixed url 2022-11-02 16:20:54 +05:30
Aman Singh 54f2fe097a fixed url 2022-11-02 16:17:23 +05:30
Aman Singh 9c899979ff fixed url 2022-11-02 16:09:57 +05:30
Aman Singh 6ac1efad25 fixed url 2022-11-02 15:58:40 +05:30
Aman Singh 128a2d77c0 fixed minor changes 2022-11-02 12:36:19 +05:30
Aman Singh 69e789b294 removed prints statements 2022-11-02 12:23:26 +05:30
Aman Singh 000711c7f1 fixed public url in code for acr 2022-11-02 11:50:39 +05:30
Jamie Li 864a7e5319 Fix manifest of ACR (#62) 2022-08-18 11:52:19 +05:30
27 changed files with 280 additions and 107 deletions
+24 -25
View File
@@ -77,14 +77,14 @@ steps:
exclude:
- pull_request
- name: docker-kaniko-v1-8
- name: docker-kaniko-v1-9
image: plugins/docker
settings:
repo: plugins/kaniko
auto_tag: true
auto_tag_suffix: linux-amd64-kaniko1.8.1
auto_tag_suffix: linux-amd64-kaniko1.9.1
daemon_off: false
dockerfile: docker/docker/Dockerfile.linux.amd64.kaniko1.8.1
dockerfile: docker/docker/Dockerfile.linux.amd64.kaniko1.9.1
username:
from_secret: docker_username
password:
@@ -94,14 +94,14 @@ steps:
exclude:
- pull_request
- name: gcr-kaniko-v1-8
- name: gcr-kaniko-v1-9
image: plugins/docker
settings:
repo: plugins/kaniko-gcr
auto_tag: true
auto_tag_suffix: linux-amd64-kaniko1.8.1
auto_tag_suffix: linux-amd64-kaniko1.9.1
daemon_off: false
dockerfile: docker/gcr/Dockerfile.linux.amd64.kaniko1.8.1
dockerfile: docker/gcr/Dockerfile.linux.amd64.kaniko1.9.1
username:
from_secret: docker_username
password:
@@ -112,14 +112,14 @@ steps:
- pull_request
- name: ecr-kaniko-v1-8
- name: ecr-kaniko-v1-9
image: plugins/docker
settings:
repo: plugins/kaniko-ecr
auto_tag: true
auto_tag_suffix: linux-amd64-kaniko1.8.1
auto_tag_suffix: linux-amd64-kaniko1.9.1
daemon_off: false
dockerfile: docker/ecr/Dockerfile.linux.amd64.kaniko1.8.1
dockerfile: docker/ecr/Dockerfile.linux.amd64.kaniko1.9.1
username:
from_secret: docker_username
password:
@@ -130,12 +130,11 @@ steps:
- pull_request
---
kind: pipeline
type: docker
type: vm
name: arm
platform:
os: linux
arch: arm64
pool:
use: ubuntu_arm64
steps:
- name: build
@@ -212,14 +211,14 @@ steps:
exclude:
- pull_request
- name: docker-kaniko-v1-8
- name: docker-kaniko-v1-9
image: plugins/docker
settings:
repo: plugins/kaniko
auto_tag: true
auto_tag_suffix: linux-arm64-kaniko1.8.1
auto_tag_suffix: linux-arm64-kaniko1.9.1
daemon_off: false
dockerfile: docker/docker/Dockerfile.linux.arm64.kaniko1.8.1
dockerfile: docker/docker/Dockerfile.linux.arm64.kaniko1.9.1
username:
from_secret: docker_username
password:
@@ -229,14 +228,14 @@ steps:
exclude:
- pull_request
- name: gcr-kaniko-v1-8
- name: gcr-kaniko-v1-9
image: plugins/docker
settings:
repo: plugins/kaniko-gcr
auto_tag: true
auto_tag_suffix: linux-arm64-kaniko1.8.1
auto_tag_suffix: linux-arm64-kaniko1.9.1
daemon_off: false
dockerfile: docker/gcr/Dockerfile.linux.arm64.kaniko1.8.1
dockerfile: docker/gcr/Dockerfile.linux.arm64.kaniko1.9.1
username:
from_secret: docker_username
password:
@@ -247,14 +246,14 @@ steps:
- pull_request
- name: ecr-kaniko-v1-8
- name: ecr-kaniko-v1-9
image: plugins/docker
settings:
repo: plugins/kaniko-ecr
auto_tag: true
auto_tag_suffix: linux-arm64-kaniko1.8.1
auto_tag_suffix: linux-arm64-kaniko1.9.1
daemon_off: false
dockerfile: docker/ecr/Dockerfile.linux.arm64.kaniko1.8.1
dockerfile: docker/ecr/Dockerfile.linux.arm64.kaniko1.9.1
username:
from_secret: docker_username
password:
@@ -348,7 +347,7 @@ steps:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/docker/manifest-kaniko1.8.1.tmpl
spec: docker/docker/manifest-kaniko1.9.1.tmpl
username:
from_secret: docker_username
@@ -360,7 +359,7 @@ steps:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/gcr/manifest-kaniko1.8.1.tmpl
spec: docker/gcr/manifest-kaniko1.9.1.tmpl
username:
from_secret: docker_username
@@ -372,7 +371,7 @@ steps:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/ecr/manifest-kaniko1.8.1.tmpl
spec: docker/ecr/manifest-kaniko1.9.1.tmpl
username:
from_secret: docker_username
+1 -1
View File
@@ -2,7 +2,7 @@
Drone kaniko plugin uses [kaniko](https://github.com/GoogleContainerTools/kaniko) to build and publish Docker images to a container registry.
Plugin images are published with 1.6.0 as well as 1.8.1 kaniko version from 1.5.1 release tag. `plugins/kaniko:<release-tag>` uses 1.6.0 version while `plugins/kaniko:<release-tag>-kaniko1.8.1` uses 1.8.1 version. Similar convention is used for plugins/kaniko-ecr & plugins/kaniko-gcr images as well.
Plugin images are published with 1.6.0 as well as 1.9.1 kaniko version from 1.5.1 release tag. `plugins/kaniko:<release-tag>` uses 1.6.0 version while `plugins/kaniko:<release-tag>-kaniko1.9.1` uses 1.9.1 version. Similar convention is used for plugins/kaniko-ecr & plugins/kaniko-gcr images as well.
## Build
+83 -24
View File
@@ -9,6 +9,7 @@ import (
"net/http"
"net/url"
"os"
"strings"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
@@ -29,6 +30,7 @@ const (
certPathEnv string = "AZURE_CLIENT_CERTIFICATE_PATH"
dockerConfigPath string = "/kaniko/.docker"
defaultDigestFile string = "/kaniko/digest-file"
finalUrl string = "https://portal.azure.com/#view/Microsoft_Azure_ContainerRegistries/TagMetadataBlade/registryId/"
)
var (
@@ -139,6 +141,11 @@ func main() {
Usage: "Azure Tenant Id",
EnvVar: "TENANT_ID",
},
cli.StringFlag{
Name: "subscription-id",
Usage: "Azure Subscription Id",
EnvVar: "SUBSCRIPTION_ID",
},
cli.StringFlag{
Name: "client-id",
Usage: "Azure Client Id",
@@ -210,11 +217,12 @@ func run(c *cli.Context) error {
registry := c.String("registry")
noPush := c.Bool("no-push")
err := createDockerConfig(
publicUrl, err := setupAuth(
c.String("tenant-id"),
c.String("client-id"),
c.String("client-cert"),
c.String("client-secret"),
c.String("subscription-id"),
registry,
noPush,
)
@@ -250,7 +258,7 @@ func run(c *cli.Context) error {
Artifact: kaniko.Artifact{
Tags: c.StringSlice("tags"),
Repo: c.String("repo"),
Registry: c.String("registry"),
Registry: publicUrl, // this is public url on which the artifact can be seen
ArtifactFile: c.String("artifact-file"),
RegistryType: artifact.Docker,
},
@@ -258,46 +266,45 @@ func run(c *cli.Context) error {
return plugin.Exec()
}
func createDockerConfig(tenantId, clientId, cert,
clientSecret, registry string, noPush bool) error {
func setupAuth(tenantId, clientId, cert,
clientSecret, subscriptionId, registry string, noPush bool) (string, error) {
if registry == "" {
return fmt.Errorf("registry must be specified")
return "", fmt.Errorf("registry must be specified")
}
if noPush {
return nil
return "", nil
}
// case of client secret or cert based auth
if clientId != "" {
// only setup auth when pushing or credentials are defined
token, err := getACRToken(tenantId, clientId, clientSecret, cert, registry)
token, publicUrl, err := getACRToken(subscriptionId, tenantId, clientId, clientSecret, cert, registry)
if err != nil {
return errors.Wrap(err, "failed to fetch ACR Token")
return "", errors.Wrap(err, "failed to fetch ACR Token")
}
err = docker.CreateDockerCfgFile(username, token, registry, dockerConfigPath)
if err != nil {
return errors.Wrap(err, "failed to create docker config")
return "", errors.Wrap(err, "failed to create docker config")
}
return publicUrl, nil
} else {
return fmt.Errorf("managed authentication is not supported")
return "", fmt.Errorf("managed authentication is not supported")
}
return nil
}
func getACRToken(tenantId, clientId, clientSecret, cert, registry string) (string, error) {
func getACRToken(subscriptionId, tenantId, clientId, clientSecret, cert, registry string) (string, string, error) {
if tenantId == "" {
return "", fmt.Errorf("tenantId can't be empty for AAD authentication")
return "", "", fmt.Errorf("tenantId can't be empty for AAD authentication")
}
if clientId == "" {
return "", fmt.Errorf("clientId can't be empty for AAD authentication")
return "", "", fmt.Errorf("clientId can't be empty for AAD authentication")
}
if clientSecret == "" && cert == "" {
return "", fmt.Errorf("one of client secret or cert should be defined")
return "", "", fmt.Errorf("one of client secret or cert should be defined")
}
// in case of authentication via cert
@@ -309,21 +316,22 @@ func getACRToken(tenantId, clientId, clientSecret, cert, registry string) (strin
}
if err := os.Setenv(clientIdEnv, clientId); err != nil {
return "", errors.Wrap(err, "failed to set env variable client Id")
return "", "", errors.Wrap(err, "failed to set env variable client Id")
}
if err := os.Setenv(clientSecretKeyEnv, clientSecret); err != nil {
return "", errors.Wrap(err, "failed to set env variable client secret")
return "", "", errors.Wrap(err, "failed to set env variable client secret")
}
if err := os.Setenv(tenantKeyEnv, tenantId); err != nil {
return "", errors.Wrap(err, "failed to set env variable tenant Id")
return "", "", errors.Wrap(err, "failed to set env variable tenant Id")
}
if err := os.Setenv(certPathEnv, ACRCertPath); err != nil {
return "", errors.Wrap(err, "failed to set env variable cert path")
return "", "", errors.Wrap(err, "failed to set env variable cert path")
}
env, err := azidentity.NewEnvironmentCredential(nil)
if err != nil {
return "", errors.Wrap(err, "failed to get env credentials from azure")
return "", "", errors.Wrap(err, "failed to get env credentials from azure")
}
policy := policy.TokenRequestOptions{
Scopes: []string{"https://management.azure.com/.default"},
}
@@ -334,14 +342,20 @@ func getACRToken(tenantId, clientId, clientSecret, cert, registry string) (strin
azToken, err := env.GetToken(context.Background(), policy)
if err != nil {
return "", errors.Wrap(err, "failed to fetch access token")
return "", "", errors.Wrap(err, "failed to fetch access token")
}
publicUrl, err := getPublicUrl(azToken.Token, registry, subscriptionId)
if err != nil {
// execution should not fail because of this error.
fmt.Fprintf(os.Stderr, "failed to get public url with error: %s\n", err)
}
ACRToken, err := fetchACRToken(tenantId, azToken.Token, registry)
if err != nil {
return "", errors.Wrap(err, "failed to fetch ACR token")
return "", "", errors.Wrap(err, "failed to fetch ACR token")
}
return ACRToken, nil
return ACRToken, publicUrl, nil
}
func fetchACRToken(tenantId, token, registry string) (string, error) {
@@ -385,3 +399,48 @@ func setupACRCert(cert string) error {
}
return nil
}
func getPublicUrl(token, registryUrl, subscriptionId string) (string, error) {
// for backward compatibilty, if the subscription id is not defined, do not fail step.
if len(subscriptionId) == 0 {
return "", nil
}
registry := strings.Split(registryUrl, ".")[0]
burl := "https://management.azure.com/subscriptions/" +
subscriptionId + "/resources?$filter=resourceType%20eq%20'Microsoft.ContainerRegistry/registries'%20and%20name%20eq%20'" +
registry + "'&api-version=2021-04-01&$select=id"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, burl, nil)
if err != nil {
fmt.Println(err)
return "", errors.Wrap(err, "failed to create request for getting container registry setting")
}
req.Header.Add("Authorization", "Bearer "+token)
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return "", errors.Wrap(err, "failed to send request for getting container registry setting")
}
defer res.Body.Close()
var response strct
err = json.NewDecoder(res.Body).Decode(&response)
if err != nil {
return "", errors.Wrap(err, "failed to send request for getting container registry setting")
}
return finalUrl + encodeParam(response.Value[0].ID), nil
}
func encodeParam(s string) string {
return url.QueryEscape(s)
}
type strct struct {
Value []struct {
ID string `json:"id"`
} `json:"value"`
}
+39 -6
View File
@@ -90,6 +90,11 @@ func main() {
Usage: "enable auto generation of build tags",
EnvVar: "PLUGIN_AUTO_TAG",
},
cli.StringFlag{
Name: "dockerconfig",
Usage: "docker json dockerconfig",
EnvVar: "PLUGIN_CONFIG",
},
cli.StringFlag{
Name: "auto-tag-suffix",
Usage: "the suffix of auto build tags",
@@ -171,6 +176,11 @@ func main() {
Usage: "Set this flag if you only want to build the image, without pushing to a registry",
EnvVar: "PLUGIN_NO_PUSH",
},
cli.StringFlag{
Name: "tar-path",
Usage: "Set this flag to save the image as a tarball at path",
EnvVar: "PLUGIN_TAR_PATH",
},
cli.StringFlag{
Name: "verbosity",
Usage: "Set this flag with value as oneof <panic|fatal|error|warn|info|debug|trace> to set the logging level for kaniko. Defaults to info.",
@@ -186,6 +196,11 @@ func main() {
Usage: "build only used stages",
EnvVar: "PLUGIN_SKIP_UNUSED_STAGES",
},
cli.StringFlag{
Name: "output-file",
Usage: "Output file location that will be generated by the plugin. This file will include information of the output that are exported by the plugin.",
EnvVar: "DRONE_OUTPUT",
},
}
if err := app.Run(os.Args); err != nil {
@@ -196,9 +211,15 @@ func main() {
func run(c *cli.Context) error {
username := c.String("username")
noPush := c.Bool("no-push")
configOverride := c.String("dockerconfig")
// only setup auth when pushing or credentials are defined
if !noPush || username != "" {
// if configOverride is provided, use this for docker auth
if len(configOverride) > 0 {
if err := writeDockerCfgFile([]byte(configOverride)); err != nil {
return err
}
} else if !noPush || username != "" {
// setup auth when pushing or credentials are defined and docker config override is false
if err := createDockerCfgFile(username, c.String("password"), c.String("registry")); err != nil {
return err
}
@@ -226,6 +247,7 @@ func run(c *cli.Context) error {
CacheTTL: c.Int("cache-ttl"),
DigestFile: defaultDigestFile,
NoPush: noPush,
TarPath: c.String("tar-path"),
Verbosity: c.String("verbosity"),
Platform: c.String("platform"),
SkipUnusedStages: c.Bool("skip-unused-stages"),
@@ -237,6 +259,9 @@ func run(c *cli.Context) error {
ArtifactFile: c.String("artifact-file"),
RegistryType: artifact.Docker,
},
Output: kaniko.Output{
OutputFile: c.String("output-file"),
},
}
return plugin.Exec()
}
@@ -259,14 +284,22 @@ func createDockerCfgFile(username, password, registry string) error {
registry = v1RegistryURL
}
authBytes := []byte(fmt.Sprintf("%s:%s", username, password))
encodedString := base64.StdEncoding.EncodeToString(authBytes)
jsonBytes := []byte(fmt.Sprintf(`{"auths": {"%s": {"auth": "%s"}}}`, registry, encodedString))
if err := writeDockerCfgFile(jsonBytes); err != nil {
return errors.Wrap(err, "failed to write docker config file")
}
return nil
}
// Write json bytes in the docker config file
func writeDockerCfgFile(jsonBytes []byte) error {
err := os.MkdirAll(dockerPath, 0600)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to create %s directory", dockerPath))
}
authBytes := []byte(fmt.Sprintf("%s:%s", username, password))
encodedString := base64.StdEncoding.EncodeToString(authBytes)
jsonBytes := []byte(fmt.Sprintf(`{"auths": {"%s": {"auth": "%s"}}}`, registry, encodedString))
err = ioutil.WriteFile(dockerConfigPath, jsonBytes, 0644)
if err != nil {
return errors.Wrap(err, "failed to create docker config file")
+13 -3
View File
@@ -64,6 +64,11 @@ func main() {
Value: "Dockerfile",
EnvVar: "PLUGIN_DOCKERFILE",
},
cli.StringFlag{
Name: "docker-registry",
Usage: "docker registry",
EnvVar: "PLUGIN_DOCKER_REGISTRY,DOCKER_REGISTRY",
},
cli.StringFlag{
Name: "docker-username",
Usage: "docker username",
@@ -242,6 +247,7 @@ func run(c *cli.Context) error {
noPush := c.Bool("no-push")
dockerConfig, err := createDockerConfig(
c.String("docker-registry"),
c.String("docker-username"),
c.String("docker-password"),
c.String("access-key"),
@@ -328,12 +334,16 @@ func run(c *cli.Context) error {
return plugin.Exec()
}
func createDockerConfig(dockerUsername, dockerPassword, accessKey, secretKey,
func createDockerConfig(dockerRegistry, dockerUsername, dockerPassword, accessKey, secretKey,
registry, assumeRole, externalId, region string, noPush bool) (*docker.Config, error) {
dockerConfig := docker.NewConfig()
if dockerUsername != "" {
dockerConfig.SetAuth(docker.RegistryV1, dockerUsername, dockerPassword)
// if no docker registry provided, use dockerhub by default
if len(dockerRegistry) == 0 {
dockerRegistry = docker.RegistryV1
}
dockerConfig.SetAuth(dockerRegistry, dockerUsername, dockerPassword)
}
if assumeRole != "" {
@@ -469,7 +479,7 @@ func getAssumeRoleCreds(region, roleArn, externalId, roleSessionName string) (st
username, password, registry, err := getAuthInfo(svc)
if err != nil {
return "", "", "", errors.Wrap(err, "failed to get ECR auth")
return "", "", "", errors.Wrap(err, "failed to get ECR auth: no basic auth credentials")
}
return username, password, registry, nil
}
+28
View File
@@ -10,6 +10,7 @@ import (
func TestCreateDockerConfig(t *testing.T) {
got, err := createDockerConfig(
"",
"docker-username",
"docker-password",
"access-key",
@@ -34,10 +35,37 @@ func TestCreateDockerConfig(t *testing.T) {
}
}
func TestCreateDockerConfigFromGivenRegistry(t *testing.T) {
got, err := createDockerConfig(
"docker-registry",
"docker-username",
"docker-password",
"access-key",
"secret-key",
"ecr-registry",
"",
"",
"",
false,
)
if err != nil {
t.Error("failed to create docker config")
}
want := docker.NewConfig()
want.SetAuth("docker-registry", "docker-username", "docker-password")
want.SetCredHelper(docker.RegistryECRPublic, "ecr-login")
want.SetCredHelper("ecr-registry", "ecr-login")
if !reflect.DeepEqual(want, got) {
t.Errorf("not equal:\n want: %#v\n got: %#v", want, got)
}
}
func TestCreateDockerConfigKanikoOneDotEight(t *testing.T) {
os.Setenv(kanikoVersionEnv, "1.8.1")
defer os.Setenv(kanikoVersionEnv, "")
got, err := createDockerConfig(
"",
"docker-username",
"docker-password",
"access-key",
+2 -2
View File
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.8.1
ENV KANIKO_VERSION=1.9.1
ADD release/linux/amd64/kaniko-acr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-acr"]
+2 -2
View File
@@ -1,8 +1,8 @@
FROM gcr.io/kaniko-project/executor:v1.8.1
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV HOME /root
ENV USER root
ENV KANIKO_VERSION=1.8.1
ENV KANIKO_VERSION=1.9.1
ADD release/linux/arm64/kaniko-acr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-acr"]
+3 -3
View File
@@ -1,4 +1,4 @@
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
image: plugins/kaniko-acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
@@ -7,12 +7,12 @@ tags:
{{/if}}
manifests:
-
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
image: plugins/kaniko-acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
image: plugins/kaniko-acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
+2 -2
View File
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.6.0
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.6.0
ENV KANIKO_VERSION=1.9.1
ADD release/linux/amd64/kaniko-docker /kaniko/
ENTRYPOINT ["/kaniko/kaniko-docker"]
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.8.1
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.8.1
ENV KANIKO_VERSION=1.9.1
ADD release/linux/amd64/kaniko-docker /kaniko/
ENTRYPOINT ["/kaniko/kaniko-docker"]
+2 -2
View File
@@ -1,8 +1,8 @@
FROM gcr.io/kaniko-project/executor:v1.6.0
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV HOME /root
ENV USER root
ENV KANIKO_VERSION=1.6.0
ENV KANIKO_VERSION=1.9.1
ADD release/linux/arm64/kaniko-docker /kaniko/
ENTRYPOINT ["/kaniko/kaniko-docker"]
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.8.1
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.8.1
ENV KANIKO_VERSION=1.9.1
ADD release/linux/arm64/kaniko-docker /kaniko/
ENTRYPOINT ["/kaniko/kaniko-docker"]
@@ -1,4 +1,4 @@
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-kaniko1.8.1{{else}}latest-kaniko1.8.1{{/if}}
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-kaniko1.9.1{{else}}latest-kaniko1.9.1{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
@@ -7,12 +7,12 @@ tags:
{{/if}}
manifests:
-
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.8.1
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.9.1
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-kaniko1.8.1
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-kaniko1.9.1
platform:
architecture: arm64
os: linux
+2 -2
View File
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.6.0
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.6.0
ENV KANIKO_VERSION=1.9.1
ADD release/linux/amd64/kaniko-ecr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-ecr"]
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.8.1
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.8.1
ENV KANIKO_VERSION=1.9.1
ADD release/linux/amd64/kaniko-ecr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-ecr"]
+2 -2
View File
@@ -1,8 +1,8 @@
FROM gcr.io/kaniko-project/executor:v1.6.0
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV HOME /root
ENV USER root
ENV KANIKO_VERSION=1.6.0
ENV KANIKO_VERSION=1.9.1
ADD release/linux/arm64/kaniko-ecr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-ecr"]
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.8.1
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.8.1
ENV KANIKO_VERSION=1.9.1
ADD release/linux/arm64/kaniko-ecr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-ecr"]
@@ -1,4 +1,4 @@
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-kaniko1.8.1{{else}}latest-kaniko1.8.1{{/if}}
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-kaniko1.9.1{{else}}latest-kaniko1.9.1{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
@@ -7,12 +7,12 @@ tags:
{{/if}}
manifests:
-
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.8.1
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.9.1
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-kaniko1.8.1
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-kaniko1.9.1
platform:
architecture: arm64
os: linux
+2 -2
View File
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.6.0
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.6.0
ENV KANIKO_VERSION=1.9.1
ADD release/linux/amd64/kaniko-gcr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-gcr"]
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.8.1
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.8.1
ENV KANIKO_VERSION=1.9.1
ADD release/linux/amd64/kaniko-gcr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-gcr"]
+2 -2
View File
@@ -1,8 +1,8 @@
FROM gcr.io/kaniko-project/executor:v1.6.0
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV HOME /root
ENV USER root
ENV KANIKO_VERSION=1.6.0
ENV KANIKO_VERSION=1.9.1
ADD release/linux/arm64/kaniko-gcr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-gcr"]
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.8.1
FROM gcr.io/kaniko-project/executor:v1.9.1
ENV KANIKO_VERSION=1.8.1
ENV KANIKO_VERSION=1.9.1
ADD release/linux/arm64/kaniko-gcr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-gcr"]
@@ -1,4 +1,4 @@
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-kaniko1.8.1{{else}}latest-kaniko1.8.1{{/if}}
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-kaniko1.9.1{{else}}latest-kaniko1.9.1{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
@@ -7,12 +7,12 @@ tags:
{{/if}}
manifests:
-
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.8.1
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.9.1
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-kaniko1.8.1
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-kaniko1.9.1
platform:
architecture: arm64
os: linux
+30 -7
View File
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/drone/drone-kaniko/pkg/artifact"
"github.com/drone/drone-kaniko/pkg/output"
"github.com/drone/drone-kaniko/pkg/tagger"
"golang.org/x/mod/semver"
)
@@ -38,6 +39,7 @@ type (
Verbosity string // Log level
Platform string // Allows to build with another default platform than the host, similarly to docker build --platform
SkipUnusedStages bool // Build only used stages
TarPath string // Set this flag to save the image as a tarball at path
}
// Artifact defines content of artifact file
@@ -49,10 +51,16 @@ type (
ArtifactFile string // Artifact file location
}
// Output defines content of output file
Output struct {
OutputFile string // File where plugin output are saved
}
// Plugin defines the Docker plugin parameters.
Plugin struct {
Build Build // Docker build configuration
Artifact Artifact // Artifact file content
Output Output // Output file content
}
)
@@ -148,14 +156,15 @@ func (p Plugin) Exec() error {
fmt.Sprintf("--context=dir://%s", p.Build.Context),
}
// Set the destination repository
if !p.Build.NoPush {
// Set the destination repository only when we push or save to tarball
if !p.Build.NoPush || p.Build.TarPath != "" {
for _, tag := range tags {
for _, label := range p.Build.labelsForTag(tag) {
cmdArgs = append(cmdArgs, fmt.Sprintf("--destination=%s:%s", p.Build.Repo, label))
}
}
}
// Set the build arguments
for _, arg := range p.Build.Args {
cmdArgs = append(cmdArgs, fmt.Sprintf("--build-arg=%s", arg))
@@ -212,6 +221,10 @@ func (p Plugin) Exec() error {
cmdArgs = append(cmdArgs, "--skip-unused-stages")
}
if p.Build.TarPath != "" {
cmdArgs = append(cmdArgs, fmt.Sprintf("--tar-path=%s", p.Build.TarPath))
}
cmd := exec.Command("/kaniko/executor", cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
@@ -223,19 +236,29 @@ func (p Plugin) Exec() error {
}
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)
err = artifact.WritePluginArtifactFile(p.Artifact.RegistryType, p.Artifact.ArtifactFile, p.Artifact.Registry, p.Artifact.Repo, getDigest(p.Build.DigestFile), 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)
}
}
if p.Output.OutputFile != "" {
if err = output.WritePluginOutputFile(p.Output.OutputFile, getDigest(p.Build.DigestFile)); err != nil {
fmt.Fprintf(os.Stderr, "failed to write plugin output file at path: %s with error: %s\n", p.Output.OutputFile, err)
}
}
return nil
}
func getDigest(digestFile string) string {
content, err := ioutil.ReadFile(digestFile)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read digest file contents at path: %s with error: %s\n", digestFile, err)
}
return string(content)
}
// trace writes each command to stdout with the command wrapped in an xml
// tag so that it can be extracted and displayed in the logs.
func trace(cmd *exec.Cmd) {
+10 -1
View File
@@ -100,7 +100,16 @@ func TestBuild_AutoTags(t *testing.T) {
},
},
{
name: "tag push",
name: "beta tag push",
repoBranch: "master",
commitRef: "refs/tags/v1.0.0-beta.1",
autoTagSuffix: "",
expectedTags: []string{
"1.0.0-beta.1",
},
},
{
name: "tag push with suffix",
repoBranch: "master",
commitRef: "refs/tags/v1.0.0",
autoTagSuffix: "linux-amd64",
+12
View File
@@ -0,0 +1,12 @@
package output
import (
"github.com/joho/godotenv"
)
func WritePluginOutputFile(outputFilePath, digest string) error {
output := map[string]string{
"digest": digest,
}
return godotenv.Write(output, outputFilePath)
}