mxbuild-docker
v0.1.19
Published
Mendix Build Docker Helper Tool
Downloads
6
Maintainers
Readme
mxbuild.docker
The MxBuild Docker helper utility consists of a CLI and Rest API interface for building MxBuild Dockers and Mendix Application Dockers. This tool focuses on Docker only, but uses the cloud foundry scripts provided by Mendix but is not only aimed at CF.
Quick Start - Dockerize Mendix App with pre-built MxBuild Docker
written for my good friend MO
Download a prebuilt Docker for the version of Mendix you want to support:
docker pull hgeldenhuys/mxbuild:6.10.10
Run the Docker Image:
docker run --rm --name=mx -v /homefolder/${MendixProjects}:/mx -p 3000:3000 -it hgeldenhuys/mxbuild:6.10.10
This is the server output:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. ## .-. .-..-. .-. .----. .-. .-..-..-. .----.
. ## ## == | `.' | \ \/ / | {} }| { } || || | | 🔧 \
. ## ## === | |\ /| | / /\ \ | {} }| {_} || || `--.| /
. /""""""""""""""""\___/ === `-' ` `-'`-' `-' `----' `-----'`-'`----'`----'
.🌊🌊{🌊🌊 🌊🌊🌊 🌊🌊🌊 🌊🌊/ == Docker Helper Utility v1.0.0 Copyright 2019
. \______ 👁 __/ By Herman Geldenhuys
. \ \ __/
. \____\______/
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
🌍 Server is running at http://[::1]:3000
For performance reasons it is recommended to share 1 or 2 volumes with your docker. The first one containing the SVN checkouts of your project and the second a shared cache of dependencies downloaded from Mendix' CDN servers. This helps save us some time.
The Rest API will be listening on port 3000
on the localhost and will look for Mendix source applications in /mx
Open your browser on port 3000:
Compile Mendix App
SVN Check out your Mendix Project into your ${MendixProjects}
folder - ${SVNFolder}
Note1: Be sure to duplicate ${SVNFolder}
to another folder if you intend on keeping the source
after compilation. Typically inside a CI pipeline where you might want to run your
integration test suite from the source folder. After compilation the SVN contents will
be lost
Click explorer
WARNING: this step replaces the SVN contents with a compiled version of the app. See Note 1
Select compile-mendix-app and enter the relative path to your ${SVNFolder}
and click Execute
or run this curl command:
http://localhost:3000/compile-mendix-app?sourceFolderPath=${SVNFolder}
Now your folder content contains the compiled app:
➜ 6.10.10 ls -l
total 96
drwxr-xr-x 3 mendix staff 96 29 Oct 17:18 bin
drwxr-xr-x 4 mendix staff 128 29 Oct 17:17 data
drwxr-xr-x 2 mendix staff 64 29 Oct 17:17 database
drwxr-xr-x 22 mendix staff 704 29 Oct 16:23 lib
drwxr-xr-x 2 mendix staff 64 29 Oct 17:17 log
drwxr-xr-x 8 mendix staff 256 29 Oct 17:16 model
drwxr-xr-x@ 6 mendix staff 192 26 Mar 2019 nginx
drwxr-xr-x 3 mendix staff 96 29 Oct 17:17 runtimes
-rw-r--r--@ 1 mendix staff 133 26 Mar 2019 sources.yml
-rwxr-xr-x 1 mendix staff 42495 29 Oct 17:18 start.py
drwxr-xr-x 22 mendix staff 704 29 Oct 17:16 web
Stage Docker dependencies
Move the ${SVNFolder}
to a sub-folder called project in your docker staging folder
aka ${DockerStagingFolder}
.:
➜ mkdir -p project
➜ mv ./* project/ 2> /dev/null
➜ ls -l
total 0
drwxr-xr-x 16 mendix staff 512 29 Oct 17:31 project
Now run the http://localhost:3000/stage-mendix-dockerfile API Rest end point, specifying the docker-staging-folder
,
image-name
and image-tag
. Specify the return-constants-defaults
if you want a
template of the project constants in JSON format for later use:
or this curl command:
curl -X GET "http://localhost:3000/stage-mendix-dockerfile?docker-staging-folder=`${DockerStagingFolder}`&image-name=${DockerImageName}&image-tag=latest&return-constants-defaults=false" -H "accept: */*"
This is the output server-side (given you are using a cache-path previously used):
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. ## .-. .-..-. .-. .----. .-. .-..-..-. .----.
. ## ## == | `.' | \ \/ / | {} }| { } || || | | 🔧 \
. ## ## === | |\ /| | / /\ \ | {} }| {_} || || `--.| /
. /""""""""""""""""\___/ === `-' ` `-'`-' `-' `----' `-----'`-'`----'`----'
.🌊🌊{🌊🌊 🌊🌊🌊 🌊🌊🌊 🌊🌊/ == Docker Helper Utility v1.0.0 Copyright 2019
. \______ 👁 __/ By Herman Geldenhuys
. \ \ __/
. \____\______/
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
🌍 Server is running at http://[::1]:3000
stage-mendix-docker-files --serve-verbose --deployment-folder="/mx/6.10.10" --json --cache-folder=/tmp/docker1 --name=myapp --tag=latest
🦑 already have MXBuild
🦑 already have Runtime
🦑 already have Mono
🦑 already have JDK
🦑 already have JRE
🐙 updating repo /tmp/docker1/buildpack...
In the browser this is your response JSON:
{
"runtimeVersion": "6.10.10",
"projectName": "6.10.10",
"buildContext": "/Users/mendix/Mendix/6.10.10",
"buildCommand": "docker build --no-cache -f Dockerfile.deploy -t myapp:latest .",
"runCommand": "docker run --rm -d -e ADMIN_PASSWORD={yourAdminPwd} -e CONSTANTS={yourEnvJson} -e DATABASE_ENDPOINT={yourJDBCString} [--link postgres:postgres] -p 8081:8081 -p 8080:8080 myapp:latest",
"hint": "Generate the Constants using this utility, and then store in a secret that transforms it at run into an environment variable argument."
}
Now you can cd to the buildContext
and execute the buildCommand
and then the
runCommand
as examples. Just replace the values in the variables between
curly braces with your own jdbc connection url, test constants or production constants
passed via a secret and link to other dockers as needed.
Microflow Constants
When you launch your Mendix Docker, your microflow constants are passed as a JSON string as an environment variable called CONSTANTS. The MxBuild utility also provides you with a handy way of converting an existing settings.yaml and extracting your constants in JSON.
Just point the Rest API to the settings.yaml or m2ee.yaml file and either return
the entire YAML or just the Constants section by setting the microflowConstantsOnly
to true
.
For example if you pointed your API to /somefolder/m2ee-tools-master/examples/m2ee.yaml
or used this curl command:
curl -X POST "http://localhost:3000/convert-yaml-to-json?path=%2Fsomefolder%2Fm2ee-tools-master%202%2Fexamples%2Fm2ee.yamlµflowConstantsOnly=true" -H "accept: */*"
the output would be:
{"Module.Constant": "text","AnotherModule.AnotherConstant": "bla"}
For example, running the previous run command:
docker run --rm -d -e ADMIN_PASSWORD=Complicated.Password1 -e CONSTANTS='{"Module.Constant": "text","AnotherModule.AnotherConstant": "bla"}' -e DATABASE_ENDPOINT=postgres://mendix:mendix@postgres:5432/mendix --link postgres:postgres -p 8081:8081 -p 8080:8080 myapp:latest"
Links
Supported Mendix Versions
- 6.10.10
- 6.10.18