Dockerfile 4.19 KB
# syntax=docker/dockerfile:1.4
# Builds a minimal docker image with openjdk and moqui with various volumes for configuration and persisted data outside the container
# NOTE: add components, build and if needed load data before building a docker image with this
ARG RUNTIME_IMAGE=eclipse-temurin:11-jdk
FROM ${RUNTIME_IMAGE} AS moqui-base

RUN true \
	&& apt-get update \
	&& apt-get install -y unzip less git \
	&& apt-get clean && rm -rf /var/lib/apt/lists/* \
	&& groupadd -g 1000 moqui \
	&& useradd -u 1000 -g 1000 -G 0 -d /opt/moqui moqui \
	&& mkdir /opt/moqui \
	&& chown moqui:moqui /opt/moqui \
	&& true

FROM moqui-base AS moqui-jdbc-drivers

RUN true \
	&& apt-get update \
	&& apt-get install -y libpostgresql-jdbc-java \
	&& apt-get clean && rm -rf /var/lib/apt/lists/* \
	&& true

# build runs as root; attempting to chown all the copied-in files runs
# *very* slow
FROM moqui-base AS moqui-build

WORKDIR /opt/moqui-build

RUN ["mkdir", "/opt/moqui-scripts"]
COPY --from=moqui-builder fix-git-submodules /opt/moqui-scripts/fix-git-submodules

COPY ./ /opt/moqui-app/

RUN ["/opt/moqui-scripts/fix-git-submodules", "-start", "/opt/moqui-app"]

RUN true && set -x \
	&& rm -rf /opt/moqui-build && ln -sf /opt/moqui-app/framework /opt/moqui-build \
	&& rm -rf /opt/moqui-build/runtime && ln -sf /opt/moqui-app/runtime /opt/moqui-build/runtime \
	&& rm -rf /opt/moqui-build/runtime/component && ln -sf /opt/moqui-app/component /opt/moqui-build/runtime/component \
	&& true

RUN ["./gradlew", "--no-daemon", "--info", "build", "addRuntime"]

WORKDIR /opt/moqui
USER moqui
RUN ["unzip", "-o", "/opt/moqui-build/moqui-plus-runtime.war"]

FROM moqui-base AS moqui-app
MAINTAINER Moqui Framework <moqui@googlegroups.com>

USER moqui
WORKDIR /opt/moqui

COPY --from=moqui-build /opt/moqui/ /opt/moqui/
RUN ["ls", "-l", "/opt/moqui/"]

# create user for search and chown corresponding files
#ARG search_name=opensearch

# This is a fix for previous installs, not needed for new setups.
# upgrade fix #RUN if [ -d runtime/opensearch/bin ]; then echo "Installing OpenSearch User"; \
# upgrade fix #      search_name=opensearch; \
# upgrade fix #      groupadd -g 1000 opensearch && \
# upgrade fix #      useradd -u 1000 -g 1000 -G 0 -d /opt/moqui/runtime/opensearch opensearch && \
# upgrade fix #      chmod 0775 /opt/moqui/runtime/opensearch && \
# upgrade fix #      chown -R 1000:0 /opt/moqui/runtime/opensearch; \
# upgrade fix #    elif [ -d runtime/elasticsearch/bin ]; then echo "Installing ElasticSearch User"; \
# upgrade fix #      search_name=elasticsearch; \
# upgrade fix #      groupadd -r elasticsearch && \
# upgrade fix #      useradd --no-log-init -r -g elasticsearch -d /opt/moqui/runtime/elasticsearch elasticsearch && \
# upgrade fix #      chown -R elasticsearch:elasticsearch runtime/elasticsearch; \
# upgrade fix #    fi

# exposed as volumes for configuration purposes
RUN ["mkdir", "-p", "/opt/moqui/runtime/conf", "/opt/moqui/runtime/lib", "/opt/moqui/runtime/classes", "/opt/moqui/runtime/ecomponent"]
VOLUME ["/opt/moqui/runtime/conf", "/opt/moqui/runtime/lib", "/opt/moqui/runtime/classes", "/opt/moqui/runtime/ecomponent"]
# exposed as volumes to persist data outside the container, recommended
RUN ["mkdir", "-p", "/opt/moqui/runtime/log", "/opt/moqui/runtime/txlog", "/opt/moqui/runtime/sessions", "/opt/moqui/runtime/db"]
VOLUME ["/opt/moqui/runtime/log", "/opt/moqui/runtime/txlog", "/opt/moqui/runtime/sessions", "/opt/moqui/runtime/db"]

# Main Servlet Container Port
EXPOSE 8080
# Not used for external search # # Search HTTP Port
# Not used for external search # EXPOSE 9200
# Not used for external search # # Search Cluster (TCP Transport) Port
# Not used for external search # EXPOSE 9300
# Hazelcast Cluster Port
EXPOSE 5701

# this is to run from the war file directly, preferred approach unzips war file in advance
# ENTRYPOINT ["java", "-jar", "moqui.war"]
ENTRYPOINT ["java", "-cp", ".", "MoquiStart"]

HEALTHCHECK --interval=30s --timeout=600ms --start-period=120s CMD curl -f -H "X-Forwarded-Proto: https" -H "X-Forwarded-Ssl: on" http://localhost:8080/status || exit 1
# specify this as a default parameter if none are specified with docker exec/run, ie run production by default
CMD ["port=8080", "conf=conf/MoquiProductionConf.xml"]