mirror of
https://github.com/drone/drone-kaniko.git
synced 2026-06-04 18:23:49 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a71177d4b4 | |||
| 5582e3ed7c | |||
| 4c0f781999 | |||
| 20525e5403 | |||
| 04885c8ec8 |
+2
-2
@@ -11,7 +11,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang:1.22
|
||||
image: golang:1.22.4
|
||||
commands:
|
||||
- go test ./...
|
||||
- sh scripts/build.sh
|
||||
@@ -178,7 +178,7 @@ pool:
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang:1.22
|
||||
image: golang:1.22.4
|
||||
commands:
|
||||
- go test ./...
|
||||
- sh scripts/build.sh
|
||||
|
||||
@@ -4,6 +4,12 @@ Drone kaniko plugin uses [kaniko](https://github.com/GoogleContainerTools/kaniko
|
||||
|
||||
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.
|
||||
|
||||
Run the following script to install git-leaks support to this repo.
|
||||
```
|
||||
chmod +x ./git-hooks/install.sh
|
||||
./git-hooks/install.sh
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
Build the binaries with the following commands:
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
v2RegistryURL string = "https://index.docker.io/v2/" // v2 registry is not supported
|
||||
v2RegistryURL string = "https://index.docker.io/v2/" // v2 registry is not supported
|
||||
)
|
||||
|
||||
func TestCreateDockerConfigWithBaseRegistry(t *testing.T) {
|
||||
@@ -100,22 +100,7 @@ func TestCreateDockerConfigWithBaseRegistry(t *testing.T) {
|
||||
Password: "",
|
||||
},
|
||||
}, tempDir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
// v2 registry but without username password
|
||||
err = config.CreateDockerConfig([]docker.RegistryCredentials{
|
||||
{
|
||||
Registry: registry,
|
||||
Username: username,
|
||||
Password: password,
|
||||
},
|
||||
{
|
||||
Registry: v2RegistryURL,
|
||||
Username: "",
|
||||
Password: "",
|
||||
},
|
||||
}, tempDir)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualError(t, err, "Username must be specified for registry: "+dockerRegistry)
|
||||
|
||||
// private base registry without username/password
|
||||
err = config.CreateDockerConfig([]docker.RegistryCredentials{
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/drone/drone-kaniko/pkg/docker"
|
||||
)
|
||||
|
||||
func Test_buildRepo(t *testing.T) {
|
||||
tests := []struct {
|
||||
@@ -36,58 +42,80 @@ func Test_buildRepo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateDockerConfigFromGivenRegistry(t *testing.T) {
|
||||
func TestCreateDockerConfig(t *testing.T) {
|
||||
config := docker.NewConfig()
|
||||
tempDir, err := ioutil.TempDir("", "docker-config-test")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temporary directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
username string
|
||||
password string
|
||||
registry string
|
||||
dockerUsername string
|
||||
dockerPassword string
|
||||
dockerRegistry string
|
||||
wantErr bool
|
||||
name string
|
||||
credentials []docker.RegistryCredentials
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid credentials",
|
||||
username: "testuser",
|
||||
password: "testpassword",
|
||||
registry: "https://index.docker.io/v1/",
|
||||
wantErr: false,
|
||||
name: "valid credentials",
|
||||
credentials: []docker.RegistryCredentials{
|
||||
{
|
||||
Registry: "https://index.docker.io/v1/",
|
||||
Username: "testuser",
|
||||
Password: "testpassword",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "v2 registry",
|
||||
username: "testuser",
|
||||
password: "testpassword",
|
||||
registry: "https://index.docker.io/v2/",
|
||||
wantErr: false,
|
||||
name: "v2 registry",
|
||||
credentials: []docker.RegistryCredentials{
|
||||
{
|
||||
Registry: "https://index.docker.io/v2/",
|
||||
Username: "testuser",
|
||||
Password: "testpassword",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "docker registry credentials",
|
||||
username: "testuser",
|
||||
password: "testpassword",
|
||||
registry: "https://index.docker.io/v1/",
|
||||
dockerUsername: "dockeruser",
|
||||
dockerPassword: "dockerpassword",
|
||||
dockerRegistry: "https://docker.io",
|
||||
wantErr: false,
|
||||
name: "docker registry credentials",
|
||||
credentials: []docker.RegistryCredentials{
|
||||
{
|
||||
Registry: "https://index.docker.io/v1/",
|
||||
Username: "testuser",
|
||||
Password: "testpassword",
|
||||
},
|
||||
{
|
||||
Registry: "https://docker.io",
|
||||
Username: "dockeruser",
|
||||
Password: "dockerpassword",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "empty docker registry",
|
||||
username: "testuser",
|
||||
password: "testpassword",
|
||||
registry: "https://index.docker.io/v1/",
|
||||
dockerUsername: "dockeruser",
|
||||
dockerPassword: "",
|
||||
dockerRegistry: "https://docker.io",
|
||||
wantErr: false,
|
||||
name: "empty docker registry",
|
||||
credentials: []docker.RegistryCredentials{
|
||||
{
|
||||
Registry: "https://index.docker.io/v1/",
|
||||
Username: "testuser",
|
||||
Password: "testpassword",
|
||||
},
|
||||
{
|
||||
Registry: "https://docker.io",
|
||||
Username: "dockeruser",
|
||||
Password: "",
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := createDockerConfig(tt.username, tt.password, tt.registry, tt.dockerUsername, tt.dockerPassword, tt.dockerRegistry)
|
||||
err := config.CreateDockerConfig(tt.credentials, tempDir)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("createDockerConfig() error = %v, wantErr %v", err, tt.wantErr)
|
||||
t.Errorf("CreateDockerConfig() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
This document explains on how to install certain git hooks globally for all repositories in your machine.
|
||||
|
||||
Step 1: git clone https://github.com/drone/drone-kaniko.git
|
||||
Step 2: cd git-hooks
|
||||
Step 3: Run install.sh
|
||||
|
||||
"install.sh" script will create .git_template in the user directory and will put the git hook and its dependent scripts in it. Along with the .git_template folder, it will add 2 sections "init" and "hooks boolean" in the .gitconfig file in the same user's root directory.
|
||||
After running "install.sh" if you create/clone a new git repository then all the hooks will get install automatically for the git repository. In case of existing git repository copy the contents of ~/.git_template/hooks into the .git/hooks directory of existing git repository.
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
#Helper script to be used as a pre-commit hook.
|
||||
|
||||
echo "This hook checks for any secrets getting pushed as part of commit. If you feel that scan is false positive. \
|
||||
Then add the exclusion in .gitleaksignore file. For more info visit: https://github.com/zricethezav/gitleaks"
|
||||
|
||||
GIT_LEAKS_PRE_COMMIT=s$(git config --bool hook.pre-commit.gitleak)
|
||||
|
||||
echo "INFO: Scanning Commits information for any GIT LEAKS"
|
||||
gitleaks protect --staged -v --exit-code=100
|
||||
STATUS=$?
|
||||
if [ $STATUS = 100 ]; then
|
||||
echo "WARNING: GIT LEAKS has detected sensitive information in your changes. Please remove them or add them (IF NON-SENSITIVE) in .gitleaksignore file."
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
#Helper script to be used as a pre-commit hook.
|
||||
|
||||
echo "This hook checks for any secrets getting pushed as part of commit. If you feel that scan is false positive. \
|
||||
Then add the exclusion in .gitleaksignore file. For more info visit: https://github.com/zricethezav/gitleaks"
|
||||
|
||||
GIT_LEAKS=$(git config --bool hook.pre-push.gitleaks)
|
||||
|
||||
echo "INFO: Scanning Commits information for any GIT LEAKS"
|
||||
gitleaks detect -s ./ --log-level=debug --log-opts=-1 -v
|
||||
STATUS=$?
|
||||
if [ $STATUS != 0 ]; then
|
||||
echo "WARNING: GIT LEAKS has detected sensitive information in your changes. Please remove them or add them (IF NON-SENSITIVE) in .gitleaksignore file."
|
||||
exit $STATUS
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
GL_SCRIPT_PATH="$HOME/.git_template/hooks/git-leaks-pre-commit.sh"
|
||||
|
||||
pushd `dirname $0` > /dev/null && cd ../.. && BASEDIR=$(pwd -L) && popd > /dev/null
|
||||
BASENAME=`basename $0`
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
#Initial commit : diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
GIT_LEAKS_PRE_COMMIT=hook.pre-commit.gitleaks
|
||||
if [ "`git config $GIT_LEAKS_PRE_COMMIT`" == "false" ]
|
||||
then
|
||||
echo -e '\033[0;31m' checking git leaks is disabled - to enable: '\033[0;37m'git config --unset $GIT_LEAKS_PRE_COMMIT '\033[0m'
|
||||
echo -e '\033[0;34m' checking git leaks ... to enable: '\033[0;37m'git config --add $GIT_LEAKS_PRE_COMMIT true '\033[0m'
|
||||
else
|
||||
echo -e '\033[0;34m' checking for git leaks...
|
||||
[ -f "${GL_SCRIPT_PATH}" ] && . ${GL_SCRIPT_PATH} || echo "ERROR: Hook Script Not Found..." && exit 404
|
||||
fi
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
GL_SCRIPT_PATH="$HOME/.git_template/hooks/git-leaks.sh"
|
||||
|
||||
pushd `dirname $0` > /dev/null && cd ../.. && BASEDIR=$(pwd -L) && popd > /dev/null
|
||||
BASENAME=`basename $0`
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
#Initial commit : diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
GIT_LEAKS=hook.pre-push.gitleaks
|
||||
if [ "`git config $GIT_LEAKS`" == "false" ]
|
||||
then
|
||||
echo -e '\033[0;31m' checking git leaks is disabled - to enable: '\033[0;37m'git config --unset $GIT_LEAKS '\033[0m'
|
||||
echo -e '\033[0;34m' checking git leaks ... to enable: '\033[0;37m'git config --add $GIT_LEAKS true '\033[0m'
|
||||
else
|
||||
echo -e '\033[0;34m' checking for git leaks...
|
||||
[ -f "${GL_SCRIPT_PATH}" ] && . ${GL_SCRIPT_PATH} || echo "ERROR: Hook Script Not Found..." && exit 404
|
||||
fi
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#Function to check if package is installed or not
|
||||
#args: $1: Name of the Package
|
||||
function check_package_installed() {
|
||||
LOCAL_PACKAGE_NAME=$1
|
||||
echo "Checking if $LOCAL_PACKAGE_NAME is installed or not..."
|
||||
brew list $LOCAL_PACKAGE_NAME
|
||||
if [ "$?" -eq 1 ];then
|
||||
echo "Installing $LOCAL_PACKAGE_NAME package..."
|
||||
brew install $LOCAL_PACKAGE_NAME
|
||||
fi
|
||||
}
|
||||
|
||||
function create_git_template() {
|
||||
cd $BASEDIR
|
||||
mkdir -p ~/.git_template/hooks
|
||||
git config --global init.templatedir ${GIT_TEMPLATE}
|
||||
git config --global --add $GIT_LEAKS true
|
||||
git config --global --add $GIT_LEAKS_PRE_COMMIT true
|
||||
find hooks/ -type f -exec cp "{}" ~/.git_template/hooks \;
|
||||
#cp -f hooks/* ~/.git_template/hooks
|
||||
cat ~/.gitconfig
|
||||
}
|
||||
|
||||
GIT_TEMPLATE="~/.git_template"
|
||||
GIT_LEAKS=hook.pre-push.gitleaks
|
||||
GIT_LEAKS_PRE_COMMIT=hook.pre-commit.gitleaks
|
||||
|
||||
pushd `dirname $0` && BASEDIR=$(pwd -L) && popd
|
||||
|
||||
echo This script will install hooks that run scripts that could be updated without notice.
|
||||
|
||||
while true; do
|
||||
read -p "Do you wish to install these hooks?" yn
|
||||
case $yn in
|
||||
[Yy]* ) check_package_installed "gitleaks";
|
||||
break;;
|
||||
[Nn]* ) exit;;
|
||||
* ) echo "Please answer yes or no.";;
|
||||
esac
|
||||
done
|
||||
|
||||
create_git_template
|
||||
@@ -47,4 +47,4 @@ require (
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
go 1.22.0
|
||||
go 1.22.4
|
||||
|
||||
@@ -222,7 +222,7 @@ func (p Plugin) Exec() error {
|
||||
}
|
||||
|
||||
if p.Build.SnapshotMode != "" {
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--snapshotMode=%s", p.Build.SnapshotMode))
|
||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--snapshot-mode=%s", p.Build.SnapshotMode))
|
||||
}
|
||||
|
||||
if p.Build.EnableCache {
|
||||
|
||||
@@ -53,20 +53,3 @@ func TestConfig(t *testing.T) {
|
||||
assert.Equal(t, c.Auths, configFromFile.Auths)
|
||||
assert.Equal(t, c.CredHelpers, configFromFile.CredHelpers)
|
||||
}
|
||||
|
||||
func TestWriteDockerConfig(t *testing.T) {
|
||||
tempDir, err := ioutil.TempDir("", "docker-config-test")
|
||||
assert.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
data := []byte(`{"auths":{"https://index.docker.io/v1/":{"auth":"dGVzdDpwYXNzd29yZA=="}}}`)
|
||||
err = WriteDockerConfig(data, tempDir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
configPath := filepath.Join(tempDir, "config.json")
|
||||
_, err = os.Stat(configPath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = WriteDockerConfig(data, "/invalid/path")
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user