mirror of
https://github.com/drone/drone-kaniko.git
synced 2026-06-14 05:12:27 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ae79bd9d1b | |||
| ae33ce93b8 | |||
| a8c364c9e7 | |||
| a879280371 |
+142
-7
@@ -13,6 +13,8 @@ import (
|
|||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
|
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
|
||||||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
|
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
|
||||||
|
"github.com/google/go-containerregistry/pkg/authn"
|
||||||
|
"github.com/google/go-containerregistry/pkg/crane"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
@@ -20,6 +22,7 @@ import (
|
|||||||
kaniko "github.com/drone/drone-kaniko"
|
kaniko "github.com/drone/drone-kaniko"
|
||||||
"github.com/drone/drone-kaniko/pkg/artifact"
|
"github.com/drone/drone-kaniko/pkg/artifact"
|
||||||
"github.com/drone/drone-kaniko/pkg/docker"
|
"github.com/drone/drone-kaniko/pkg/docker"
|
||||||
|
"github.com/drone/drone-kaniko/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -96,6 +99,17 @@ func main() {
|
|||||||
Usage: "build args",
|
Usage: "build args",
|
||||||
EnvVar: "PLUGIN_BUILD_ARGS",
|
EnvVar: "PLUGIN_BUILD_ARGS",
|
||||||
},
|
},
|
||||||
|
cli.GenericFlag{
|
||||||
|
Name: "args-new",
|
||||||
|
Usage: "build args new",
|
||||||
|
EnvVar: "PLUGIN_BUILD_ARGS_NEW",
|
||||||
|
Value: new(utils.CustomStringSliceFlag),
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "plugin-multiple-build-agrs",
|
||||||
|
Usage: "plugin multiple build agrs",
|
||||||
|
EnvVar: "PLUGIN_MULTIPLE_BUILD_ARGS",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "target",
|
Name: "target",
|
||||||
Usage: "build target",
|
Usage: "build target",
|
||||||
@@ -206,6 +220,21 @@ func main() {
|
|||||||
Usage: "Set this flag if you only want to build the image, without pushing to a registry",
|
Usage: "Set this flag if you only want to build the image, without pushing to a registry",
|
||||||
EnvVar: "PLUGIN_NO_PUSH",
|
EnvVar: "PLUGIN_NO_PUSH",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "push-only",
|
||||||
|
Usage: "Set this flag if you only want to push a pre-built image from a tarball",
|
||||||
|
EnvVar: "PLUGIN_PUSH_ONLY",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "source-tar-path",
|
||||||
|
Usage: "Path to the local tarball to be pushed when push-only is set",
|
||||||
|
EnvVar: "PLUGIN_SOURCE_TAR_PATH",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "tar-path",
|
||||||
|
Usage: "Set this flag to save the image as a tarball at path",
|
||||||
|
EnvVar: "PLUGIN_TAR_PATH,PLUGIN_DESTINATION_TAR_PATH",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "verbosity",
|
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.",
|
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.",
|
||||||
@@ -380,6 +409,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run(c *cli.Context) error {
|
func run(c *cli.Context) error {
|
||||||
|
// Check if push-only flag is set
|
||||||
|
if c.Bool("push-only") {
|
||||||
|
return handlePushOnly(c)
|
||||||
|
}
|
||||||
|
|
||||||
registry := c.String("registry")
|
registry := c.String("registry")
|
||||||
noPush := c.Bool("no-push")
|
noPush := c.Bool("no-push")
|
||||||
|
|
||||||
@@ -410,6 +444,8 @@ func run(c *cli.Context) error {
|
|||||||
AutoTagSuffix: c.String("auto-tag-suffix"),
|
AutoTagSuffix: c.String("auto-tag-suffix"),
|
||||||
ExpandTag: c.Bool("expand-tag"),
|
ExpandTag: c.Bool("expand-tag"),
|
||||||
Args: c.StringSlice("args"),
|
Args: c.StringSlice("args"),
|
||||||
|
ArgsNew: c.Generic("args-new").(*utils.CustomStringSliceFlag).GetValue(),
|
||||||
|
IsMultipleBuildArgs: c.Bool("plugin-multiple-build-agrs"),
|
||||||
Target: c.String("target"),
|
Target: c.String("target"),
|
||||||
Repo: c.String("repo"),
|
Repo: c.String("repo"),
|
||||||
Mirrors: c.StringSlice("registry-mirrors"),
|
Mirrors: c.StringSlice("registry-mirrors"),
|
||||||
@@ -471,6 +507,12 @@ func run(c *cli.Context) error {
|
|||||||
flag := c.Bool("ignore-var-run")
|
flag := c.Bool("ignore-var-run")
|
||||||
plugin.Build.IgnoreVarRun = &flag
|
plugin.Build.IgnoreVarRun = &flag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set tar-path if provided
|
||||||
|
if c.IsSet("tar-path") {
|
||||||
|
plugin.Build.TarPath = c.String("tar-path")
|
||||||
|
}
|
||||||
|
|
||||||
return plugin.Exec()
|
return plugin.Exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,21 +725,114 @@ func setDockerAuth(username, password, registry, dockerUsername, dockerPassword,
|
|||||||
Password: password,
|
Password: password,
|
||||||
}
|
}
|
||||||
|
|
||||||
pullFromRegistryCreds := docker.RegistryCredentials{
|
credentials := []docker.RegistryCredentials{pushToRegistryCreds}
|
||||||
Registry: dockerRegistry,
|
|
||||||
Username: dockerUsername,
|
if dockerRegistry != "" {
|
||||||
Password: dockerPassword,
|
pullFromRegistryCreds := docker.RegistryCredentials{
|
||||||
|
Registry: dockerRegistry,
|
||||||
|
Username: dockerUsername,
|
||||||
|
Password: dockerPassword,
|
||||||
|
}
|
||||||
|
credentials = append(credentials, pullFromRegistryCreds)
|
||||||
|
} else {
|
||||||
|
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||||
|
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||||
}
|
}
|
||||||
|
|
||||||
credentials := []docker.RegistryCredentials{pushToRegistryCreds, pullFromRegistryCreds}
|
|
||||||
return dockerConfig.CreateDockerConfig(credentials, dockerConfigPath)
|
return dockerConfig.CreateDockerConfig(credentials, dockerConfigPath)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeParam(s string) string {
|
func encodeParam(s string) string {
|
||||||
return url.QueryEscape(s)
|
return url.QueryEscape(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handlePushOnly(c *cli.Context) error {
|
||||||
|
// Validate inputs for push-only operation
|
||||||
|
sourceTarPath := c.String("source-tar-path")
|
||||||
|
if sourceTarPath == "" {
|
||||||
|
return fmt.Errorf("source_tar_path is required when push_only is set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(sourceTarPath); os.IsNotExist(err) {
|
||||||
|
return fmt.Errorf("image tarball does not exist at path: %s", sourceTarPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
repo := c.String("repo")
|
||||||
|
registry := c.String("registry")
|
||||||
|
if repo == "" || registry == "" {
|
||||||
|
return fmt.Errorf("repository and registry must be specified for push-only operation")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup ACR authentication
|
||||||
|
publicUrl, err := setupAuth(
|
||||||
|
c.String("tenant-id"),
|
||||||
|
c.String("client-id"),
|
||||||
|
c.String("client-cert"),
|
||||||
|
c.String("client-secret"),
|
||||||
|
c.String("subscription-id"),
|
||||||
|
registry,
|
||||||
|
c.String("base-image-username"),
|
||||||
|
c.String("base-image-password"),
|
||||||
|
c.String("base-image-registry"),
|
||||||
|
false, // We want to push in push-only mode
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the image from the tarball
|
||||||
|
logrus.Infof("Loading image from tarball: %s", sourceTarPath)
|
||||||
|
|
||||||
|
img, err := crane.Load(sourceTarPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to load image from tarball: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the Docker config directory exists (should have been created by setupAuth)
|
||||||
|
if _, err := os.Stat(dockerConfigPath); os.IsNotExist(err) {
|
||||||
|
return fmt.Errorf("Docker config directory does not exist: %v", err)
|
||||||
|
} else if err != nil {
|
||||||
|
return fmt.Errorf("error checking Docker config directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Explicitly set DOCKER_CONFIG environment variable to ensure crane finds the config
|
||||||
|
if err := os.Setenv("DOCKER_CONFIG", dockerConfigPath); err != nil {
|
||||||
|
return fmt.Errorf("failed to set DOCKER_CONFIG environment variable: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup crane options
|
||||||
|
opts := []crane.Option{
|
||||||
|
crane.WithAuthFromKeychain(authn.DefaultKeychain),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push for each tag
|
||||||
|
tags := c.StringSlice("tags")
|
||||||
|
if len(tags) == 0 {
|
||||||
|
tags = []string{"latest"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the registry from setupAuth if publicUrl is available, otherwise use the provided registry
|
||||||
|
pushRegistry := registry
|
||||||
|
if publicUrl != "" {
|
||||||
|
logrus.Infof("Using public URL for pushing: %s", publicUrl)
|
||||||
|
// Extract just the registry part from the full URL if needed
|
||||||
|
// This depends on the format of publicUrl, adjust parsing as needed
|
||||||
|
pushRegistry = publicUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tag := range tags {
|
||||||
|
dest := fmt.Sprintf("%s/%s:%s", pushRegistry, repo, tag)
|
||||||
|
logrus.Infof("Pushing image to: %s", dest)
|
||||||
|
|
||||||
|
if err := crane.Push(img, dest, opts...); err != nil {
|
||||||
|
return fmt.Errorf("failed to push image to %s: %v", dest, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("Successfully pushed image to %s", dest)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type strct struct {
|
type strct struct {
|
||||||
Value []struct {
|
Value []struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
|||||||
@@ -153,4 +153,4 @@ func TestCreateDockerConfigWithoutBaseRegistry(t *testing.T) {
|
|||||||
// Check if the public Docker Hub auth is not set
|
// Check if the public Docker Hub auth is not set
|
||||||
_, exists := config.Auths[""]
|
_, exists := config.Auths[""]
|
||||||
assert.False(t, exists)
|
assert.False(t, exists)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ import (
|
|||||||
kaniko "github.com/drone/drone-kaniko"
|
kaniko "github.com/drone/drone-kaniko"
|
||||||
"github.com/drone/drone-kaniko/pkg/artifact"
|
"github.com/drone/drone-kaniko/pkg/artifact"
|
||||||
"github.com/drone/drone-kaniko/pkg/docker"
|
"github.com/drone/drone-kaniko/pkg/docker"
|
||||||
|
"github.com/drone/drone-kaniko/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -101,6 +103,17 @@ func main() {
|
|||||||
Usage: "build args",
|
Usage: "build args",
|
||||||
EnvVar: "PLUGIN_BUILD_ARGS",
|
EnvVar: "PLUGIN_BUILD_ARGS",
|
||||||
},
|
},
|
||||||
|
cli.GenericFlag{
|
||||||
|
Name: "args-new",
|
||||||
|
Usage: "build args new",
|
||||||
|
EnvVar: "PLUGIN_BUILD_ARGS_NEW",
|
||||||
|
Value: new(utils.CustomStringSliceFlag),
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "plugin-multiple-build-agrs",
|
||||||
|
Usage: "plugin multiple build agrs",
|
||||||
|
EnvVar: "PLUGIN_MULTIPLE_BUILD_ARGS",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "target",
|
Name: "target",
|
||||||
Usage: "build target",
|
Usage: "build target",
|
||||||
@@ -238,6 +251,7 @@ func main() {
|
|||||||
Usage: "Enable or disable compressed caching.",
|
Usage: "Enable or disable compressed caching.",
|
||||||
EnvVar: "PLUGIN_COMPRESSED_CACHING",
|
EnvVar: "PLUGIN_COMPRESSED_CACHING",
|
||||||
},
|
},
|
||||||
|
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "context-sub-path",
|
Name: "context-sub-path",
|
||||||
Usage: "Sub-path within the context to build.",
|
Usage: "Sub-path within the context to build.",
|
||||||
@@ -348,6 +362,11 @@ func main() {
|
|||||||
Usage: "Ignore the /var/run directory during build.",
|
Usage: "Ignore the /var/run directory during build.",
|
||||||
EnvVar: "PLUGIN_IGNORE_VAR_RUN",
|
EnvVar: "PLUGIN_IGNORE_VAR_RUN",
|
||||||
},
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "args",
|
||||||
|
Usage: "build args",
|
||||||
|
EnvVar: "PLUGIN_BUILD_ARGS",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "ignore-path",
|
Name: "ignore-path",
|
||||||
Usage: "Path to ignore during the build.",
|
Usage: "Path to ignore during the build.",
|
||||||
@@ -420,6 +439,8 @@ func run(c *cli.Context) error {
|
|||||||
AutoTagSuffix: c.String("auto-tag-suffix"),
|
AutoTagSuffix: c.String("auto-tag-suffix"),
|
||||||
ExpandTag: c.Bool("expand-tag"),
|
ExpandTag: c.Bool("expand-tag"),
|
||||||
Args: c.StringSlice("args"),
|
Args: c.StringSlice("args"),
|
||||||
|
ArgsNew: c.Generic("args-new").(*utils.CustomStringSliceFlag).GetValue(),
|
||||||
|
IsMultipleBuildArgs: c.Bool("plugin-multiple-build-agrs"),
|
||||||
Target: c.String("target"),
|
Target: c.String("target"),
|
||||||
Repo: buildRepo(c.String("registry"), c.String("repo"), c.Bool("expand-repo")),
|
Repo: buildRepo(c.String("registry"), c.String("repo"), c.Bool("expand-repo")),
|
||||||
Mirrors: c.StringSlice("registry-mirrors"),
|
Mirrors: c.StringSlice("registry-mirrors"),
|
||||||
@@ -508,6 +529,9 @@ func setDockerAuth(username, password, registry, baseImageUsername, baseImagePas
|
|||||||
Password: baseImagePassword,
|
Password: baseImagePassword,
|
||||||
}
|
}
|
||||||
credentials = append(credentials, pullFromRegistryCreds)
|
credentials = append(credentials, pullFromRegistryCreds)
|
||||||
|
} else {
|
||||||
|
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||||
|
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||||
}
|
}
|
||||||
// Creates docker config for both the regustries used for authentication
|
// Creates docker config for both the regustries used for authentication
|
||||||
return dockerConfig.CreateDockerConfig(credentials, dockerPath)
|
return dockerConfig.CreateDockerConfig(credentials, dockerPath)
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import (
|
|||||||
kaniko "github.com/drone/drone-kaniko"
|
kaniko "github.com/drone/drone-kaniko"
|
||||||
"github.com/drone/drone-kaniko/pkg/artifact"
|
"github.com/drone/drone-kaniko/pkg/artifact"
|
||||||
"github.com/drone/drone-kaniko/pkg/docker"
|
"github.com/drone/drone-kaniko/pkg/docker"
|
||||||
|
"github.com/drone/drone-kaniko/pkg/utils"
|
||||||
"github.com/google/go-containerregistry/pkg/authn"
|
"github.com/google/go-containerregistry/pkg/authn"
|
||||||
"github.com/google/go-containerregistry/pkg/crane"
|
"github.com/google/go-containerregistry/pkg/crane"
|
||||||
)
|
)
|
||||||
@@ -132,7 +133,7 @@ func main() {
|
|||||||
Name: "args-new",
|
Name: "args-new",
|
||||||
Usage: "build args new",
|
Usage: "build args new",
|
||||||
EnvVar: "PLUGIN_BUILD_ARGS_NEW",
|
EnvVar: "PLUGIN_BUILD_ARGS_NEW",
|
||||||
Value: new(CustomStringSliceFlag),
|
Value: new(utils.CustomStringSliceFlag),
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "plugin-multiple-build-agrs",
|
Name: "plugin-multiple-build-agrs",
|
||||||
@@ -504,7 +505,7 @@ func run(c *cli.Context) error {
|
|||||||
AutoTagSuffix: c.String("auto-tag-suffix"),
|
AutoTagSuffix: c.String("auto-tag-suffix"),
|
||||||
ExpandTag: c.Bool("expand-tag"),
|
ExpandTag: c.Bool("expand-tag"),
|
||||||
Args: c.StringSlice("args"),
|
Args: c.StringSlice("args"),
|
||||||
ArgsNew: c.Generic("args-new").(*CustomStringSliceFlag).GetValue(),
|
ArgsNew: c.Generic("args-new").(*utils.CustomStringSliceFlag).GetValue(),
|
||||||
IsMultipleBuildArgs: c.Bool("plugin-multiple-build-agrs"),
|
IsMultipleBuildArgs: c.Bool("plugin-multiple-build-agrs"),
|
||||||
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")),
|
||||||
@@ -585,6 +586,9 @@ func setDockerAuth(dockerRegistry, dockerUsername, dockerPassword, accessKey, se
|
|||||||
Password: dockerPassword,
|
Password: dockerPassword,
|
||||||
}
|
}
|
||||||
credentials = append(credentials, pullFromRegistryCreds)
|
credentials = append(credentials, pullFromRegistryCreds)
|
||||||
|
} else {
|
||||||
|
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||||
|
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||||
}
|
}
|
||||||
|
|
||||||
if assumeRole != "" && oidcToken != "" {
|
if assumeRole != "" && oidcToken != "" {
|
||||||
|
|||||||
@@ -42,4 +42,4 @@ func TestCreateDockerConfigForECRWithBaseRegistry(t *testing.T) {
|
|||||||
|
|
||||||
expectedDockerAuth := docker.Auth{Auth: base64.StdEncoding.EncodeToString([]byte(dockerUsername + ":" + dockerPassword))}
|
expectedDockerAuth := docker.Auth{Auth: base64.StdEncoding.EncodeToString([]byte(dockerUsername + ":" + dockerPassword))}
|
||||||
assert.Equal(t, expectedDockerAuth, config.Auths[dockerRegistry])
|
assert.Equal(t, expectedDockerAuth, config.Auths[dockerRegistry])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import (
|
|||||||
"github.com/drone/drone-kaniko/pkg/docker"
|
"github.com/drone/drone-kaniko/pkg/docker"
|
||||||
"github.com/google/go-containerregistry/pkg/authn"
|
"github.com/google/go-containerregistry/pkg/authn"
|
||||||
"github.com/google/go-containerregistry/pkg/crane"
|
"github.com/google/go-containerregistry/pkg/crane"
|
||||||
|
"github.com/drone/drone-kaniko/pkg/utils"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -96,6 +98,17 @@ func main() {
|
|||||||
Usage: "build args",
|
Usage: "build args",
|
||||||
EnvVar: "PLUGIN_BUILD_ARGS",
|
EnvVar: "PLUGIN_BUILD_ARGS",
|
||||||
},
|
},
|
||||||
|
cli.GenericFlag{
|
||||||
|
Name: "args-new",
|
||||||
|
Usage: "build args new",
|
||||||
|
EnvVar: "PLUGIN_BUILD_ARGS_NEW",
|
||||||
|
Value: new(utils.CustomStringSliceFlag),
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "plugin-multiple-build-agrs",
|
||||||
|
Usage: "plugin multiple build agrs",
|
||||||
|
EnvVar: "PLUGIN_MULTIPLE_BUILD_ARGS",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "target",
|
Name: "target",
|
||||||
Usage: "build target",
|
Usage: "build target",
|
||||||
@@ -384,6 +397,9 @@ func run(c *cli.Context) error {
|
|||||||
); err != nil {
|
); err != nil {
|
||||||
return errors.Wrap(err, "failed to create docker config")
|
return errors.Wrap(err, "failed to create docker config")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||||
|
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,6 +414,8 @@ func run(c *cli.Context) error {
|
|||||||
AutoTagSuffix: c.String("auto-tag-suffix"),
|
AutoTagSuffix: c.String("auto-tag-suffix"),
|
||||||
ExpandTag: c.Bool("expand-tag"),
|
ExpandTag: c.Bool("expand-tag"),
|
||||||
Args: c.StringSlice("args"),
|
Args: c.StringSlice("args"),
|
||||||
|
ArgsNew: c.Generic("args-new").(*utils.CustomStringSliceFlag).GetValue(),
|
||||||
|
IsMultipleBuildArgs: c.Bool("plugin-multiple-build-agrs"),
|
||||||
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")),
|
||||||
Mirrors: c.StringSlice("registry-mirrors"),
|
Mirrors: c.StringSlice("registry-mirrors"),
|
||||||
|
|||||||
+20
-4
@@ -13,13 +13,14 @@ import (
|
|||||||
kaniko "github.com/drone/drone-kaniko"
|
kaniko "github.com/drone/drone-kaniko"
|
||||||
"github.com/drone/drone-kaniko/pkg/artifact"
|
"github.com/drone/drone-kaniko/pkg/artifact"
|
||||||
"github.com/drone/drone-kaniko/pkg/docker"
|
"github.com/drone/drone-kaniko/pkg/docker"
|
||||||
|
"github.com/drone/drone-kaniko/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
dockerConfigPath string = "/kaniko/.docker"
|
dockerConfigPath string = "/kaniko/.docker"
|
||||||
// GCR JSON key file path
|
// GCR JSON key file path
|
||||||
gcrKeyPath string = "/kaniko/config.json"
|
gcrKeyPath string = "/kaniko/config.json"
|
||||||
gcrEnvVariable string = "GOOGLE_APPLICATION_CREDENTIALS"
|
gcrEnvVariable string = "GOOGLE_APPLICATION_CREDENTIALS"
|
||||||
|
|
||||||
defaultDigestFile string = "/kaniko/digest-file"
|
defaultDigestFile string = "/kaniko/digest-file"
|
||||||
)
|
)
|
||||||
@@ -333,6 +334,18 @@ func main() {
|
|||||||
Usage: "Number of retries for downloading base images.",
|
Usage: "Number of retries for downloading base images.",
|
||||||
EnvVar: "PLUGIN_IMAGE_DOWNLOAD_RETRY",
|
EnvVar: "PLUGIN_IMAGE_DOWNLOAD_RETRY",
|
||||||
},
|
},
|
||||||
|
cli.GenericFlag{
|
||||||
|
Name: "args-new",
|
||||||
|
Usage: "build args new",
|
||||||
|
EnvVar: "PLUGIN_BUILD_ARGS_NEW",
|
||||||
|
Value: new(utils.CustomStringSliceFlag),
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "plugin-multiple-build-agrs",
|
||||||
|
Usage: "plugin multiple build agrs",
|
||||||
|
EnvVar: "PLUGIN_MULTIPLE_BUILD_ARGS",
|
||||||
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
@@ -353,7 +366,7 @@ func run(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup docker config only when base image registry is specified
|
// setup docker config only when base image registry is specified
|
||||||
if c.String("base-image-registry") != ""{
|
if c.String("base-image-registry") != "" {
|
||||||
if err := setDockerAuth(
|
if err := setDockerAuth(
|
||||||
c.String("base-image-username"),
|
c.String("base-image-username"),
|
||||||
c.String("base-image-password"),
|
c.String("base-image-password"),
|
||||||
@@ -361,6 +374,9 @@ func run(c *cli.Context) error {
|
|||||||
); err != nil {
|
); err != nil {
|
||||||
return errors.Wrap(err, "failed to create docker config")
|
return errors.Wrap(err, "failed to create docker config")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("\033[33mTo ensure consistent and reliable pipeline execution, we recommend setting up a Base Image Connector.\033[0m\n" +
|
||||||
|
"\033[33mWhile optional at this time, configuring it helps prevent failures caused by Docker Hub's rate limits.\033[0m")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +455,7 @@ func run(c *cli.Context) error {
|
|||||||
return plugin.Exec()
|
return plugin.Exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setDockerAuth(dockerUsername, dockerPassword, dockerRegistry string) (error) {
|
func setDockerAuth(dockerUsername, dockerPassword, dockerRegistry string) error {
|
||||||
dockerConfig := docker.NewConfig()
|
dockerConfig := docker.NewConfig()
|
||||||
dockerRegistryCreds := docker.RegistryCredentials{
|
dockerRegistryCreds := docker.RegistryCredentials{
|
||||||
Registry: dockerRegistry,
|
Registry: dockerRegistry,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:v1.23.2
|
FROM harnesscommunity/kaniko-executor:1.25.0-linux-amd64
|
||||||
|
|
||||||
ENV KANIKO_VERSION=1.23.2
|
ENV KANIKO_VERSION=1.25.0
|
||||||
ADD release/linux/amd64/kaniko-acr /kaniko/
|
ADD release/linux/amd64/kaniko-acr /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-acr"]
|
ENTRYPOINT ["/kaniko/kaniko-acr"]
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:v1.23.0
|
FROM harnesscommunity/kaniko-executor:1.25.0-linux-arm64
|
||||||
|
|
||||||
ENV HOME /root
|
ENV HOME /root
|
||||||
ENV USER root
|
ENV USER root
|
||||||
|
|
||||||
ENV KANIKO_VERSION=1.23.0
|
ENV KANIKO_VERSION=1.25.0
|
||||||
ADD release/linux/arm64/kaniko-acr /kaniko/
|
ADD release/linux/arm64/kaniko-acr /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-acr"]
|
ENTRYPOINT ["/kaniko/kaniko-acr"]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:v1.23.2
|
FROM harnesscommunity/kaniko-executor:1.25.0-linux-amd64
|
||||||
|
|
||||||
ENV KANIKO_VERSION=1.23.2
|
ENV KANIKO_VERSION=1.25.0
|
||||||
ADD release/linux/amd64/kaniko-docker /kaniko/
|
ADD release/linux/amd64/kaniko-docker /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-docker"]
|
ENTRYPOINT ["/kaniko/kaniko-docker"]
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:v1.23.2
|
FROM harnesscommunity/kaniko-executor:1.25.0-linux-arm64
|
||||||
|
|
||||||
ENV HOME /root
|
ENV HOME /root
|
||||||
ENV USER root
|
ENV USER root
|
||||||
|
|
||||||
ENV KANIKO_VERSION=1.23.2
|
ENV KANIKO_VERSION=1.25.0
|
||||||
ADD release/linux/arm64/kaniko-docker /kaniko/
|
ADD release/linux/arm64/kaniko-docker /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-docker"]
|
ENTRYPOINT ["/kaniko/kaniko-docker"]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:v1.23.2
|
FROM harnesscommunity/kaniko-executor:1.25.0-linux-amd64
|
||||||
|
|
||||||
ENV KANIKO_VERSION=1.23.2
|
ENV KANIKO_VERSION=1.25.0
|
||||||
ADD release/linux/amd64/kaniko-ecr /kaniko/
|
ADD release/linux/amd64/kaniko-ecr /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-ecr"]
|
ENTRYPOINT ["/kaniko/kaniko-ecr"]
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:v1.23.2
|
FROM harnesscommunity/kaniko-executor:1.25.0-linux-arm64
|
||||||
|
|
||||||
ENV HOME /root
|
ENV HOME /root
|
||||||
ENV USER root
|
ENV USER root
|
||||||
ENV KANIKO_VERSION=1.23.2
|
ENV KANIKO_VERSION=1.25.0
|
||||||
|
|
||||||
ADD release/linux/arm64/kaniko-ecr /kaniko/
|
ADD release/linux/arm64/kaniko-ecr /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-ecr"]
|
ENTRYPOINT ["/kaniko/kaniko-ecr"]
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:v1.23.2
|
FROM harnesscommunity/kaniko-executor:1.25.0-linux-amd64
|
||||||
|
|
||||||
ENV KANIKO_VERSION=1.23.2
|
ENV KANIKO_VERSION=1.25.0
|
||||||
ADD release/linux/amd64/kaniko-gar /kaniko/
|
ADD release/linux/amd64/kaniko-gar /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-gar"]
|
ENTRYPOINT ["/kaniko/kaniko-gar"]
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
FROM gcr.io/kaniko-project/executor:v1.23.2
|
FROM harnesscommunity/kaniko-executor:1.25.0-linux-arm64
|
||||||
|
|
||||||
ENV HOME /root
|
ENV HOME /root
|
||||||
ENV USER root
|
ENV USER root
|
||||||
ENV KANIKO_VERSION=1.23.2
|
ENV KANIKO_VERSION=1.25.0
|
||||||
|
|
||||||
ADD release/linux/arm64/kaniko-gar /kaniko/
|
ADD release/linux/arm64/kaniko-gar /kaniko/
|
||||||
ENTRYPOINT ["/kaniko/kaniko-gar"]
|
ENTRYPOINT ["/kaniko/kaniko-gar"]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@@ -10,6 +10,7 @@ type CustomStringSliceFlag struct {
|
|||||||
Value []string
|
Value []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetValue returns the slice of strings stored in the flag
|
||||||
func (f *CustomStringSliceFlag) GetValue() []string {
|
func (f *CustomStringSliceFlag) GetValue() []string {
|
||||||
if f.Value == nil {
|
if f.Value == nil {
|
||||||
return make([]string, 0)
|
return make([]string, 0)
|
||||||
@@ -17,6 +18,7 @@ func (f *CustomStringSliceFlag) GetValue() []string {
|
|||||||
return f.Value
|
return f.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns a string representation of the flag
|
||||||
func (f *CustomStringSliceFlag) String() string {
|
func (f *CustomStringSliceFlag) String() string {
|
||||||
if f.Value == nil {
|
if f.Value == nil {
|
||||||
return ""
|
return ""
|
||||||
@@ -24,6 +26,7 @@ func (f *CustomStringSliceFlag) String() string {
|
|||||||
return strings.Join(f.Value, ";")
|
return strings.Join(f.Value, ";")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set sets the value of the flag from a string
|
||||||
func (f *CustomStringSliceFlag) Set(v string) error {
|
func (f *CustomStringSliceFlag) Set(v string) error {
|
||||||
for _, s := range strings.Split(v, ";") {
|
for _, s := range strings.Split(v, ";") {
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
Reference in New Issue
Block a user