[CI/CD] Automatic module imports at platform startup

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

1 Like

Direct approach

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


|- git-importspec.yaml

Spec File:

title: "Demo"
- name: "Demo"
  version: "5"
  git: "https://github.com/simplicitesoftware/module-demo"
- name: "DemoAPIs"
  version: "5"
  git: "https://github.com/simplicitesoftware/module-demo-apis"


sudo docker run -it --rm -p 8080:8080 -v "$(pwd)"/modules:/usr/local/tomcat/webapps/ROOT/WEB-INF/modules:ro registry.simplicite.io/platform:5-latest

Dockerfile approach

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

echo "========= SIMPLICITE DOCKER APP DELIVERY==========="

### ========== VARIABLES ==========

# declare the N module repositories **in the correct import order**
declare -a repositories=(

### ========== MODULE IMPORT ==========
echo "\n### Build modules & import specification from repositories"

rm -rf tmp && mkdir tmp && cd tmp

echo "title: \"$APP_NAME\"" >> $SPECFILE
echo "modules:" >> $SPECFILE

for r in "${repositories[@]}"
    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

# ========== 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