Support auto-generated Dockerfile from Transformation Advisor
Dev mode for containers should support the Dockerfile that Transformation Advisor (TA) generates for users when they migrate their application from WAS to Liberty.
The generated Dockerfile uses multi-stage builds. Dev mode does not handle files copied from a part of the multi-stage build that comes before the OpenLiberty stage of the build (marked by something like FROM open-liberty:kernel-java8-openj9) e.g. COPY --from=<build-stage-name>
Example Dockerfile generated by TA:
# Generated by IBM TransformationAdvisor
# Fri Dec 04 19:13:15 UTC 2020
FROM adoptopenjdk/openjdk8-openj9 AS build-stage
RUN apt-get update && \
apt-get install -y maven unzip
COPY . /project
WORKDIR /project
#RUN mvn -X initialize process-resources verify => to get dependencies from maven
#RUN mvn clean package
#RUN mvn --version
RUN mvn --version
RUN mkdir -p /config/apps && \
mkdir -p /sharedlibs && \
cp ./src/main/liberty/config/server.xml /config && \
cp ./target/*.*ar /config/apps/ && \
if [ ! -z "$(ls ./src/main/liberty/lib)" ]; then \
cp ./src/main/liberty/lib/* /sharedlibs; \
fi
FROM open-liberty:kernel-java8-openj9
ARG SSL=true
ARG MP_MONITORING=true
ARG HTTP_ENDPOINT=false
RUN mkdir -p /opt/ol/wlp/usr/shared/config/lib/global
COPY --chown=1001:0 --from=build-stage /config/ /config/
COPY --chown=1001:0 --from=build-stage /sharedlibs/ /opt/ol/wlp/usr/shared/config/lib/global
USER root
RUN configure.sh
USER 1001
# Upgrade to production license if URL to JAR provided
ARG LICENSE_JAR_URL
RUN \
if [ $LICENSE_JAR_URL ]; then \
wget $LICENSE_JAR_URL -O /tmp/license.jar \
&& java -jar /tmp/license.jar -acceptLicense /opt/ibm \
&& rm /tmp/license.jar; \
fi
Here is some more info on the current issues with the example TA Dockerfile.
The section below, setup by WORKDIR, causes the Docker build to break. Dev mode does not handle removing the cp ./target/*.*ar /config/apps/ && \ line.
WORKDIR /project
...
...
RUN mkdir -p /config/apps && \
mkdir -p /sharedlibs && \
cp ./src/main/liberty/config/server.xml /config && \
cp ./target/*.*ar /config/apps/ && \
if [ ! -z "$(ls ./src/main/liberty/lib)" ]; then \
cp ./src/main/liberty/lib/* /sharedlibs; \
fi
Dev mode also does not support hot deployment with multi-stage builds. These two lines...
COPY --chown=1001:0 --from=build-stage /config/ /config/
COPY --chown=1001:0 --from=build-stage /sharedlibs/ /opt/ol/wlp/usr/shared/config/lib/global
...trigger the following two warnings:
[WARNING] The Dockerfile line 'COPY --chown=1001:0 --from=build-stage /config/ /config/' will not be able to be hot deployed to the dev mode container. Dev mode does not currently support hot deployment with multi-stage COPY commands.
[WARNING] The Dockerfile line 'COPY --chown=1001:0 --from=build-stage /sharedlibs/ /opt/ol/wlp/usr/shared/config/lib/global' will not be able to be hot deployed to the dev mode container. Dev mode does not currently support hot deployment with multi-stage COPY commands.
Maybe for a two-stage build we should just ignore the first stage and enhance our modifications/tweaks to make sure they handle the additional syntax we'd need to modify in stage 2 (if our tweaks don't cover these already)?