mirror of
https://github.com/drone/drone-kaniko.git
synced 2026-06-14 05:12:27 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| afd6a19cce | |||
| d381ac6700 | |||
| 39f3398dfe | |||
| 59e09c14de | |||
| 5e7bcabe6a |
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/pkg/errors"
|
||||
@@ -145,6 +146,11 @@ func main() {
|
||||
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.",
|
||||
EnvVar: "PLUGIN_VERBOSITY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "platform",
|
||||
Usage: "Allows to build with another default platform than the host, similarly to docker build --platform",
|
||||
EnvVar: "PLUGIN_PLATFORM",
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
@@ -181,10 +187,11 @@ func run(c *cli.Context) error {
|
||||
DigestFile: defaultDigestFile,
|
||||
NoPush: noPush,
|
||||
Verbosity: c.String("verbosity"),
|
||||
Platform: c.String("platform"),
|
||||
},
|
||||
Artifact: kaniko.Artifact{
|
||||
Tags: c.StringSlice("tags"),
|
||||
Repo: c.String("repo"),
|
||||
Repo: buildRepo(c.String("registry"), c.String("repo")),
|
||||
Registry: c.String("registry"),
|
||||
ArtifactFile: c.String("artifact-file"),
|
||||
RegistryType: artifact.Docker,
|
||||
@@ -225,3 +232,17 @@ func createDockerCfgFile(username, password, registry string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildRepo(registry, repo string) string {
|
||||
if registry == "" {
|
||||
// No custom registry, just return the repo name
|
||||
return repo
|
||||
}
|
||||
if strings.HasPrefix(repo, registry + "/") {
|
||||
// Repo already includes the registry prefix
|
||||
// For backward compatibility, we won't add the prefix again.
|
||||
return repo
|
||||
}
|
||||
// Prefix the repo with the registry
|
||||
return registry + "/" + repo
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_buildRepo(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
registry string
|
||||
repo string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "dockerhub",
|
||||
repo: "golang",
|
||||
want: "golang",
|
||||
},
|
||||
{
|
||||
name: "internal",
|
||||
registry: "artifactory.example.com",
|
||||
repo: "service",
|
||||
want: "artifactory.example.com/service",
|
||||
},
|
||||
{
|
||||
name: "backward_compatibility",
|
||||
registry: "artifactory.example.com",
|
||||
repo: "artifactory.example.com/service",
|
||||
want: "artifactory.example.com/service",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := buildRepo(tt.registry, tt.repo); got != tt.want {
|
||||
t.Errorf("buildRepo(%q, %q) = %v, want %v", tt.registry, tt.repo, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,11 @@ func main() {
|
||||
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.",
|
||||
EnvVar: "PLUGIN_VERBOSITY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "platform",
|
||||
Usage: "Allows to build with another default platform than the host, similarly to docker build --platform",
|
||||
EnvVar: "PLUGIN_PLATFORM",
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
@@ -252,6 +257,7 @@ func run(c *cli.Context) error {
|
||||
DigestFile: defaultDigestFile,
|
||||
NoPush: noPush,
|
||||
Verbosity: c.String("verbosity"),
|
||||
Platform: c.String("platform"),
|
||||
},
|
||||
Artifact: kaniko.Artifact{
|
||||
Tags: c.StringSlice("tags"),
|
||||
|
||||
@@ -130,6 +130,11 @@ func main() {
|
||||
Usage: "Set this flag as --verbosity=<panic|fatal|error|warn|info|debug|trace> to set the logging level for kaniko. Defaults to info.",
|
||||
EnvVar: "PLUGIN_VERBOSITY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "platform",
|
||||
Usage: "Allows to build with another default platform than the host, similarly to docker build --platform",
|
||||
EnvVar: "PLUGIN_PLATFORM",
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
@@ -167,6 +172,7 @@ func run(c *cli.Context) error {
|
||||
DigestFile: defaultDigestFile,
|
||||
NoPush: noPush,
|
||||
Verbosity: c.String("verbosity"),
|
||||
Platform: c.String("platform"),
|
||||
},
|
||||
Artifact: kaniko.Artifact{
|
||||
Tags: c.StringSlice("tags"),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM gcr.io/kaniko-project/executor:v1.6.0
|
||||
FROM gcr.io/kaniko-project/executor:v1.7.0
|
||||
|
||||
ADD release/linux/amd64/kaniko-docker /kaniko/
|
||||
ENTRYPOINT ["/kaniko/kaniko-docker"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM gcr.io/kaniko-project/executor:arm64-v1.6.0
|
||||
FROM gcr.io/kaniko-project/executor:v1.7.0
|
||||
|
||||
ENV HOME /root
|
||||
ENV USER root
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM gcr.io/kaniko-project/executor:v1.6.0
|
||||
FROM gcr.io/kaniko-project/executor:v1.7.0
|
||||
|
||||
ADD release/linux/amd64/kaniko-ecr /kaniko/
|
||||
ENTRYPOINT ["/kaniko/kaniko-ecr"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM gcr.io/kaniko-project/executor:arm64-v1.6.0
|
||||
FROM gcr.io/kaniko-project/executor:v1.7.0
|
||||
|
||||
ENV HOME /root
|
||||
ENV USER root
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM gcr.io/kaniko-project/executor:v1.6.0
|
||||
FROM gcr.io/kaniko-project/executor:v1.7.0
|
||||
|
||||
ADD release/linux/amd64/kaniko-gcr /kaniko/
|
||||
ENTRYPOINT ["/kaniko/kaniko-gcr"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM gcr.io/kaniko-project/executor:arm64-v1.6.0
|
||||
FROM gcr.io/kaniko-project/executor:v1.7.0
|
||||
|
||||
ENV HOME /root
|
||||
ENV USER root
|
||||
|
||||
@@ -30,6 +30,7 @@ type (
|
||||
DigestFile string // Digest file location
|
||||
NoPush bool // Set this flag if you only want to build the image, without pushing to a registry
|
||||
Verbosity string // Log level
|
||||
Platform string // Allows to build with another default platform than the host, similarly to docker build --platform
|
||||
}
|
||||
|
||||
// Artifact defines content of artifact file
|
||||
@@ -142,7 +143,7 @@ func (p Plugin) Exec() error {
|
||||
}
|
||||
|
||||
if p.Build.CacheTTL != 0 {
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--cache-ttl=%d", p.Build.CacheTTL))
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--cache-ttl=%dh", p.Build.CacheTTL))
|
||||
}
|
||||
|
||||
if p.Build.DigestFile != "" {
|
||||
@@ -157,6 +158,10 @@ func (p Plugin) Exec() error {
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--verbosity=%s", p.Build.Verbosity))
|
||||
}
|
||||
|
||||
if p.Build.Platform != "" {
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--customPlatform=%s", p.Build.Platform))
|
||||
}
|
||||
|
||||
cmd := exec.Command("/kaniko/executor", cmdArgs...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
Reference in New Issue
Block a user