Compare commits

..

17 Commits

Author SHA1 Message Date
Aman Singh 648478377d addressed comments 2022-08-01 20:59:21 +05:30
Aman Singh 8d244528bc fixed dockerfile 2022-08-01 19:25:24 +05:30
Aman Singh 032be851de addressed comments 2022-08-01 19:22:48 +05:30
Aman Singh 2a15df4bd0 fixed error handeling 2022-08-01 18:25:50 +05:30
Aman Singh edde153446 addressed pr review comments 2022-08-01 18:13:58 +05:30
Aman Singh c32ed28951 addressed pr review comments 2022-08-01 18:12:07 +05:30
Aman Singh 83dc0a47c8 fixed go.mod and go.sum 2022-08-01 13:27:50 +05:30
Aman Singh 2a96f08569 moved code to an external file 2022-08-01 13:25:49 +05:30
Aman Singh 40b88e559f fixed push code 2022-08-01 13:10:57 +05:30
Aman Singh 42860e1bf6 fixed drone.yml 2022-08-01 12:55:51 +05:30
Aman Singh 261458b664 fixed base image 2022-08-01 12:49:29 +05:30
Aman Singh 62904766db addressed pr comments 2022-08-01 12:34:34 +05:30
Aman Singh fdf1104358 addressed pr comments 2022-08-01 12:33:00 +05:30
Aman Singh 39ca5e4471 added dockerfile 2022-08-01 12:04:26 +05:30
Aman Singh bb4c34c632 fixed cert support 2022-08-01 11:32:27 +05:30
Aman Singh 97101432f6 added drone yaml 2022-08-01 10:45:36 +05:30
Aman Singh 08b3a85089 Added acr integration 2022-08-01 10:44:47 +05:30
32 changed files with 94 additions and 470 deletions
+12 -148
View File
@@ -77,14 +77,14 @@ steps:
exclude:
- pull_request
- name: docker-kaniko-v1-9
- name: docker-kaniko-v1-8
image: plugins/docker
settings:
repo: plugins/kaniko
auto_tag: true
auto_tag_suffix: linux-amd64-kaniko1.9.1
auto_tag_suffix: linux-amd64-kaniko1.8.1
daemon_off: false
dockerfile: docker/docker/Dockerfile.linux.amd64.kaniko1.9.1
dockerfile: docker/docker/Dockerfile.linux.amd64.kaniko1.8.1
username:
from_secret: docker_username
password:
@@ -94,14 +94,14 @@ steps:
exclude:
- pull_request
- name: gcr-kaniko-v1-9
- name: gcr-kaniko-v1-8
image: plugins/docker
settings:
repo: plugins/kaniko-gcr
auto_tag: true
auto_tag_suffix: linux-amd64-kaniko1.9.1
auto_tag_suffix: linux-amd64-kaniko1.8.1
daemon_off: false
dockerfile: docker/gcr/Dockerfile.linux.amd64.kaniko1.9.1
dockerfile: docker/gcr/Dockerfile.linux.amd64.kaniko1.8.1
username:
from_secret: docker_username
password:
@@ -112,148 +112,14 @@ steps:
- pull_request
- name: ecr-kaniko-v1-9
- name: ecr-kaniko-v1-8
image: plugins/docker
settings:
repo: plugins/kaniko-ecr
auto_tag: true
auto_tag_suffix: linux-amd64-kaniko1.9.1
auto_tag_suffix: linux-amd64-kaniko1.8.1
daemon_off: false
dockerfile: docker/ecr/Dockerfile.linux.amd64.kaniko1.9.1
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event:
exclude:
- pull_request
---
kind: pipeline
type: vm
name: arm
pool:
use: ubuntu_arm64
steps:
- name: build
image: golang:1.18
commands:
- go test ./...
- sh scripts/build.sh
- name: docker
image: plugins/docker
settings:
repo: plugins/kaniko
auto_tag: true
auto_tag_suffix: linux-arm64
daemon_off: false
dockerfile: docker/docker/Dockerfile.linux.arm64
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event:
exclude:
- pull_request
- name: gcr
image: plugins/docker
settings:
repo: plugins/kaniko-gcr
auto_tag: true
auto_tag_suffix: linux-arm64
daemon_off: false
dockerfile: docker/gcr/Dockerfile.linux.arm64
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event:
exclude:
- pull_request
- name: ecr
image: plugins/docker
settings:
repo: plugins/kaniko-ecr
auto_tag: true
auto_tag_suffix: linux-arm64
daemon_off: false
dockerfile: docker/ecr/Dockerfile.linux.arm64
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event:
exclude:
- pull_request
- name: acr
image: plugins/docker
settings:
repo: plugins/kaniko-acr
auto_tag: true
auto_tag_suffix: linux-arm64
daemon_off: false
dockerfile: docker/acr/Dockerfile.linux.arm64
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event:
exclude:
- pull_request
- name: docker-kaniko-v1-9
image: plugins/docker
settings:
repo: plugins/kaniko
auto_tag: true
auto_tag_suffix: linux-arm64-kaniko1.9.1
daemon_off: false
dockerfile: docker/docker/Dockerfile.linux.arm64.kaniko1.9.1
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event:
exclude:
- pull_request
- name: gcr-kaniko-v1-9
image: plugins/docker
settings:
repo: plugins/kaniko-gcr
auto_tag: true
auto_tag_suffix: linux-arm64-kaniko1.9.1
daemon_off: false
dockerfile: docker/gcr/Dockerfile.linux.arm64.kaniko1.9.1
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event:
exclude:
- pull_request
- name: ecr-kaniko-v1-9
image: plugins/docker
settings:
repo: plugins/kaniko-ecr
auto_tag: true
auto_tag_suffix: linux-arm64-kaniko1.9.1
daemon_off: false
dockerfile: docker/ecr/Dockerfile.linux.arm64.kaniko1.9.1
dockerfile: docker/ecr/Dockerfile.linux.amd64.kaniko1.8.1
username:
from_secret: docker_username
password:
@@ -327,7 +193,6 @@ trigger:
depends_on:
- default
- arm
---
kind: pipeline
@@ -347,7 +212,7 @@ steps:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/docker/manifest-kaniko1.9.1.tmpl
spec: docker/docker/manifest-kaniko1.8.1.tmpl
username:
from_secret: docker_username
@@ -359,7 +224,7 @@ steps:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/gcr/manifest-kaniko1.9.1.tmpl
spec: docker/gcr/manifest-kaniko1.8.1.tmpl
username:
from_secret: docker_username
@@ -371,7 +236,7 @@ steps:
ignore_missing: true
password:
from_secret: docker_password
spec: docker/ecr/manifest-kaniko1.9.1.tmpl
spec: docker/ecr/manifest-kaniko1.8.1.tmpl
username:
from_secret: docker_username
@@ -382,4 +247,3 @@ trigger:
depends_on:
- default
- arm
-1
View File
@@ -2,4 +2,3 @@ release
coverage.out
vendor
.idea
.vscode
+2 -8
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.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.
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.
## Build
@@ -17,7 +17,6 @@ export GO111MODULE=on
go build -v -a -tags netgo -o release/linux/amd64/kaniko-docker ./cmd/kaniko-docker
go build -v -a -tags netgo -o release/linux/amd64/kaniko-gcr ./cmd/kaniko-gcr
go build -v -a -tags netgo -o release/linux/amd64/kaniko-ecr ./cmd/kaniko-ecr
go build -v -a -tags netgo -o release/linux/amd64/kaniko-acr ./cmd/kaniko-acr
```
## Docker
@@ -29,11 +28,6 @@ docker build \
--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) \
--file docker/docker/Dockerfile.linux.amd64 --tag plugins/kaniko .
docker build \
--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) \
--file docker/acr/Dockerfile.linux.amd64 --tag plugins/kaniko-acr .
docker build \
--label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
@@ -135,4 +129,4 @@ docker run --rm \
```
Tags to push:
- latest.
- latest
+32 -99
View File
@@ -2,14 +2,12 @@ package main
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"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"
@@ -28,9 +26,8 @@ const (
clientSecretKeyEnv string = "AZURE_CLIENT_SECRET"
tenantKeyEnv string = "AZURE_TENANT_ID"
certPathEnv string = "AZURE_CLIENT_CERTIFICATE_PATH"
dockerConfigPath string = "/kaniko/.docker"
dockerConfigPath string = "/kaniko/.docker/config.json"
defaultDigestFile string = "/kaniko/digest-file"
finalUrl string = "https://portal.azure.com/#view/Microsoft_Azure_ContainerRegistries/TagMetadataBlade/registryId/"
)
var (
@@ -133,7 +130,7 @@ func main() {
},
cli.StringFlag{
Name: "client-cert",
Usage: "Azure client certificate encoded in base64 format",
Usage: "Azure client certificate",
EnvVar: "CLIENT_CERTIFICATE",
},
cli.StringFlag{
@@ -141,11 +138,6 @@ 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",
@@ -217,12 +209,11 @@ func run(c *cli.Context) error {
registry := c.String("registry")
noPush := c.Bool("no-push")
publicUrl, err := setupAuth(
err := createDockerConfig(
c.String("tenant-id"),
c.String("client-id"),
c.String("client-cert"),
c.String("client-secret"),
c.String("subscription-id"),
registry,
noPush,
)
@@ -258,7 +249,7 @@ func run(c *cli.Context) error {
Artifact: kaniko.Artifact{
Tags: c.StringSlice("tags"),
Repo: c.String("repo"),
Registry: publicUrl, // this is public url on which the artifact can be seen
Registry: c.String("registry"),
ArtifactFile: c.String("artifact-file"),
RegistryType: artifact.Docker,
},
@@ -266,45 +257,46 @@ func run(c *cli.Context) error {
return plugin.Exec()
}
func setupAuth(tenantId, clientId, cert,
clientSecret, subscriptionId, registry string, noPush bool) (string, error) {
func createDockerConfig(tenantId, clientId, cert,
clientSecret, registry string, noPush bool) 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, publicUrl, err := getACRToken(subscriptionId, tenantId, clientId, clientSecret, cert, registry)
token, err := getACRToken(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(subscriptionId, tenantId, clientId, clientSecret, cert, registry string) (string, string, error) {
func getACRToken(tenantId, clientId, clientSecret, cert, registry 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 secert or cert should be defined")
}
// in case of authentication via cert
@@ -315,21 +307,13 @@ func getACRToken(subscriptionId, tenantId, clientId, clientSecret, cert, registr
}
}
if err := os.Setenv(clientIdEnv, clientId); err != nil {
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")
}
if err := os.Setenv(tenantKeyEnv, tenantId); err != nil {
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")
}
// TODO check for presence of file as well.
os.Setenv(clientIdEnv, clientId)
os.Setenv(clientSecretKeyEnv, clientSecret)
os.Setenv(tenantKeyEnv, tenantId)
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{
@@ -342,20 +326,14 @@ func getACRToken(subscriptionId, tenantId, clientId, clientSecret, cert, registr
azToken, err := env.GetToken(context.Background(), policy)
if err != nil {
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)
return "", errors.Wrap(err, "failed to fetch access token")
}
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, publicUrl, nil
return ACRToken, nil
}
func fetchACRToken(tenantId, token, registry string) (string, error) {
@@ -388,59 +366,14 @@ func fetchACRToken(tenantId, token, registry string) (string, error) {
return "", errors.New("failed to get refresh token from acr")
}
func setupACRCert(cert string) error {
decoded, err := base64.StdEncoding.DecodeString(cert)
if err != nil {
return errors.Wrap(err, "failed to base64 decode ACR certificate")
}
err = ioutil.WriteFile(ACRCertPath, []byte(decoded), 0644)
func setupACRCert(jsonKey string) error {
err := ioutil.WriteFile(ACRCertPath, []byte(jsonKey), 0644)
if err != nil {
return errors.Wrap(err, "failed to write ACR certificate")
}
err = os.Setenv(certPathEnv, ACRCertPath)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed to set %s environment variable", certPathEnv))
}
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"`
}
+6 -39
View File
@@ -90,11 +90,6 @@ 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",
@@ -176,11 +171,6 @@ 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.",
@@ -196,11 +186,6 @@ 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 {
@@ -211,15 +196,9 @@ func main() {
func run(c *cli.Context) error {
username := c.String("username")
noPush := c.Bool("no-push")
configOverride := c.String("dockerconfig")
// 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
// only setup auth when pushing or credentials are defined
if !noPush || username != "" {
if err := createDockerCfgFile(username, c.String("password"), c.String("registry")); err != nil {
return err
}
@@ -247,7 +226,6 @@ 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"),
@@ -259,9 +237,6 @@ 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()
}
@@ -284,22 +259,14 @@ 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")
+3 -13
View File
@@ -64,11 +64,6 @@ 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",
@@ -247,7 +242,6 @@ 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"),
@@ -334,16 +328,12 @@ func run(c *cli.Context) error {
return plugin.Exec()
}
func createDockerConfig(dockerRegistry, dockerUsername, dockerPassword, accessKey, secretKey,
func createDockerConfig(dockerUsername, dockerPassword, accessKey, secretKey,
registry, assumeRole, externalId, region string, noPush bool) (*docker.Config, error) {
dockerConfig := docker.NewConfig()
if dockerUsername != "" {
// if no docker registry provided, use dockerhub by default
if len(dockerRegistry) == 0 {
dockerRegistry = docker.RegistryV1
}
dockerConfig.SetAuth(dockerRegistry, dockerUsername, dockerPassword)
dockerConfig.SetAuth(docker.RegistryV1, dockerUsername, dockerPassword)
}
if assumeRole != "" {
@@ -479,7 +469,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: no basic auth credentials")
return "", "", "", errors.Wrap(err, "failed to get ECR auth")
}
return username, password, registry, nil
}
-28
View File
@@ -10,7 +10,6 @@ import (
func TestCreateDockerConfig(t *testing.T) {
got, err := createDockerConfig(
"",
"docker-username",
"docker-password",
"access-key",
@@ -35,37 +34,10 @@ 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:v1.9.1
FROM gcr.io/kaniko-project/executor
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.8.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.9.1
FROM gcr.io/kaniko-project/executor:arm64-v1.8.1
ENV HOME /root
ENV USER root
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.8.1
ADD release/linux/arm64/kaniko-acr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-acr"]
+2 -7
View File
@@ -1,4 +1,4 @@
image: plugins/kaniko-acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
@@ -7,12 +7,7 @@ tags:
{{/if}}
manifests:
-
image: plugins/kaniko-acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
-
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.9.1
FROM gcr.io/kaniko-project/executor:v1.6.0
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.6.0
ADD release/linux/amd64/kaniko-docker /kaniko/
ENTRYPOINT ["/kaniko/kaniko-docker"]
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.9.1
FROM gcr.io/kaniko-project/executor:v1.8.1
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.8.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.9.1
FROM gcr.io/kaniko-project/executor:arm64-v1.6.0
ENV HOME /root
ENV USER root
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.6.0
ADD release/linux/arm64/kaniko-docker /kaniko/
ENTRYPOINT ["/kaniko/kaniko-docker"]
@@ -1,5 +0,0 @@
FROM gcr.io/kaniko-project/executor:v1.9.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.9.1{{else}}latest-kaniko1.9.1{{/if}}
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-kaniko1.8.1{{else}}latest-kaniko1.8.1{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
@@ -7,12 +7,7 @@ tags:
{{/if}}
manifests:
-
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.9.1
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.8.1
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-kaniko1.9.1
platform:
architecture: arm64
os: linux
-5
View File
@@ -11,8 +11,3 @@ manifests:
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko:{{#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.9.1
FROM gcr.io/kaniko-project/executor:v1.6.0
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.6.0
ADD release/linux/amd64/kaniko-ecr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-ecr"]
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.9.1
FROM gcr.io/kaniko-project/executor:v1.8.1
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.8.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.9.1
FROM gcr.io/kaniko-project/executor:arm64-v1.6.0
ENV HOME /root
ENV USER root
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.6.0
ADD release/linux/arm64/kaniko-ecr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-ecr"]
@@ -1,5 +0,0 @@
FROM gcr.io/kaniko-project/executor:v1.9.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.9.1{{else}}latest-kaniko1.9.1{{/if}}
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-kaniko1.8.1{{else}}latest-kaniko1.8.1{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
@@ -7,12 +7,7 @@ tags:
{{/if}}
manifests:
-
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.9.1
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.8.1
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-kaniko1.9.1
platform:
architecture: arm64
os: linux
-5
View File
@@ -10,9 +10,4 @@ manifests:
image: plugins/kaniko-ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko-ecr:{{#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.9.1
FROM gcr.io/kaniko-project/executor:v1.6.0
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.6.0
ADD release/linux/amd64/kaniko-gcr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-gcr"]
@@ -1,5 +1,5 @@
FROM gcr.io/kaniko-project/executor:v1.9.1
FROM gcr.io/kaniko-project/executor:v1.8.1
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.8.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.9.1
FROM gcr.io/kaniko-project/executor:arm64-v1.6.0
ENV HOME /root
ENV USER root
ENV KANIKO_VERSION=1.9.1
ENV KANIKO_VERSION=1.6.0
ADD release/linux/arm64/kaniko-gcr /kaniko/
ENTRYPOINT ["/kaniko/kaniko-gcr"]
@@ -1,5 +0,0 @@
FROM gcr.io/kaniko-project/executor:v1.9.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.9.1{{else}}latest-kaniko1.9.1{{/if}}
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-kaniko1.8.1{{else}}latest-kaniko1.8.1{{/if}}
{{#if build.tags}}
tags:
{{#each build.tags}}
@@ -7,12 +7,7 @@ tags:
{{/if}}
manifests:
-
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.9.1
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-kaniko1.8.1
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-kaniko1.9.1
platform:
architecture: arm64
os: linux
-5
View File
@@ -11,8 +11,3 @@ manifests:
platform:
architecture: amd64
os: linux
-
image: plugins/kaniko-gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform:
architecture: arm64
os: linux
+7 -30
View File
@@ -8,7 +8,6 @@ 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"
)
@@ -39,7 +38,6 @@ 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
@@ -51,16 +49,10 @@ 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
}
)
@@ -156,15 +148,14 @@ func (p Plugin) Exec() error {
fmt.Sprintf("--context=dir://%s", p.Build.Context),
}
// Set the destination repository only when we push or save to tarball
if !p.Build.NoPush || p.Build.TarPath != "" {
// Set the destination repository
if !p.Build.NoPush {
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))
@@ -221,10 +212,6 @@ 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
@@ -236,29 +223,19 @@ func (p Plugin) Exec() error {
}
if p.Build.DigestFile != "" && p.Artifact.ArtifactFile != "" {
err = artifact.WritePluginArtifactFile(p.Artifact.RegistryType, p.Artifact.ArtifactFile, p.Artifact.Registry, p.Artifact.Repo, getDigest(p.Build.DigestFile), p.Artifact.Tags)
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)
}
}
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) {
+1 -10
View File
@@ -100,16 +100,7 @@ func TestBuild_AutoTags(t *testing.T) {
},
},
{
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",
name: "tag push",
repoBranch: "master",
commitRef: "refs/tags/v1.0.0",
autoTagSuffix: "linux-amd64",
+1 -2
View File
@@ -26,8 +26,7 @@ func CreateDockerCfgFile(username, password, registry, path string) error {
authBytes := []byte(fmt.Sprintf("%s:%s", username, password))
encodedString := base64.StdEncoding.EncodeToString(authBytes)
jsonBytes := []byte(fmt.Sprintf(`{"auths": {"%s": {"auth": "%s"}}}`, "https://"+registry, encodedString))
filePath := path + "/config.json"
err = ioutil.WriteFile(filePath, jsonBytes, 0644)
err = ioutil.WriteFile(path, jsonBytes, 0644)
if err != nil {
return errors.Wrap(err, "failed to create docker config file")
}
-12
View File
@@ -1,12 +0,0 @@
package output
import (
"github.com/joho/godotenv"
)
func WritePluginOutputFile(outputFilePath, digest string) error {
output := map[string]string{
"digest": digest,
}
return godotenv.Write(output, outputFilePath)
}