|
| 1 | +# syntax=docker/dockerfile:1.7-labs |
| 2 | + |
| 3 | +# Stages: |
| 4 | +# 1. Builder Stage: Compiles the application and resolves dependencies. Produces |
| 5 | +# JAR files that can be deployed. |
| 6 | +# 1a. Install dependencies |
| 7 | +# 1b. Build the application |
| 8 | +# 2. Runner Stage: Creates a lightweight image that runs the application using the JRE. |
| 9 | + |
| 10 | +FROM ubuntu:noble-20250415.1 AS builder |
| 11 | +WORKDIR /app |
| 12 | +# sdkman requires bash |
| 13 | +SHELL ["/bin/bash", "-c"] |
| 14 | + |
| 15 | +# Stage 1a: Install dependencies |
| 16 | +# Install necessary tools |
| 17 | +COPY .sdkmanrc . |
| 18 | +RUN apt-get update\ |
| 19 | + && apt-get install -y zip curl\ |
| 20 | + && curl -s "https://get.sdkman.io?ci=true" | bash \ |
| 21 | + && source "$HOME/.sdkman/bin/sdkman-init.sh" && sdk env install \ |
| 22 | + && rm -rf /var/lib/apt/lists/* |
| 23 | + |
| 24 | +# Stage 1b: Build the application |
| 25 | +# Copy the entire source tree (excluding .dockerignore files), and build |
| 26 | +COPY --exclude=docker . . |
| 27 | +WORKDIR /app/server |
| 28 | +RUN source "$HOME/.sdkman/bin/sdkman-init.sh" \ |
| 29 | + && ANT_OPTS="-Dfile.encoding=UTF8" ant -f mirth-build.xml -DdisableSigning=true |
| 30 | + |
| 31 | +# Stage 2b: JDK runtime container |
| 32 | +FROM eclipse-temurin:21.0.7_6-jdk-noble as jdk-run |
| 33 | + |
| 34 | +RUN groupadd mirth \ |
| 35 | + && usermod -l mirth ubuntu \ |
| 36 | + && adduser mirth mirth \ |
| 37 | + && mkdir -p /opt/connect/appdata \ |
| 38 | + && chown -R mirth:mirth /opt/connect |
| 39 | + |
| 40 | +WORKDIR /opt/connect |
| 41 | +COPY --chown=mirth:mirth --from=builder \ |
| 42 | + --exclude=cli-lib \ |
| 43 | + --exclude=mirth-cli-launcher.jar \ |
| 44 | + --exclude=mccommand \ |
| 45 | + --exclude=manager-lib \ |
| 46 | + --exclude=mirth-manager-launcher.jar \ |
| 47 | + --exclude=mcmanager \ |
| 48 | + /app/server/setup ./ |
| 49 | + |
| 50 | +VOLUME /opt/connect/appdata |
| 51 | +VOLUME /opt/connect/custom-extensions |
| 52 | +EXPOSE 8443 |
| 53 | + |
| 54 | +USER mirth |
| 55 | +ENTRYPOINT [ "/opt/connect/entrypoint.sh" ] |
| 56 | +CMD ["/opt/connect/mirth-connect.sh"] |
| 57 | + |
| 58 | +# Stage 2b: JRE runtime container |
| 59 | +FROM eclipse-temurin:21.0.7_6-jre-alpine as jre-run |
| 60 | + |
| 61 | +# Alpine does not include bash by default, so we install it |
| 62 | +RUN apk add --no-cache bash |
| 63 | +# useradd and groupadd are not available in Alpine |
| 64 | +RUN addgroup -S mirth \ |
| 65 | + && adduser -S -g mirth mirth \ |
| 66 | + && mkdir -p /opt/connect/appdata \ |
| 67 | + && chown -R mirth:mirth /opt/connect |
| 68 | + |
| 69 | +WORKDIR /opt/connect |
| 70 | +COPY --chown=mirth:mirth --from=builder \ |
| 71 | + --exclude=cli-lib \ |
| 72 | + --exclude=mirth-cli-launcher.jar \ |
| 73 | + --exclude=mccommand \ |
| 74 | + --exclude=manager-lib \ |
| 75 | + --exclude=mirth-manager-launcher.jar \ |
| 76 | + --exclude=mcmanager \ |
| 77 | + /app/server/setup ./ |
| 78 | + |
| 79 | +VOLUME /opt/connect/appdata |
| 80 | +VOLUME /opt/connect/custom-extensions |
| 81 | +EXPOSE 8443 |
| 82 | + |
| 83 | +USER mirth |
| 84 | +ENTRYPOINT [ "/opt/connect/entrypoint.sh" ] |
| 85 | +CMD ["/opt/connect/mirth-connect.sh"] |
0 commit comments