Skip to content

shelterbox/docker-mendix-buildpack

 
 

Repository files navigation

Docker Mendix Buildpack

Build Status

The Mendix Buildpack for Docker (aka docker-mendix-buildpack) provides a standard way to build and run your Mendix Application in a Docker container.

Try a sample mendix application

Open a terminal and run the following code:

Important note: always provide <TAG> value to guarantee consistent builds. List of tags is available here.

git clone --branch <TAG> --config core.autocrlf=false https://github.com/mendix/docker-mendix-buildpack
cd docker-mendix-buildpack
make get-sample
make build-image
make run-container

You can now open your browser http://localhost:8080

Uses cases scenarios:

This project is a goto reference for the following scenarios :

  1. Build and run a Mendix Application on your own docker set up
  2. Build the Docker Image of your Mendix application, push to a container repository and run it.

Getting started

Requirements

  • Docker (Installation here)
  • For preparing, a local installation of wget (for macOS)
  • For local testing, make sure you can run the docker-compose command

Usage

Compilation

Before running the container, it is necessary to build the image with your application. This buildpack contains Dockerfile with a script that will compile your application using cf-mendix-buildpack.

docker build 
  --build-arg BUILD_PATH=<mendix-project-location> \
  --build-arg ROOTFS_IMAGE=<root-fs-image-tag> \
  --build-arg CF_BUILDPACK=<cf-buildpack-version> \
  --tag mendix/mendix-buildpack:v1.2 .

For build you can provide next arguments:

  • BUILD_PATH indicates where the application model is located. It is a root directory of an unzipped .MDA or .MPK file. In the latter case, this is the directory where your .MPR file is located. Must be within build context. Defaults to ./project.
  • ROOTFS_IMAGE is a version of CloudFoundry buildpack. Defaults to mendix/rootfs:bionic. To use Ubuntu 14.04, change this to mendix/rootfs:trusty. It's also possible to use a custom rootfs image as described in Advanced feature: full-build.
  • CF_BUILDPACK is a version of CloudFoundry buildpack. Defaults to master. For stable pipelines, it's recommended to use a fixed version from v3.7.0 and later.

Startup

To start the container, it is required to provide the container with the password to create an administrative account of your mendix application ADMIN_PASSWORD and the DATABASE_ENDPOINT as you can see in the example below:

docker run -it \
  -e ADMIN_PASSWORD=Password1! \
  -e DATABASE_ENDPOINT=postgres://username:password@host:port/mendix \
  mendix/mendix-buildpack:v1.2  

or for Microsoft SQL server

docker run -it \
  -e ADMIN_PASSWORD=Password1! \
  -e DATABASE_ENDPOINT=sqlserver://username:password@host:port/mendix \
  mendix/mendix-buildpack:v1.2  

Alternative ways to configure database connection:

  • DATABASE_URL environment variable
docker run -it \
  -e ADMIN_PASSWORD=Password1! \
  -e DATABASE_URL=sqlserver://username:password@host:port/mendix \
  mendix/mendix-buildpack:v1.2  
// full config
docker run -it \
  -e ADMIN_PASSWORD=Password1! \
  -e MXRUNTIME_DatabaseType=MYSQL \
  -e MXRUNTIME_DatabaseUserName=mendix \
  -e MXRUNTIME_DatabasePassword=mendix \
  -e MXRUNTIME_DatabaseName=mendix \
  -e MXRUNTIME_DatabaseHost=host:port \
  mendix/mendix-buildpack:v1.2  

// config with jdbc url
docker run -it \
  -e ADMIN_PASSWORD=Password1! \
  -e MXRUNTIME_DatabaseType=MYSQL \
  -e MXRUNTIME_DatabaseUserName=mendix \
  -e MXRUNTIME_DatabasePassword=mendix \
  -e MXRUNTIME_DatabaseJdbcUrl=mysql://db:3306/mendix \
  -e MXRUNTIME_DatabaseName=mendix \
  mendix/mendix-buildpack:v1.2  

Features

This project uses the same base technology that Mendix uses to run the application in Cloud Foundry (the mendix cloudfoundry buildpack).

  • Compilation of a Mendix application from project sources
  • Automatic generation of the configuration (m2ee.yaml)
  • Startup of the application when the container is spin up
  • Configured nginx as the reverse proxy

Current limitations

  • PostgreSQL and SQLSERVER database supported
  • This setup will use a trial license for your application by default

Enabling License

If you wish to start your application with a non-trial license, please provide the additional environment variables:

  • LICENSE_ID
  • LICENSE_KEY

example:

docker run -it \
  -p 8080:80 \
  -e ADMIN_PASSWORD=Password1! \
  -e DATABASE_ENDPOINT=postgres://mendix:mendix@172.17.0.2:5432/mendix \
  -e LICENSE_ID=<UUID> \
  -e LICENSE_KEY=<LICENSE_KEY> \
  mendix/mendix-buildpack:v1.2  

Passing environment variables to your Mendix runtime

The default values for constants will be used as defined in your project. However, you can override them with environment variables. You need to replace the dot with an underscore and prefix it with MX_. So a constant like Module. Constant with value ABC123 could be set like this:

example:

docker run -it \
  -p 8080:80 \
  -e ADMIN_PASSWORD=Password1! \
  -e DATABASE_ENDPOINT=postgres://mendix:mendix@172.17.0.2:5432/mendix \
  -e MX_Module_Constant=ABC123 \
  -e LICENSE_ID=<UUID> \
  -e LICENSE_KEY=<LICENSE_KEY> \
  mendix/mendix-buildpack:v1.2  

Two ways to pass multi-line environment variable:

  1. Command line - when docker run executed, it's possible to pass multi-line value with double quotes
docker run -it \
  -e CERTIFICATE_AUTHORITIES="-----BEGIN CERTIFICATE-----
                MIIGejCCBGKgAwIBAgIJANuKwREDEb4sMA0GCSqGSIb3DQEBCwUAMIGEMQswCQYD
                VQQGEwJOTDEVMBMGA1UECBMMWnVpZC1Ib2xsYW5kMRIwEAYDVQQHEwlSb3R0ZXJk
                YW0xDzANBgNVBAoTBk1lbmRpeDEXMBUGA1UEAxMOTWVuZGl4IENBIC0gRzIxIDAe..."
  1. Docker-compose - special prefix can be used
environment:
    CERTIFICATE_AUTHORITIES: |-
                -----BEGIN CERTIFICATE-----
                MIIGejCCBGKgAwIBAgIJANuKwREDEb4sM....

Requested a test scenario from Jouke and Xiwen, meanwhile will update docker-buildpack documentation.

Configuring Custom Runtime Settings

To configure any of the advanced Custom Runtime Settings you can use setting name prefixed with MXRUNTIME_ as an environment variable.

For example, to configure the ConnectionPoolingMinIdle setting to value 10, you can set the following environment variable:

Example:

docker run -it \
  -p 8080:80 \
  -e ADMIN_PASSWORD=Password1! \
  -e DATABASE_ENDPOINT=postgres://mendix:mendix@172.17.0.2:5432/mendix \
  -e MXRUNTIME_ConnectionPoolingMinIdle 10 \
  mendix/mendix-buildpack:v1.2  

If the setting contains a dot . you can use an underscore _ in the environment variable. So to set com.mendix.storage.s3.EndPoint to foo you can use:

MXRUNTIME_com_mendix_storage_s3_EndPoint foo

Configuring Enabled Scheduled Events

The scheduled events can be configured using environment variable SCHEDULED_EVENTS.

Possible values are ALL, NONE or a comma separated list of the scheduled events that you would like to enable. For example: ModuleA.ScheduledEvent.ModuleB.OtherScheduledEvent

An example in a docker run command:

docker run -it \
  -p 8080:80 \
  -e ADMIN_PASSWORD=Password1! \
  -e DATABASE_ENDPOINT=postgres://mendix:mendix@172.17.0.2:5432/mendix \
  -e SCHEDULED_EVENTS=ALL \
  mendix/mendix-buildpack:v1.2  

Configuring Application log levels

Configuring log levels happens by adding one or more environment variables starting with the name LOGGING_CONFIG (the part of the name after that is not relevant and only used to distinguish between multiple entries if necessary). Its value should be valid JSON, in the format:

{
  "LOGNODE": "LEVEL"
}

You can see the available Log Nodes in your application in the Mendix Modeler. The level should be one of:

  • CRITICAL
  • ERROR
  • WARNING
  • INFO
  • DEBUG
  • TRACE

Example:

docker run -it \
  -p 8080:80 \
  -e ADMIN_PASSWORD=Password1! \
  -e DATABASE_ENDPOINT=postgres://mendix:mendix@172.17.0.2:5432/mendix \
  -e LOGGING_CONFIG='{"Core": "DEBUG"}' \
  mendix/mendix-buildpack:v1.2  

Monitoring the runtime

The admin interface can be used to measure the health of the Runtime as per documentation. The password of the admin port can be set using the environment variable M2EE_PASSWORD. The standard username is MxAdmin. The interface is exposed to the outside world on the url /_mxadmin/ and can be accessed by using basic HTTP authentication. Refer to the documentation to learn how to use this interface.

To clarify:

  • the HTTP basic authentication credentials are: MxAdmin / [M2EE_PASSWORD] .
  • the X-M2EE-Authentication header contains a base64-encoded version of [M2EE_PASSWORD] .

Health check

The docker compose files, in the /test folder, contain an example how to perform a healtcheck on a Mendix app:

healthcheck:
            test: ["CMD", "curl", "-f", "http://localhost"]
            interval: 15s
            retries: 2
            start_period: 10s
            timeout: 3s

The health check monitors the status of the Mendix container, but it does not autoheal or restarts the container in case of unhealthy status, relying on the Docker runtime to perform the aforementioned task. For instance, Kubernetes is in charge to restart the unhealthy containers, but reporting their status it is a responsibility of the containers themselves. For a Kubernetes example, please follow this link.

For further information, the official documentation here.

Certificate Management

Certificate Authorities (CAs) can be managed using the CERTIFICATE_AUTHORITIES environment variable, see the upstream Cloud Foundry Build Pack documentation.

In case your environment does not support multi-line environment variables, a Base64-encoded string containing the desired CA Certificates can be used alternatively.

This string should be set into the CERTIFICATE_AUTHORITIES_BASE64 environment variable.

Advanced feature: full-build

To save build time, the build pack will normally use a pre-built rootfs from Docker Hub. This rootfs is prepared nightly by Mendix using this Dockerfile. If you want to build the root-fs yourself you can use the following script:

docker build --build-arg BUILD_PATH=<mendix-project-location> \
	-t <root-fs-image-tag> -f Dockerfile.rootfs.bionic .

After that you can build the target image with the next command:

docker build 
  --build-arg BUILD_PATH=<mendix-project-location> \
  --build-arg ROOTFS_IMAGE=<root-fs-image-tag> \
	-t mendix/mendix-buildpack:v1.2 .

Contributions

Contributions are welcomed:

  1. open an issue about your topic
  2. fork, make a branch named starting with the issue number you are resolving (see here) and make a pull request to the master branch
  3. please add some tests for feature changes

Build Details

This was built with the following:

  • Docker version 1.12.6

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the Apache License v2 (for details, see the LICENSE file).

Packages

No packages published

Languages

  • Python 45.7%
  • Dockerfile 23.1%
  • Shell 18.9%
  • Makefile 12.3%