54 lines
No EOL
2.1 KiB
Docker
54 lines
No EOL
2.1 KiB
Docker
# Stage 1: Build the application using SBT
|
|
# We use a stable OpenJDK 8 base and install the specific SBT version needed,
|
|
# as public SBT images for older versions can be unreliable.
|
|
FROM openjdk:8-jdk-slim as builder
|
|
|
|
# SBT version from project/build.properties
|
|
ARG SBT_VERSION=0.13.11
|
|
ENV SBT_HOME=/usr/local/sbt
|
|
ENV PATH=${SBT_HOME}/bin:${PATH}
|
|
|
|
# Install required tools and the specific version of SBT
|
|
# The .tgz for 0.13.11 is missing from GitHub releases. We'll install it manually.
|
|
RUN apt-get update && \
|
|
# Install certificates for HTTPS, curl to download, and unzip to verify
|
|
apt-get install -y ca-certificates wget unzip && \
|
|
mkdir -p "${SBT_HOME}/bin" && \
|
|
wget -O "${SBT_HOME}/bin/sbt-launch.jar" "https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/${SBT_VERSION}/sbt-launch-${SBT_VERSION}.jar" && \
|
|
# Explicitly check that the file was downloaded before trying to use it
|
|
[ -f "${SBT_HOME}/bin/sbt-launch.jar" ] && \
|
|
# Verify the downloaded JAR is valid
|
|
unzip -t "${SBT_HOME}/bin/sbt-launch.jar" && \
|
|
echo '#!/bin/sh' > "${SBT_HOME}/bin/sbt" && \
|
|
echo 'SBT_OPTS="-Xms512M -Xmx1536M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M"' >> "${SBT_HOME}/bin/sbt" && \
|
|
echo 'java $SBT_OPTS -jar `dirname $0`/sbt-launch.jar "$@"' >> "${SBT_HOME}/bin/sbt" && \
|
|
chmod 0755 "${SBT_HOME}/bin/sbt" && \
|
|
apt-get purge -y --auto-remove wget unzip && \
|
|
rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy project definition files and resolve dependencies first for better layer caching
|
|
COPY project/ ./project/
|
|
COPY build.sbt .
|
|
|
|
# This step will download all the dependencies
|
|
RUN sbt update
|
|
|
|
# Copy the rest of the source code
|
|
COPY . .
|
|
|
|
# Package the application into a WAR file
|
|
RUN sbt package
|
|
|
|
# Stage 2: Create the runtime image with Tomcat
|
|
FROM tomcat:9.0-jdk11-openjdk-slim
|
|
|
|
# Remove the default webapps
|
|
RUN rm -rf /usr/local/tomcat/webapps/*
|
|
|
|
# Copy the WAR file from the builder stage to Tomcat's webapps directory
|
|
# The WAR file will be automatically deployed by Tomcat on startup
|
|
COPY --from=builder /app/target/scala-2.11/coc-base-analyser_2.11-0.1.war /usr/local/tomcat/webapps/ROOT.war
|
|
|
|
EXPOSE 8080 |