Skip to content

Commit 82b0539

Browse files
authored
Merge pull request #122 from mendix/DES-3187_upgrade-cf-buildpack
DES-3187 Docker Buildpack improvements
2 parents dee9948 + 9346d41 commit 82b0539

8 files changed

+30
-45
lines changed

Dockerfile

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ FROM ${BUILDER_ROOTFS_IMAGE} AS builder
1313
ARG BUILD_PATH=project
1414
ARG DD_API_KEY
1515
# CF buildpack version
16-
ARG CF_BUILDPACK=v4.15.4
16+
ARG CF_BUILDPACK=v4.17.1
1717
# CF buildpack download URL
1818
ARG CF_BUILDPACK_URL=https://github.com/mendix/cf-mendix-buildpack/releases/download/${CF_BUILDPACK}/cf-mendix-buildpack.zip
1919

@@ -24,6 +24,9 @@ ARG EXCLUDE_LOGFILTER=true
2424
ARG BLOBSTORE
2525
ARG BUILDPACK_XTRACE
2626

27+
# Set the user ID
28+
ARG USER_UID=1001
29+
2730
# Each comment corresponds to the script line:
2831
# 1. Create all directories needed by scripts
2932
# 2. Download CF buildpack
@@ -36,7 +39,7 @@ RUN mkdir -p /opt/mendix/buildpack /opt/mendix/build &&\
3639
curl -fsSL ${CF_BUILDPACK_URL} -o /tmp/cf-mendix-buildpack.zip && \
3740
python3 -m zipfile -e /tmp/cf-mendix-buildpack.zip /opt/mendix/buildpack/ &&\
3841
rm /tmp/cf-mendix-buildpack.zip &&\
39-
chgrp -R 0 /opt/mendix &&\
42+
chown -R ${USER_UID}:0 /opt/mendix &&\
4043
chmod -R g=u /opt/mendix
4144

4245
# Copy python scripts which execute the buildpack (exporting the VCAP variables)
@@ -69,7 +72,7 @@ RUN mkdir -p /tmp/buildcache /var/mendix/build /var/mendix/build/.local &&\
6972
./compilation /opt/mendix/build /tmp/buildcache &&\
7073
rm -fr /tmp/buildcache /tmp/javasdk /tmp/opt /tmp/downloads /opt/mendix/buildpack/compilation /opt/mendix/buildpack/git &&\
7174
ln -s /opt/mendix/.java /opt/mendix/build &&\
72-
chgrp -R 0 /opt/mendix /var/mendix &&\
75+
chown -R ${USER_UID}:0 /opt/mendix /var/mendix &&\
7376
chmod -R g=u /opt/mendix /var/mendix
7477

7578
FROM ${ROOTFS_IMAGE}
@@ -79,8 +82,14 @@ LABEL maintainer="[email protected]"
7982
# Uninstall build-time dependencies to remove potentially vulnerable libraries
8083
ARG UNINSTALL_BUILD_DEPENDENCIES=true
8184

82-
# Allow the root group to modify /etc/passwd so that the startup script can update the non-root uid
83-
RUN chmod g=u /etc/passwd
85+
# Set the user ID
86+
ARG USER_UID=1001
87+
# Set the home path
88+
ENV HOME=/opt/mendix/build
89+
90+
# Allow the user group to modify /etc/passwd so that OpenShift 3 randomized UIDs are supported by CF Buildpack
91+
RUN chmod g=u /etc/passwd &&\
92+
chown ${USER_UID}:0 /etc/passwd
8493

8594
# Uninstall Ubuntu packages which are only required during build time
8695
RUN if [ "$UNINSTALL_BUILD_DEPENDENCIES" = "true" ] && grep -q ubuntu /etc/os-release ; then\
@@ -96,16 +105,20 @@ COPY scripts/startup scripts/vcap_application.json /opt/mendix/build/
96105

97106
# Create vcap home directory for Datadog configuration
98107
RUN mkdir -p /home/vcap &&\
99-
chgrp -R 0 /home/vcap &&\
108+
chown -R ${USER_UID}:0 /home/vcap &&\
100109
chmod -R g=u /home/vcap
101110

102111
# Each comment corresponds to the script line:
103112
# 1. Make the startup script executable
104113
# 2. Update ownership of /opt/mendix so that the app can run as a non-root user
105114
# 3. Update permissions of /opt/mendix so that the app can run as a non-root user
115+
# 4. Ensure that running Java 8 as root will still be able to load offline licenses
106116
RUN chmod +rx /opt/mendix/build/startup &&\
107-
chgrp -R 0 /opt/mendix &&\
108-
chmod -R g=u /opt/mendix
117+
chown -R ${USER_UID}:0 /opt/mendix &&\
118+
chmod -R g=u /opt/mendix &&\
119+
ln -s /opt/mendix/.java /root
120+
121+
USER ${USER_UID}
109122

110123
# Copy jre from build container
111124
COPY --from=builder /var/mendix/build/.local/usr /opt/mendix/build/.local/usr
@@ -121,10 +134,6 @@ ENV NGINX_CUSTOM_BIN_PATH=/usr/sbin/nginx
121134

122135
WORKDIR /opt/mendix/build
123136

124-
USER 1001
125-
126-
ENV HOME "/opt/mendix/build"
127-
128137
# Expose nginx port
129138
ENV PORT 8080
130139
EXPOSE $PORT

Dockerfile.rootfs.bionic

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ENV LC_ALL en_US.UTF-8
1919

2020
# Set nginx permissions
2121
RUN touch /run/nginx.pid && \
22-
chgrp -R 0 /var/log/nginx /var/lib/nginx /run/nginx.pid &&\
22+
chown -R 1001:0 /var/log/nginx /var/lib/nginx /run/nginx.pid &&\
2323
chmod -R g=u /var/log/nginx /var/lib/nginx /run/nginx.pid
2424

2525
# Set python alias to python3 (required for Datadog)

Dockerfile.rootfs.ubi8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RUN dnf update -y && \
1818

1919
# Set nginx permissions
2020
RUN touch /run/nginx.pid && \
21-
chgrp -R 0 /run/nginx.pid &&\
21+
chown -R 1001:0 /run/nginx.pid &&\
2222
chmod -R g=u /run/nginx.pid
2323

2424
# Set python alias to python3 (required for Datadog)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ For build you can provide next arguments:
5757
- **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](https://docs.docker.com/engine/reference/commandline/build/#extended-description). Defaults to `./project`.
5858
- **ROOTFS_IMAGE** is a type of rootfs image. Defaults to `mendix/rootfs:ubi8` (Red Hat Universal Base Image 8). To use Ubuntu 18.04, change this to `mendix/rootfs:bionic`. It's also possible to use a custom rootfs image as described in [Advanced feature: full-build](#advanced-feature-full-build).
5959
- **BUILDER_ROOTFS_IMAGE** is a type of rootfs image used for downloading the Mendix app dependencies and compiling the Mendix app from source. Defaults to `mendix/rootfs:bionic`. It's also possible to use a custom rootfs image as described in [Advanced feature: full-build](#advanced-feature-full-build).
60-
- **CF_BUILDPACK** is a version of CloudFoundry buildpack. Defaults to `v4.15.4`. For stable pipelines, it's recommended to use a fixed version from **v4.15.4** and later. CloudFoundry buildpack versions below **v4.15.4** are not supported.
60+
- **CF_BUILDPACK** is a version of CloudFoundry buildpack. Defaults to `v4.17.1`. For stable pipelines, it's recommended to use a fixed version from **v4.17.1** and later. CloudFoundry buildpack versions below **v4.17.1** are not supported.
6161
- **EXCLUDE_LOGFILTER** will exclude the `mendix-logfilter` binary from the resulting Docker image if set to `true`. Defaults to `true`. Excluding `mendix-logfilter` will reduce the image size and remove a component that's not commonly used; the `LOG_RATELIMIT` environment variable option will be disabled.
6262
- **UNINSTALL_BUILD_DEPENDENCIES** will uninstall packages which are not needed to launch an app, and are only used during the build phase. Defaults to `true`. This option will remove several libraries which are known to have unpatched CVE vulnerabilities.
6363
- **CF_BUILDPACK_URL** specifies the URL where the CF buildpack should be downloaded from (for example, a local mirror). Defaults to `https://github.com/mendix/cf-mendix-buildpack/releases/download/${CF_BUILDPACK}/cf-mendix-buildpack.zip`. Specifying **CF_BUILDPACK_URL** will override the version from **CF_BUILDPACK**.

cf-buildpack.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v4.15.4
1+
v4.17.1

scripts/cleanupjdk

Lines changed: 0 additions & 15 deletions
This file was deleted.

scripts/compilation

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,6 @@ def call_buildpack_compilation():
3636
logging.debug("Executing call_buildpack_compilation...")
3737
return subprocess.check_call(["/opt/mendix/buildpack/buildpack/stage.py", BUILD_PATH, CACHE_PATH])
3838

39-
def remove_jdk():
40-
logging.info("Removing JDK...")
41-
runtime.get_version(BUILD_PATH)
42-
43-
jdk = java.determine_jdk(runtime.get_java_version(runtime.get_version(BUILD_PATH)), 'jdk')
44-
jdk_path = os.path.join(DOT_LOCAL_LOCATION, java.compose_jvm_target_dir(jdk))
45-
if os.path.exists(jdk_path):
46-
shutil.rmtree(jdk_path, ignore_errors=False)
47-
4839
def fix_logfilter():
4940
exclude_logfilter = os.getenv("EXCLUDE_LOGFILTER", "true").lower() == "true"
5041
if exclude_logfilter:
@@ -74,7 +65,5 @@ if __name__ == '__main__':
7465
exit_code = call_buildpack_compilation()
7566
if exit_code != 0:
7667
sys.exit(exit_code)
77-
remove_jdk()
7868
fix_logfilter()
7969
make_dependencies_reusable()
80-

scripts/startup

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
import logging
44
import os
5-
import pwd
65
import re
76
import subprocess
87
import signal
@@ -106,12 +105,15 @@ def call_buildpack_startup():
106105

107106
signal.signal(signal.SIGTERM, sig_forwarder)
108107

109-
proc.wait()
108+
try:
109+
proc.wait()
110+
except KeyboardInterrupt:
111+
logging.debug("Interrupted by keyboard")
110112

111113
def add_uid():
112114
logging.info("Adding uid to /etc/passwd")
113115
with open('/etc/passwd','a') as passwd_file:
114-
passwd_file.write('mendix:x:{uid}:0:mendix user:/opt/mendix/build:/sbin/nologin\n'.format(uid=os.getuid()))
116+
passwd_file.write('mendix:x:{uid}:{gid}:mendix user:/opt/mendix/build:/sbin/nologin\n'.format(uid=os.getuid(),gid=os.getgid()))
115117

116118
def get_welcome_header():
117119
welcome_ascii_header = '''

0 commit comments

Comments
 (0)