Skip to content

Commit

Permalink
TRUNK-6186 Pre-cache dependencies for Docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Aug 9, 2023
1 parent 4c1344f commit b1929d1
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ nb-configuration.xml
/webapp/src/main/webapp/WEB-INF/dwr-modules.xml
/webapp/src/main/webapp/WEB-INF/module_messages*
/web/WEB-INF/dwr-modules.xml
/openmrs-merged.properties
#############

### log files ###
Expand Down
32 changes: 20 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,37 @@ WORKDIR /openmrs_core
ENV OMRS_SDK_PLUGIN="org.openmrs.maven.plugins:openmrs-sdk-maven-plugin"
ENV OMRS_SDK_PLUGIN_VERSION="4.5.0"

COPY checkstyle.xml checkstyle-suppressions.xml CONTRIBUTING.md findbugs-include.xml LICENSE license-header.txt \
NOTICE.md README.md ruleset.xml SECURITY.md ./
COPY docker-pom.xml .

COPY pom.xml .
ARG MVN_SETTINGS="-s /usr/share/maven/ref/settings-docker.xml"

# Setup and cache SDK
RUN --mount=type=cache,target=/root/.m2 mvn $OMRS_SDK_PLUGIN:$OMRS_SDK_PLUGIN_VERSION:setup-sdk -N -DbatchAnswers=n
RUN mvn $MVN_SETTINGS -f docker-pom.xml $OMRS_SDK_PLUGIN:$OMRS_SDK_PLUGIN_VERSION:setup-sdk -N -DbatchAnswers=n

COPY pom.xml .
COPY test/pom.xml test/
COPY tools/pom.xml tools/
COPY liquibase/pom.xml liquibase/
COPY api/pom.xml api/
COPY web/pom.xml web/
COPY webapp/pom.xml webapp/

# Copy remainign poms
# Install dependencies
RUN mvn $MVN_SETTINGS -B dependency:go-offline -P !default-tools.jar,!mac-tools.jar

# Copy remaining files
COPY . .

# Append --build-arg MVN_ARGS='clean install' to change default maven arguments
ARG MVN_ARGS='clean install'

# Build the project
RUN --mount=type=cache,target=/root/.m2 mvn $MVN_ARGS
RUN mvn $MVN_SETTINGS $MVN_ARGS

RUN mkdir -p /openmrs/distribution/openmrs_core/ \
&& cp /openmrs_core/webapp/target/openmrs.war /openmrs/distribution/openmrs_core/openmrs.war

# Copy in the start-up scripts
COPY wait-for-it.sh startup-init.sh startup.sh startup-dev.sh /openmrs/
RUN chmod +x /openmrs/wait-for-it.sh && chmod +x /openmrs/startup-init.sh && chmod +x /openmrs/startup.sh \
&& cp /openmrs_core/webapp/target/openmrs.war /openmrs/distribution/openmrs_core/openmrs.war \
&& cp /openmrs_core/wait-for-it.sh /openmrs_core/startup-init.sh /openmrs_core/startup.sh /openmrs_core/startup-dev.sh /openmrs/ \
&& chmod +x /openmrs/wait-for-it.sh && chmod +x /openmrs/startup-init.sh && chmod +x /openmrs/startup.sh \
&& chmod +x /openmrs/startup-dev.sh

EXPOSE 8080
Expand Down Expand Up @@ -101,7 +109,7 @@ RUN mkdir -p /openmrs/data/modules \
&& chmod -R g+rw /openmrs

# Copy in the start-up scripts
COPY wait-for-it.sh startup-init.sh startup.sh /openmrs/
COPY --from=dev /openmrs/wait-for-it.sh /openmrs/startup-init.sh /openmrs/startup.sh /openmrs/
RUN chmod g+x /openmrs/wait-for-it.sh && chmod g+x /openmrs/startup-init.sh && chmod g+x /openmrs/startup.sh

WORKDIR /openmrs
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ services:
build:
target: dev
context: .
cache_from:
- openmrs/openmrs-core:${TAG-dev}
ports:
- "8080:8080"
- "8000:8000"
Expand Down
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ services:

api:
image: openmrs/openmrs-core:${TAG:-nightly}
build: .
build:
context: .
cache_from:
- openmrs/openmrs-core:${TAG-dev}
- openmrs/openmrs-core:${TAG-nightly}
depends_on:
- db
ports:
Expand Down
55 changes: 55 additions & 0 deletions docker-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>org.openmrs</groupId>
<artifactId>openmrs-docker</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>OpenMRS Docker</name>
<description>POM used to setup SDK in Docker builds</description>
<url>https://openmrs.org</url>

<repositories>
<repository>
<id>openmrs-repo</id>
<name>OpenMRS Nexus Repository</name>
<url>https://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>openmrs-repo</id>
<name>OpenMRS Nexus Repository</name>
<url>https://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<distributionManagement>
<repository>
<id>openmrs-repo-releases</id>
<name>OpenMRS Nexus Releases</name>
<url>https://mavenrepo.openmrs.org/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>openmrs-repo-snapshots</id>
<name>OpenMRS Nexus Snapshots</name>
<url>https://mavenrepo.openmrs.org/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>
3 changes: 3 additions & 0 deletions startup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ module.allow_web_admin=${OMRS_MODULE_WEB_ADMIN}
EOF


# Supports any custom env variable with the OMRS_EXTRA_ prefix, which translates to a property without the
# OMRS_EXTRA_ prefix. The '_' is replaced with '.' and '__' with '_'.
EXTRA_VARS=(${!OMRS_EXTRA_@})
if [[ -n "${EXTRA_VARS+x}" ]]; then
EXTRA_PROPERTIES=""
Expand Down

0 comments on commit b1929d1

Please sign in to comment.