Last active
May 5, 2021 10:27
-
-
Save jmesnil/5136d57ae6f1cb711ce30cd08c17afcb to your computer and use it in GitHub Desktop.
Build an application image with WildFly S2I
This file contains hidden or 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
#!/bin/bash | |
################################################ | |
# Build an Application Image using WildFly S2I # | |
################################################ | |
echo " _ ___ __ __________ ________ ____"; | |
echo "| | / (_) /___/ / ____/ /_ __ / ___/__ \ / _/"; | |
echo "| | /| / / / / __ / /_ / / / / / \__ \__/ / / / "; | |
echo "| |/ |/ / / / /_/ / __/ / / /_/ / ___/ / __/_/ / "; | |
echo "|__/|__/_/_/\__,_/_/ /_/\__, / /____/____/___/ "; | |
echo " /____/ "; | |
echo | |
echo | |
echo | |
help() { | |
cli_name=${0##*/} | |
echo " | |
$cli_name | |
Usage: $cli_name build [<WildFly parameters>] <source location> <image name> [<s2i parameters>] | |
Where | |
* <WildFly parameters> are: | |
-v <WildFly S2I tag> | |
If omitted, the latest WildFly S2I images are used. | |
-l <Galleon Layers> | |
A list of comma-separated Galleon layers to provision | |
-f <Galleon Feature Packs> | |
A list of comma-separated Galleon Feature packs to use for provisioning. | |
Each feature pack is referenced by a Maven GAV coordinate | |
-g <Galleon Directory> | |
A directory containg Galleon configuration | |
-d | |
Display debug logs | |
* <source location> | |
The location of the application source (can be a local directory or a Git repository URL) | |
* <image name> | |
The name of the application image | |
* <s2i parameters> | |
Any additional parameters to pass to the s2i build commands (as documented in | |
https://github.com/openshift/source-to-image/blob/master/docs/cli.md#s2i-build) | |
" | |
exit 1 | |
} | |
build_artifacts_image() { | |
echo "Building artifact image ${build_artifacts_image}..." | |
S2I_ARGS=" -e GALLEON_PROVISION_DEFAULT_FAT_SERVER=true" | |
if [ "x$GALLEON_LAYERS" != "x" ]; then | |
echo " Galleon Layers: ${GALLEON_LAYERS}" | |
S2I_ARGS="$S2I_ARGS -e GALLEON_PROVISION_LAYERS=${GALLEON_LAYERS}" | |
fi | |
if [ "x$FEATURE_PACKS" != "x" ]; then | |
echo " Galleon Feature Packs: ${FEATURE_PACKS}" | |
S2I_ARGS="$S2I_ARGS -e GALLEON_PROVISION_FEATURE_PACKS=${FEATURE_PACKS}" | |
fi | |
if [ "x$GALLEON_DIR" != "x" ]; then | |
echo " Galleon Directory: ${GALLEON_DIR}" | |
S2I_ARGS="$S2I_ARGS -e GALLEON_DIR=${GALLEON_DIR}" | |
fi | |
s2i build $source \ | |
${builder_image} \ | |
${build_artifacts_image} \ | |
$S2I_ARGS $@ | |
echo "${build_artifacts_image} image is built" | |
} | |
build_runtime_image() { | |
echo "Building application image ${application_image}..." | |
docker_dir=$(mktemp -d) | |
docker_file=$docker_dir/Dockerfile | |
cat <<EOF > $docker_file | |
FROM ${runtime_image} | |
COPY --from=${build_artifacts_image}:latest /s2i-output/server \$JBOSS_HOME | |
USER root | |
RUN chown -R jboss:root \$JBOSS_HOME && chmod -R ug+rwX \$JBOSS_HOME | |
RUN ln -s \$JBOSS_HOME /wildfly | |
USER jboss | |
CMD \$JBOSS_HOME/bin/openshift-launch.sh | |
EOF | |
docker build -t $application_image $docker_dir | |
ret=$? | |
rm -rf $docker_dir | |
echo "${application_image} image is built" | |
echo "You can run if from Docker with:" | |
echo " docker run -p8080:8080 ${application_image}" | |
return $ret | |
} | |
case "$1" in | |
build) | |
shift | |
while getopts "v:l:f:g:d" OPTION; do | |
case $OPTION in | |
v) | |
VERSION=$OPTARG | |
;; | |
l) | |
GALLEON_LAYERS=$OPTARG | |
;; | |
f) | |
FEATURE_PACKS=$OPTARG | |
;; | |
g) | |
GALLEON_DIR=$OPTARG | |
;; | |
d) | |
set -x | |
;; | |
*) | |
echo "Incorrect options provided" | |
exit 1 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
if [ "x$VERSION" = "x" ]; then | |
VERSION="latest" | |
fi | |
echo "Building with $VERSION images for WildFly S2I" | |
builder_image=quay.io/wildfly/wildfly-centos7:${VERSION} | |
runtime_image=quay.io/wildfly/wildfly-runtime-centos7:${VERSION} | |
source=$1 | |
application_image=$2 | |
build_artifacts_image=${application_image}-build-artifacts | |
shift 2 | |
# build the artifacts image using S2I | |
build_artifacts_image $@ | |
# build the application image from the WildFly S2I runtime image | |
# and copy in it the artifacts | |
build_runtime_image | |
;; | |
*) | |
help | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment