As of version 5.1.6, a new delivery method is offered by the platform, as documented here. It allows to pass a specification file telling the platform to import modules at startup. In a docker context, the file can be bind-mounted or inserted in a new image with the help of a dockerfile. Conveniently, the specification file:
can point to:
zip modules on the filesystem (eg: bind-mounted or inserted like the spec),
zip modules on the network
git repositories
specifies a version for the module, triggering the import if it is superior the the version present in the database
This tutorial will show how to build/run a docker image with this mechanism
In this scenario, we only mount a modules directory containing a spec file refering git repositories. At startup, the platform will proceed to import the modules
The spec is located in a directory on the host machine, and contains what follows
Instead of making the platform use some distant repositories, this method builds a custom docker image based on the Simplicité image, containing modules downloaded from a git repository and an automatically generated spec file.
NB: the same spec / zip files generation technique can be use to bind-mount a volume with the files from the repositories without having to generate a new docker image
#!/bin/sh
echo "========= SIMPLICITE DOCKER APP DELIVERY==========="
### ========== VARIABLES ==========
APP_NAME="Demo"
TARGET_SIMPLICITE_IMAGE="5-latest"
# declare the N module repositories **in the correct import order**
declare -a repositories=(
"https://github.com/simplicitesoftware/module-demo",
"https://github.com/simplicitesoftware/module-demo-apis"
)
### ========== MODULE IMPORT ==========
echo "\n### Build modules & import specification from repositories"
rm -rf tmp && mkdir tmp && cd tmp
SPECFILE=$APP_NAME"-importspec.yaml"
echo "title: \"$APP_NAME\"" >> $SPECFILE
echo "modules:" >> $SPECFILE
REPO_DIR="repo"
for r in "${repositories[@]}"
do
echo "Generate zip from $r"
git clone -q "$r" $REPO_DIR
cd $REPO_DIR
# Infer module name & version from module descriptor
MODULE_NAME="$(cat module-info.json | jq -r .name)"
MODULE_VERSION="$(cat module-info.json | jq -r .version)"
# export module as zip format
zip -q -x\.git -r "../"$MODULE_NAME".zip" *
cd ..
rm -rf $REPO_DIR
echo "- name: \"$MODULE_NAME\"" >> $SPECFILE
echo " version: \"$MODULE_VERSION\"" >> $SPECFILE
done
# ========== BUILD DOCKER ==========
echo "\n### Create Dockerfile"
echo "FROM registry.simplicite.io/platform:$TARGET_SIMPLICITE_IMAGE" >> Dockerfile
echo "COPY $SPECFILE /usr/local/tomcat/webapps/ROOT/WEB-INF/modules/" >> Dockerfile
echo "COPY *.zip /usr/local/tomcat/webapps/ROOT/WEB-INF/modules/" >> Dockerfile
cd ..
echo "\n### Build docker image"
docker build --pull ./tmp -t demosimplicite
rm -rf tmp
# ========== RUN ==========
echo "\n### Run\n"
sudo docker run -it --rm --name demosimplicite -p 80:8080 demosimplicite