Skip to content

Instantly share code, notes, and snippets.

@tieniber
Created July 23, 2020 22:26
Show Gist options
  • Save tieniber/1e206fa664481d90a88f36bdcf563e5d to your computer and use it in GitHub Desktop.
Save tieniber/1e206fa664481d90a88f36bdcf563e5d to your computer and use it in GitHub Desktop.
Mendix docker multistage build for mxclyde
# Dockerfile to create a Mendix Docker image based on either the source code or
# Mendix Deployment Archive (aka mda file)
#
# Author: Mendix Digital Ecosystems, digitalecosystems@mendix.com
# Version: 2.0.0
ARG ROOTFS_IMAGE=mxclyde/rootfs:bionic
FROM ${ROOTFS_IMAGE} as builder
LABEL Author="Mendix Digital Ecosystems"
LABEL maintainer="digitalecosystems@mendix.com"
# Build-time variables
ARG BUILD_PATH=project
ARG DD_API_KEY
# CF buildpack version
ARG CF_BUILDPACK=telegrafext-nonroot
ARG APPMETRICS_AAI
ARG APPMETRICS_TARGET
ARG APPMETRICS_PROMETHEUS
ARG APPMETRICS_GRAYLOG
# Each comment corresponds to the script line:
# 1. Install libpng12 backported from Xenial (required by Mono)
# 2. Create all directories needed by scripts
# 3. Create all directories needed by CF buildpack
# 4. Create symlink for java prefs used by CF buildpack
# 5. Download CF buildpack
RUN wget https://mxblobstore.azureedge.net/mxblobstore/libpng12-0_1.2.54-1ubuntu1.1_amd64.deb &&\
dpkg -i libpng12-0_1.2.54-1ubuntu1.1_amd64.deb &&\
mkdir -p buildpack build cache \
"/.java/.userPrefs/com/mendix/core" "/root/.java/.userPrefs/com/mendix/core" &&\
ln -s "/.java/.userPrefs/com/mendix/core/prefs.xml" "/root/.java/.userPrefs/com/mendix/core/prefs.xml" &&\
echo "CF Buildpack version ${CF_BUILDPACK}" &&\
wget -qO- https://github.com/mxclyde/cf-mendix-buildpack/archive/${CF_BUILDPACK}.tar.gz | tar xvz -C buildpack --strip-components 1
# Copy python scripts which execute the buildpack (exporting the VCAP variables)
COPY scripts/compilation /buildpack
# Copy project model/sources
COPY $BUILD_PATH build
# Add the buildpack modules
ENV PYTHONPATH "/buildpack/lib/"
# Each comment corresponds to the script line:
# 1. Call compilation script
# 2. Remove temporary folders
# 3. Create mendix user with home directory at /root
# 4. Change ownership of /build /buildpack /.java /root to mendix
WORKDIR /buildpack
RUN "/buildpack/compilation" /build /cache &&\
rm -fr /cache /tmp/javasdk /tmp/opt &&\
rm -fr /build/.local/usr/lib/jvm/AdoptOpenJDK-jdk* &&\
rm -fr /build/.local/usr/lib/jvm/jdk*
# Copy start scripts
COPY scripts/startup /build
COPY scripts/vcap_application.json /build
#Make the final container
FROM ${ROOTFS_IMAGE}
LABEL Author="Mendix Digital Ecosystems"
LABEL maintainer="digitalecosystems@mendix.com"
RUN useradd -r -U -u 1050 -d /root mendix &&\
chown -R mendix:mendix /root
COPY --from=builder --chown=mendix:mendix /build /build
COPY --from=builder --chown=mendix:mendix /buildpack /buildpack
COPY --from=builder --chown=mendix:mendix /.java /.java
COPY --from=builder --chown=mendix:mendix /root/.java /root/.java
WORKDIR /build
USER 1050
# Expose nginx port
ENV PORT 8080
EXPOSE $PORT
ENTRYPOINT ["/build/startup","/buildpack/start.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment