GUACAMOLE-408: revise Dockerfile to use multi-stage image build

This commit is contained in:
Carl Harris
2017-10-07 10:07:20 -04:00
parent 153996b725
commit 5c07e4a4ee

View File

@@ -21,29 +21,36 @@
# Dockerfile for guacamole-client # Dockerfile for guacamole-client
# #
# Start from Tomcat image # Use args for Tomcat image label to allow image builder to choose alternatives
FROM tomcat:8.0.20-jre8 # such as `--build-arg TOMCAT_JRE=jre8-alpine`
#
ARG TOMCAT_VERSION=8.0.20
ARG TOMCAT_JRE=jre8
# Environment variables # Use official maven image for the build
FROM maven:3-jdk-8 AS builder
# Build environment variables
ENV \ ENV \
BUILD_DIR=/tmp/guacamole-docker-BUILD \ BUILD_DIR=/tmp/guacamole-docker-BUILD
BUILD_DEPENDENCIES=" \
maven \
openjdk-8-jdk-headless"
# Add configuration scripts # Add configuration scripts
COPY guacamole-docker/bin /opt/guacamole/bin/ COPY guacamole-docker/bin/ /opt/guacamole/bin/
# Copy source to container for sake of build # Copy source to container for sake of build
COPY . "$BUILD_DIR" COPY . "$BUILD_DIR"
# Build latest guacamole-client and authentication # Run the build itself
RUN apt-get update && \ RUN /opt/guacamole/bin/build-guacamole.sh "$BUILD_DIR" /opt/guacamole
apt-get install -y --no-install-recommends $BUILD_DEPENDENCIES && \
/opt/guacamole/bin/build-guacamole.sh "$BUILD_DIR" /opt/guacamole && \ # For the runtime image, we start with the official Tomcat distribution
rm -Rf "$BUILD_DIR" && \ FROM tomcat:${TOMCAT_VERSION}-${TOMCAT_JRE}
rm -Rf /var/lib/apt/lists/* && \
apt-get purge -y --auto-remove $BUILD_DEPENDENCIES # This is where the build artifacts go in the runtime image
WORKDIR /opt/guacamole
# Copy artifacts from builder image into this image
COPY --from=builder /opt/guacamole/ .
# Start Guacamole under Tomcat, listening on 0.0.0.0:8080 # Start Guacamole under Tomcat, listening on 0.0.0.0:8080
EXPOSE 8080 EXPOSE 8080