Skip to content

Commit

Permalink
using job.env if available.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Nov 16, 2024
1 parent 0662fec commit 22190e1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
1 change: 1 addition & 0 deletions kaniko.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ docker run -v ~/conf:/root/conf -v ~/.docker:/root/.docker -v "$(pwd)":/workspac
-e IMAGE_TAG=${IMAGE_TAG} \
-e NAMESPACE=${NAMESPACE} \
-e REGISTRY="${REGISTRY}" \
-e DOCKER_AUTH_CONFIG="/root/.docker/config-gitlab.json" \
-e CI_COMMIT_REF_NAME="${CI_COMMIT_REF_NAME}" \
-e CI_COMMIT_SHA="$(git show --format="%H" --no-patch)" \
-e CI_COMMIT_TIMESTAMP="$(git show --format="%aI" --no-patch)" \
Expand Down
2 changes: 1 addition & 1 deletion scripts/dockerfile-functions.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##!/bin/sh
echo "docker build setup $0"
echo "docker build setup"

TXT_HI="\e[93m" && TXT_CLEAR="\e[0m"

Expand Down
19 changes: 17 additions & 2 deletions scripts/kaniko-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ KANIKO_ARGS=${KANIKO_ARGS:-'--cache=true --cache-copy-layers=true'}
REGISTRY="${REGISTRY:-registry.npohosting.nl}"
NAMESPACE=${NAMESPACE:-poms}
DOCKER_BUILD_ARGS=${DOCKER_BUILD_ARGS:-} # Uses eval, when overriding escape whitespace: '--build-arg\ "FOO=BAR"'
DOCKER_AUTH_CONFIG_FILE=$HOME/.docker/config-gitlab.json


if ! type os_app_name &> /dev/null; then
Expand All @@ -14,12 +13,28 @@ fi
# param: directory to execute for
run_kaniko() {
echo "Using build args $DOCKER_BUILD_ARGS"
setup_kaniko "$DOCKER_AUTH_CONFIG_FILE"
setup_kaniko
kaniko_execute "$@"
store_image_version
}


echo "Defining function setup_kaniko"
# Just arranges authentication by copying the config.json file to right spot
setup_kaniko() {
mkdir -p /kaniko/.docker
incoming="$DOCKER_AUTH_CONFIG"
if [ -e "$incoming" ] ; then
echo "Copying $incoming to /kaniko/.docker/config.json"
echo "lines: $(wc -l $incoming)"
cp $incoming /kaniko/.docker/config.json
else
echo "No incoming docker configuration file '$incoming'"
fi
}



echo "Defining function kaniko_execute"
# $1: is the directory to run for, defaults to DOCKER_DIR
# $2: is a version to build defaults to PROJECT_VERSION
Expand Down
21 changes: 0 additions & 21 deletions scripts/kaniko-gitlab-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,11 @@ else
echo "No job.env in $(pwd)"
fi



# shellcheck source=${KANIKO_SCRIPTS}kaniko-functions.sh
if ! type os_app_name &> /dev/null ; then
. "$KANIKO_SCRIPTS"kaniko-functions.sh
fi

echo "Defining function setup_kaniko"
# Just arranges authentication by copying the config.json file to right spot
# $1 ~/.docker/config.json file. Defaults to DOCKER_AUTH_CONFIG
setup_kaniko() {
mkdir -p /kaniko/.docker
incoming="$1"
if [ -z "$incoming" ] ; then
echo "No incoming kaniko config file. Using $DOCKER_AUTH_CONFIG"
incoming="$DOCKER_AUTH_CONFIG"
fi
if [ -e "$incoming" ] ; then
echo "Copying $incoming to /kaniko/.docker/config.json"
echo "lines: $(wc -l $incoming)"
cp $incoming /kaniko/.docker/config.json
else
echo "No incoming docker configuration file '$incoming'"
fi
}



# Stores relevant variables determined by get_artifact_versions in job.env
Expand Down
1 change: 0 additions & 1 deletion scripts/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ if [ "$TRACE" = 'true' ]; then
set -x
fi

echo Using registry ${REGISTRY}
. "$KANIKO_SCRIPTS"kaniko-gitlab-functions.sh

. "$KANIKO_SCRIPTS"kaniko-maven.sh
Expand Down

0 comments on commit 22190e1

Please sign in to comment.