Skip to content

Commit

Permalink
I think it was still a bit overdesigned. Dropped some files to simpli…
Browse files Browse the repository at this point in the history
…fy it.
  • Loading branch information
mihxil committed Nov 17, 2024
1 parent 8520559 commit a13e1d0
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 92 deletions.
3 changes: 0 additions & 3 deletions kaniko.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
$(dirname "${BASH_SOURCE[0]}")/local-setup.sh
cat job.env

# REGISTRY: openshift-image-registry.apps.cluster.chp4.io.

#echo "Registry: ${REGISTRY}"
#KANIKO_IMAGE=npo-poms/kaniko
KANIKO_IMAGE=ghcr.io/npo-poms/kaniko:5

Expand Down
7 changes: 5 additions & 2 deletions local-maven.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash

$(dirname "${BASH_SOURCE[0]}")/local-setup.sh
DIR=$(dirname "${BASH_SOURCE[0]}")
KANIKO_SCRIPTS=$DIR/scripts/

. $DIR/local-setup.sh

cat job.env

KANIKO_SCRIPTS=$(dirname ${BASH_SOURCE[0]})/scripts/
. "$KANIKO_SCRIPTS"/script.sh
6 changes: 3 additions & 3 deletions scripts/dockerfile-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ os_app_name() {
echo "defining get_artifact_versions"

# exports PROJECT_VERSION, IMAGE_TAG, IMAGE, IMAGE_NAME
# first argument: directory containing the docker file
# second argument: version (exported as PROJECT_VERSION)
# $1: directory containing the docker file
# $2: version (exported as PROJECT_VERSION)
# the name of the image is determined with os_app_name
get_artifact_versions() {
get_docker_image_name() {
DIR=$1
export PROJECT_VERSION=$2
# gets name from docker file
Expand Down
40 changes: 40 additions & 0 deletions scripts/kaniko-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,39 @@ if ! type os_app_name &> /dev/null; then
. "$KANIKO_SCRIPTS"dockerfile-functions.sh
fi

# For a certain directory, calculate the docker image name, and run kaniko
# $1: the diretory to run for
package_docker() {
app_dir=$1
echo -e "----------\nPackaging ${TXT_HI}'$app_dir'${TXT_CLEAR} (pom version: $PROJECT_VERSION)"
get_docker_image_name $app_dir $PROJECT_VERSION # defined in docker.yml
kaniko_execute $app_dir
}


package_all_docker() {
if [ ! -z "$OS_APPLICATIONS" ] ; then
for app_dir in $(echo $OS_APPLICATIONS | sed "s/,/ /g"); do
package_docker $app_dir
done
echo Finished packaging $OS_APPLICATIONS
elif [ -f Dockerfile ]; then
echo "Packaging the root directory only"
package_docker .
else

echo "No Dockerfile and no OS_APPLICATIONS variable found"
OS_APPLICATIONS=$(find . -maxdepth 3 -mindepth 3 -name "*${PROJECT_VERSION}.war" -exec sh -c 'f=$(dirname $1); (cd $f/..; basename $PWD) ;' shell {} \; | tr '\n' ',' | sed 's/,$//')
if [ ! -z "$OS_APPLICATIONS" ] ; then
echo "Guessed OS_APPLICATIONS=$OS_APPLICATIONS"
package_wars
else
echo "Could not guess either for ${PROJECT_VERSION}"
fi
fi

}

# sets up kaniko, executes it in a dir, and stores some variables
# $1: directory to execute for
run_kaniko() {
Expand All @@ -19,6 +52,13 @@ run_kaniko() {
store_image_name
}

run_kaniko_all() {
echo "Using build args $DOCKER_BUILD_ARGS"
setup_kaniko "$DOCKER_AUTH_CONFIG_FILE"
package_all_docker
store_variables
}

# 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>',
Expand Down
27 changes: 0 additions & 27 deletions scripts/kaniko-gitlab-functions.sh

This file was deleted.

53 changes: 0 additions & 53 deletions scripts/kaniko-maven.sh

This file was deleted.

17 changes: 13 additions & 4 deletions scripts/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ if [ "$TRACE" = 'true' ]; then
set -x
fi

. "$KANIKO_SCRIPTS"kaniko-gitlab-functions.sh

. "$KANIKO_SCRIPTS"kaniko-maven.sh
if [ -f job.env ] ; then
echo "Found job.env!"
cat job.env
. ./job.env
else
echo "No job.env in $(pwd)"
fi


. "$KANIKO_SCRIPTS"kaniko-functions.sh


fun=$1
if [ "$fun" = "help" ] ;then
echo usage
echo $0 Run 'run_kaniko_maven' to deploy the war project of the current directory
echo $0 Default 'run_kaniko_all' to deploy all found docker deployables
echo or if OS_APPLICATIONS is defined in all the subdirectories it
exit
fi
if [ -z "$fun" ] ; then
fun="run_kaniko_maven"
fun="run_kaniko_all"
fi
$fun .

0 comments on commit a13e1d0

Please sign in to comment.