-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
168 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ docker: | |
|
||
test: | ||
docker run -it --entrypoint /bin/sh npo-poms/kaniko | ||
|
||
source: | ||
export KANIKO_SCRIPTS=$(pwd)/scripts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
. $(dirname "${BASH_SOURCE[0]}")/local-setup.sh | ||
|
||
KANIKO_SCRIPTS=$(dirname ${BASH_SOURCE[0]})/scripts/ | ||
. "$KANIKO_SCRIPTS"/script.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Sets up some environment as gitlab would do. | ||
|
||
REGISTRY=${REGISTRY:-registry.npohosting.nl} | ||
NAMESPACE=${NAMESPACE:-poms} | ||
|
||
CI_COMMIT_REF_NAME="$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" | ||
PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | ||
echo "Found project version ${PROJECT_VERSION}" | ||
|
||
|
||
if [ "$IMAGE_TAG" = "" ] ; then # you can specify the image-tag by: IMAGE_TAG=.. kaniko.sh | ||
case $CI_COMMIT_REF_NAME in | ||
"main") | ||
IMAGE_TAG=dev | ||
;; | ||
*SNAPSHOT*) | ||
IMAGE_TAG=$(echo "${PROJECT_VERSION}-dev" | tr '[:upper:]' '[:lower:]') | ||
;; | ||
*) | ||
IMAGE_TAG=$(echo "${PROJECT_VERSION}" | tr '[:upper:]' '[:lower:]') | ||
;; | ||
esac | ||
fi | ||
|
||
echo "image tag $IMAGE_TAG" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
##!/bin/sh | ||
# This is the script can be used to build and push (via kaniko) an openshift statefull set. | ||
# This script used to be present in gitlab templates, but that's unmaintainble and unreusable | ||
# This can be used locally via run-in-docker.sh in a directory of interest | ||
|
||
|
||
# as /kaniko.sh but add some functions related to running in gitlab | ||
|
||
echo "kaniko gitlab functions" | ||
|
||
# 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 | ||
# I'm not sure this is very useful. You can just as wel call get_articaft_versions again in the next job | ||
# which will have the same effect, but I think this is robust, because no need for fiddling with 'need=<previous job>', | ||
# which is confusing and error-prone. | ||
store_image_version() { | ||
echo "IMAGE_TAG=$IMAGE_TAG" | tee job.env | ||
echo "IMAGE=$IMAGE" | tee -a job.env | ||
echo "IMAGE_NAME=$IMAGE_NAME" | tee -a job.env | ||
echo "FULL_IMAGE_NAME=$FULL_IMAGE_NAME" | tee -a job.env | ||
echo "PROJECT_VERSION=$PROJECT_VERSION" | tee -a job.env | ||
} | ||
|
||
echo "Define determine_image_version" | ||
# If store_image_version was called earlier in the pipeline, the the results of this are in job.env | ||
determine_image_version() { | ||
|
||
# used by plain docker builds | ||
if [ "$AS_LATEST" = 'true' ] ; then | ||
export LATEST="--destination $REGISTRY/$IMAGE_NAME" | ||
else | ||
export LATEST= | ||
fi | ||
|
||
if [ "$IMAGE_TAG" = '' ] ; then | ||
echo "No IMAGE_TAG defined. Breaking build. This must be defined in job rule!" | ||
exit 1 | ||
fi | ||
if [ "$IMAGE_NAME" = '' ] ; then | ||
echo "No IMAGE_NAME defined. Taking from os_app_name" | ||
IMAGE_NAME=$(os_app_name) | ||
export IMAGE_NAME | ||
fi | ||
export IMAGE=$REGISTRY/$IMAGE_NAME:$IMAGE_TAG | ||
echo "IMAGE: $IMAGE" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
##!/bin/sh | ||
# package found war file (or files using OS_APPLICATIONS) | ||
|
||
. /kaniko-gitlab.sh | ||
echo "Defining function package_applications" | ||
package_application() { | ||
if ! type kaniko_execute &> /dev/null ; then | ||
. "$KANIKO_SCRIPTS"kaniko-functions.sh | ||
fi | ||
|
||
echo "Defining function package_war(s)" | ||
|
||
package_war() { | ||
app_dir=$1 | ||
echo "Packaging '$app_dir' (pom version: $PROJECT_VERSION)" | ||
echo -e "----------\nPackaging ${EMP}'$app_dir'${NC} (pom version: $PROJECT_VERSION)" | ||
get_artifact_versions $app_dir $PROJECT_VERSION # defined in docker.yml | ||
ls -l $app_dir/target/*.war | ||
kaniko_execute $app_dir | ||
} | ||
package_application() { | ||
package_war "$@" | ||
} | ||
|
||
package_applications() { | ||
for app_dir in $(echo $OS_APPLICATIONS | sed "s/,/ /g"); do | ||
package_application $app_dir | ||
done | ||
if [ -z "$OS_APPLICATIONS" ]; then | ||
package_wars() { | ||
if [ ! -z "$OS_APPLICATIONS" ] ; then | ||
for app_dir in $(echo $OS_APPLICATIONS | sed "s/,/ /g"); do | ||
package_war $app_dir | ||
done | ||
echo Finished packaging $OS_APPLICATIONS | ||
elif [ ! -f Dockerfile ]; then | ||
echo "Packaging the root directory only" | ||
package_application . | ||
package_war . | ||
else | ||
echo "NOTHING to do. No Dockerfile and not OS_APPLICATIONS find" | ||
fi | ||
echo Finished packaging $OS_APPLICATIONS | ||
|
||
} | ||
|
||
package_applications() { | ||
package_wars "$@" | ||
} |
Oops, something went wrong.