forked from openmrs/openmrs-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TRUNK-6083: Build and deploy docker image for openmrs-core
- Loading branch information
1 parent
ac68435
commit 15097ae
Showing
6 changed files
with
551 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
# the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
# | ||
# Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
# graphic logo is a trademark of OpenMRS Inc. | ||
|
||
### Build Stage | ||
FROM maven:3.8-jdk-11 as build | ||
WORKDIR /app | ||
|
||
ENV DEPENDENCY_PLUGIN="org.apache.maven.plugins:maven-dependency-plugin:3.3.0" | ||
|
||
# Copy poms to resolve dependencies | ||
COPY pom.xml . | ||
COPY liquibase/pom.xml ./liquibase/ | ||
COPY tools/pom.xml ./tools/ | ||
COPY test/pom.xml ./test/ | ||
COPY web/pom.xml ./web/ | ||
COPY api/pom.xml ./api/ | ||
COPY webapp/pom.xml ./webapp/ | ||
|
||
# Resolve dependencies in order to cache them and run offline builds | ||
RUN mvn $DEPENDENCY_PLUGIN:go-offline | ||
|
||
ARG MVN_ARGS='install' | ||
|
||
# Build the app using cached dependencies | ||
# Append --build-arg MVN_ARGS='install -o' to change default maven arguments | ||
# Build modules individually to benefit from caching | ||
COPY checkstyle.xml checkstyle-suppressions.xml CONTRIBUTING.md findbugs-include.xml LICENSE license-header.txt \ | ||
NOTICE.md README.md ruleset.xml SECURITY.md ./ | ||
|
||
COPY liquibase ./liquibase/ | ||
RUN mvn -pl liquibase $MVN_ARGS | ||
|
||
COPY tools/ ./tools/ | ||
RUN mvn -pl tools $MVN_ARGS | ||
|
||
COPY test/ ./test/ | ||
RUN mvn -pl test $MVN_ARGS | ||
|
||
COPY api/ ./api/ | ||
RUN mvn -pl api $MVN_ARGS | ||
|
||
COPY web/ ./web/ | ||
RUN mvn -pl web $MVN_ARGS | ||
|
||
COPY webapp/ ./webapp/ | ||
RUN mvn -pl webapp $MVN_ARGS | ||
|
||
# Store dependencies for re-use when running | ||
# If mounting ~/.m2:/root/.m2 then the m2 repo content will be copied over from the image | ||
RUN cp -r /root/.m2/repository /usr/share/maven/ref/repository | ||
|
||
WORKDIR /app/webapp | ||
|
||
# Startup jetty by default for the dev image | ||
# TODO: Use Tomcat with spring devtools instead | ||
CMD ["mvn", "jetty:run", "-o"] | ||
|
||
### Production Stage | ||
FROM tomcat:9.0-jdk8-adoptopenjdk-hotspot | ||
|
||
RUN apt-get update && apt-get install -y zip dumb-init \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/local/tomcat/webapps/* | ||
|
||
RUN groupadd -r openmrs \ | ||
&& useradd --no-log-init -r -g openmrs openmrs \ | ||
&& chown -R openmrs $CATALINA_HOME \ | ||
&& mkdir -p /openmrs \ | ||
&& chown -R openmrs /openmrs | ||
|
||
USER openmrs | ||
|
||
WORKDIR /openmrs | ||
|
||
# All environment variables that are available to configure on this container are listed here | ||
# for clarity. These list the variables supported, and the default values if not overridden | ||
|
||
# These environment variables are appended to configure the Tomcat JAVA_OPTS | ||
ENV OMRS_JAVA_MEMORY_OPTS="-XX:NewSize=128m" | ||
ENV OMRS_JAVA_SERVER_OPTS="-Dfile.encoding=UTF-8 -server -Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Djava.awt.headlesslib=true" | ||
|
||
# These environment variables are used to create the openmrs-server.properties file, which controls how OpenMRS initializes | ||
ENV OMRS_CONFIG_ADD_DEMO_DATA="false" | ||
ENV OMRS_CONFIG_ADMIN_USER_PASSWORD="Admin123" | ||
ENV OMRS_CONFIG_AUTO_UPDATE_DATABASE="true" | ||
ENV OMRS_CONFIG_CREATE_DATABASE_USER="false" | ||
ENV OMRS_CONFIG_CREATE_TABLES="false" | ||
ENV OMRS_CONFIG_HAS_CURRENT_OPENMRS_DATABASE="true" | ||
ENV OMRS_CONFIG_INSTALL_METHOD="auto" | ||
ENV OMRS_CONFIG_MODULE_WEB_ADMIN="true" | ||
|
||
# These variables are specific to database connections | ||
# Supported values for OMRS_CONFIG_CONNECTION_TYPE are "mysql" and "postgresql" | ||
# other values are treated as MySQL | ||
ENV OMRS_CONFIG_CONNECTION_TYPE="mysql" | ||
ENV OMRS_CONFIG_CONNECTION_USERNAME="openmrs" | ||
ENV OMRS_CONFIG_CONNECTION_PASSWORD="openmrs" | ||
ENV OMRS_CONFIG_CONNECTION_SERVER="localhost" | ||
ENV OMRS_CONFIG_CONNECTION_DATABASE="openmrs" | ||
|
||
# These environment variables can be used to customise the database connection. | ||
# Their default values depend on which database you are using. | ||
# OMRS_CONFIG_CONNECTION_DRIVER_CLASS | ||
# OMRS_CONFIG_CONNECTION_PORT | ||
# OMRS_CONFIG_CONNECTION_ARGS | ||
# OMRS_CONFIG_CONNECTION_EXTRA_ARGS | ||
# | ||
# If you really need complete control, you can just set | ||
# OMRS_CONFIG_CONNECTION_URL to whatever the URL should be | ||
|
||
# These environment variables are meant to enable developer settings | ||
# OMRS_DEV_DEBUG_PORT | ||
|
||
# Additional environment variables as needed. This should match the name of the distribution supplied OpenMRS war file | ||
ENV OMRS_WEBAPP_NAME="openmrs" | ||
|
||
# Copy in the start-up scripts | ||
COPY --chmod=0755 wait-for-it.sh startup.sh /usr/local/tomcat/ | ||
|
||
RUN sed -i '/Connector port="8080"/a URIEncoding="UTF-8" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^\`"<>"' /usr/local/tomcat/conf/server.xml | ||
|
||
# Copy the app | ||
COPY --from=build /app/webapp/target/openmrs.war /openmrs/distribution/openmrs_core/openmrs.war | ||
|
||
EXPOSE 8080 | ||
|
||
CMD ["dumb-init", "/usr/local/tomcat/startup.sh"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: "3.7" | ||
|
||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
# the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
# | ||
# Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
# graphic logo is a trademark of OpenMRS Inc. | ||
|
||
services: | ||
db: | ||
ports: | ||
- "3306:3306" | ||
restart: "no" | ||
|
||
openmrs-core: | ||
image: openmrs-core:dev | ||
build: | ||
target: build | ||
context: . | ||
ports: | ||
- "8080:8080" | ||
- "8000:8000" | ||
volumes: | ||
- ~/.m2:/root/.m2 | ||
restart: "no" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
version: "3.7" | ||
|
||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
# the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
# | ||
# Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
# graphic logo is a trademark of OpenMRS Inc. | ||
|
||
services: | ||
db: | ||
image: mariadb:10.3 | ||
command: "mysqld --character-set-server=utf8 --collation-server=utf8_general_ci" | ||
environment: | ||
MYSQL_DATABASE: ${OPENMRS_DB_NAME:-openmrs} | ||
MYSQL_USER: ${OPENMRS_DB_USER:-openmrs} | ||
MYSQL_PASSWORD: ${OPENMRS_DB_PASSWORD:-openmrs} | ||
MYSQL_ROOT_PASSWORD: ${OPENMRS_DB_ROOT_PASSWORD:-openmrs} | ||
volumes: | ||
- db-data:/var/lib/mysql | ||
|
||
openmrs-core: | ||
image: openmrs-core:latest | ||
build: . | ||
depends_on: | ||
- db | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
OMRS_CONFIG_MODULE_WEB_ADMIN: "true" | ||
OMRS_CONFIG_AUTO_UPDATE_DATABASE: "true" | ||
OMRS_CONFIG_CREATE_TABLES: "true" | ||
OMRS_CONFIG_CONNECTION_SERVER: db | ||
OMRS_CONFIG_CONNECTION_DATABASE: ${OPENMRS_DB_NAME:-openmrs} | ||
OMRS_CONFIG_CONNECTION_USERNAME: ${OPENMRS_DB_USER:-openmrs} | ||
OMRS_CONFIG_CONNECTION_PASSWORD: ${OPENMRS_DB_PASSWORD:-openmrs} | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://localhost:8080/openmrs"] | ||
timeout: 5s | ||
volumes: | ||
- ./target/openmrs-data:/openmrs/data/:z | ||
|
||
volumes: | ||
db-data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#!/bin/bash -eu | ||
# This Source Code Form is subject to the terms of the Mozilla Public License, | ||
# v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
# obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
# the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
# | ||
# Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
# graphic logo is a trademark of OpenMRS Inc. | ||
|
||
echo "Initiating OpenMRS startup" | ||
|
||
# This startup script is responsible for fully preparing the OpenMRS Tomcat environment. | ||
|
||
OMRS_HOME="/openmrs" | ||
OMRS_WEBAPP_NAME=${OMRS_WEBAPP_NAME:-openmrs} | ||
|
||
# A volume mount is expected that contains distribution artifacts. The expected format is shown in these environment vars. | ||
|
||
OMRS_DISTRO_DIR="$OMRS_HOME/distribution" | ||
OMRS_DISTRO_CORE="$OMRS_DISTRO_DIR/openmrs_core" | ||
OMRS_DISTRO_MODULES="$OMRS_DISTRO_DIR/openmrs_modules" | ||
OMRS_DISTRO_OWAS="$OMRS_DISTRO_DIR/openmrs_owas" | ||
OMRS_DISTRO_CONFIG="$OMRS_DISTRO_DIR/openmrs_config" | ||
|
||
# Each of these mounted directories are used to populate expected configurations on the server, defined here | ||
|
||
OMRS_DATA_DIR="$OMRS_HOME/data" | ||
OMRS_MODULES_DIR="$OMRS_DATA_DIR/modules" | ||
OMRS_OWA_DIR="$OMRS_DATA_DIR/owa" | ||
OMRS_CONFIG_DIR="$OMRS_DATA_DIR/configuration" | ||
|
||
OMRS_SERVER_PROPERTIES_FILE="$OMRS_HOME/$OMRS_WEBAPP_NAME-server.properties" | ||
OMRS_RUNTIME_PROPERTIES_FILE="$OMRS_DATA_DIR/$OMRS_WEBAPP_NAME-runtime.properties" | ||
|
||
TOMCAT_DIR="/usr/local/tomcat" | ||
TOMCAT_WEBAPPS_DIR="$TOMCAT_DIR/webapps" | ||
TOMCAT_WORK_DIR="$TOMCAT_DIR/work" | ||
TOMCAT_TEMP_DIR="$TOMCAT_DIR/temp" | ||
TOMCAT_SETENV_FILE="$TOMCAT_DIR/bin/setenv.sh" | ||
|
||
echo "Clearing out existing directories of any previous artifacts" | ||
|
||
rm -fR $TOMCAT_WEBAPPS_DIR; | ||
rm -fR $OMRS_MODULES_DIR; | ||
rm -fR $OMRS_OWA_DIR | ||
rm -fR $OMRS_CONFIG_DIR | ||
rm -fR $TOMCAT_WORK_DIR | ||
rm -fR $TOMCAT_TEMP_DIR | ||
|
||
mkdir -p $TOMCAT_TEMP_DIR | ||
|
||
echo "Loading artifacts into appropriate locations" | ||
|
||
cp -r $OMRS_DISTRO_CORE $TOMCAT_WEBAPPS_DIR | ||
[ -d "$OMRS_DISTRO_MODULES" ] && cp -r $OMRS_DISTRO_MODULES $OMRS_MODULES_DIR | ||
[ -d "$OMRS_DISTRO_OWAS" ] && cp -r $OMRS_DISTRO_OWAS $OMRS_OWA_DIR | ||
[ -d "$OMRS_DISTRO_CONFIG" ] && cp -r $OMRS_DISTRO_CONFIG $OMRS_CONFIG_DIR | ||
|
||
# setup database configuration properties | ||
# Setup database configuration properties | ||
OMRS_CONFIG_DATABASE="${OMRS_CONFIG_DATABASE:-mysql}" | ||
OMRS_CONFIG_CONNECTION_SERVER="${OMRS_CONFIG_CONNECTION_SERVER:-localhost}" | ||
OMRS_CONFIG_CONNECTION_DATABASE="${OMRS_CONFIG_CONNECTION_DATABASE:-openmrs}" | ||
OMRS_CONFIG_CONNECTION_EXTRA_ARGS="${OMRS_CONFIG_CONNECTION_EXTRA_ARGS-}" | ||
|
||
if [[ -z $OMRS_CONFIG_DATABASE || "$OMRS_CONFIG_DATABASE" == "mysql" ]]; then | ||
OMRS_CONFIG_JDBC_URL_PROTOCOL=mysql | ||
OMRS_CONFIG_CONNECTION_DRIVER_CLASS="${OMRS_CONFIG_CONNECTION_DRIVER_CLASS:-com.mysql.jdbc.Driver}" | ||
OMRS_CONFIG_CONNECTION_PORT="${OMRS_CONFIG_CONNECTION_PORT:-3306}" | ||
OMRS_CONFIG_CONNECTION_ARGS="${OMRS_CONFIG_CONNECTION_ARGS:-?autoReconnect=true&sessionVariables=default_storage_engine=InnoDB&useUnicode=true&characterEncoding=UTF-8}" | ||
elif [[ "$OMRS_CONFIG_DATABASE" == "postgresql" ]]; then | ||
OMRS_CONFIG_JDBC_URL_PROTOCOL=postgresql | ||
OMRS_CONFIG_CONNECTION_DRIVER_CLASS="${OMRS_CONFIG_CONNECTION_DRIVER_CLASS:-org.postgresql.Driver}" | ||
OMRS_CONFIG_CONNECTION_PORT="${OMRS_CONFIG_CONNECTION_PORT:-5432}" | ||
else | ||
echo "Unknown database type $OMRS_CONFIG_DATABASE. Using properties for MySQL" | ||
OMRS_CONFIG_JDBC_URL_PROTOCOL=mysql | ||
OMRS_CONFIG_CONNECTION_DRIVER_CLASS="${OMRS_CONFIG_CONNECTION_DRIVER_CLASS:-com.mysql.jdbc.Driver}" | ||
OMRS_CONFIG_CONNECTION_PORT="${OMRS_CONFIG_CONNECTION_PORT:-3306}" | ||
OMRS_CONFIG_CONNECTION_ARGS="${OMRS_CONFIG_CONNECTION_ARGS:-?autoReconnect=true&sessionVariables=default_storage_engine=InnoDB&useUnicode=true&characterEncoding=UTF-8}" | ||
fi | ||
|
||
# Build the JDBC URL using the above properties | ||
OMRS_CONFIG_CONNECTION_URL="${OMRS_CONFIG_CONNECTION_URL:-jdbc:${OMRS_CONFIG_JDBC_URL_PROTOCOL}://${OMRS_CONFIG_CONNECTION_SERVER}:${OMRS_CONFIG_CONNECTION_PORT}/${OMRS_CONFIG_CONNECTION_DATABASE}${OMRS_CONFIG_CONNECTION_ARGS}${OMRS_CONFIG_CONNECTION_EXTRA_ARGS}}" | ||
|
||
echo "Writing out $OMRS_SERVER_PROPERTIES_FILE" | ||
|
||
cat > $OMRS_SERVER_PROPERTIES_FILE << EOF | ||
add_demo_data=${OMRS_CONFIG_ADD_DEMO_DATA} | ||
admin_user_password=${OMRS_CONFIG_ADMIN_USER_PASSWORD} | ||
auto_update_database=${OMRS_CONFIG_AUTO_UPDATE_DATABASE} | ||
connection.driver_class=${OMRS_CONFIG_CONNECTION_DRIVER_CLASS} | ||
connection.username=${OMRS_CONFIG_CONNECTION_USERNAME} | ||
connection.password=${OMRS_CONFIG_CONNECTION_PASSWORD} | ||
connection.url=${OMRS_CONFIG_CONNECTION_URL} | ||
create_database_user=${OMRS_CONFIG_CREATE_DATABASE_USER} | ||
create_tables=${OMRS_CONFIG_CREATE_TABLES} | ||
has_current_openmrs_database=${OMRS_CONFIG_HAS_CURRENT_OPENMRS_DATABASE} | ||
install_method=${OMRS_CONFIG_INSTALL_METHOD} | ||
module_web_admin=${OMRS_CONFIG_MODULE_WEB_ADMIN} | ||
module.allow_web_admin=${OMRS_CONFIG_MODULE_WEB_ADMIN} | ||
EOF | ||
|
||
if [ -f $OMRS_RUNTIME_PROPERTIES_FILE ]; then | ||
echo "Found existing runtime properties file at $OMRS_RUNTIME_PROPERTIES_FILE. Overwriting with $OMRS_SERVER_PROPERTIES_FILE" | ||
cp $OMRS_SERVER_PROPERTIES_FILE $OMRS_RUNTIME_PROPERTIES_FILE | ||
fi | ||
|
||
echo "Writing out $TOMCAT_SETENV_FILE file" | ||
|
||
JAVA_OPTS="$OMRS_JAVA_SERVER_OPTS" | ||
CATALINA_OPTS="$OMRS_JAVA_MEMORY_OPTS -DOPENMRS_INSTALLATION_SCRIPT=$OMRS_SERVER_PROPERTIES_FILE -DOPENMRS_APPLICATION_DATA_DIRECTORY=$OMRS_DATA_DIR/" | ||
|
||
if [ -n "${OMRS_DEV_DEBUG_PORT-}" ]; then | ||
echo "Enabling debugging on port $OMRS_DEV_DEBUG_PORT" | ||
CATALINA_OPTS="$CATALINA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$OMRS_DEV_DEBUG_PORT" | ||
fi | ||
|
||
cat > $TOMCAT_SETENV_FILE << EOF | ||
export JAVA_OPTS="$JAVA_OPTS" | ||
export CATALINA_OPTS="$CATALINA_OPTS" | ||
EOF | ||
|
||
echo "Waiting for database to initialize..." | ||
|
||
/usr/local/tomcat/wait-for-it.sh --timeout=3600 "${OMRS_CONFIG_CONNECTION_SERVER}:${OMRS_CONFIG_CONNECTION_PORT}" | ||
|
||
echo "Starting up OpenMRS..." | ||
|
||
/usr/local/tomcat/bin/catalina.sh run & | ||
|
||
# Trigger first filter to start data importation | ||
sleep 15 | ||
curl -sL "http://localhost:8080/$OMRS_WEBAPP_NAME/" > /dev/null | ||
sleep 15 | ||
|
||
# bring tomcat process to foreground again | ||
wait ${!} |
Oops, something went wrong.