Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Fully containerized build #179

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@

# Stage 0: Build image
FROM maven:3.8.3-jdk-8

ARG BACKEND_ROOT="WIPP-backend"
ARG BACKEND_APP="wipp-backend-application"
ARG BACKEND_DATA="wipp-backend-data"
ARG BACKEND_CORE="wipp-backend-core"
ARG BACKEND_ARGO="wipp-backend-argo-workflows"

COPY pom.xml /usr/local/${BACKEND_ROOT}/pom.xml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to define a WORKDIR (/opt for example) instead of copying folders to /usr/local/?

COPY ${BACKEND_NAME} /usr/local/${BACKEND_ROOT}/${BACKEND_NAME}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix typo. This should be BACKEND_APP instead of BACKEND_NAME

COPY ${BACKEND_DATA} /usr/local/${BACKEND_ROOT}/${BACKEND_DATA}
COPY ${BACKEND_CORE} /usr/local/${BACKEND_ROOT}/${BACKEND_CORE}
COPY ${BACKEND_ARGO} /usr/local/${BACKEND_ROOT}/${BACKEND_ARGO}
COPY deploy/docker/maven-settings.xml /usr/share/maven/conf/settings.xml
WORKDIR /usr/local/${BACKEND_ROOT}
RUN mvn clean package -P prod

# Stage 1: Runtime image
FROM openjdk:8-jdk-alpine
MAINTAINER National Institute of Standards and Technology
LABEL org.opencontainers.image.authors="National Institute of Standards and Technology"

EXPOSE 8080

ARG BACKEND_NAME="wipp-backend-application"
ARG BACKEND_ROOT="WIPP-backend"
ARG BACKEND_APP="wipp-backend-application"
ARG EXEC_DIR="/opt/wipp"
ARG DATA_DIR="/data/WIPP-plugins"
ARG ARGO_VERSION="v2.3.0"
Expand All @@ -24,8 +45,8 @@ RUN wget https://github.com/argoproj/argo-workflows/releases/download/${ARGO_VER
chmod +x argo-linux-amd64 && \
mv argo-linux-amd64 /usr/local/bin/argo

# Copy WIPP backend application exec WAR
COPY ${BACKEND_NAME}/target/${BACKEND_NAME}-*-exec.war ${EXEC_DIR}/wipp-backend.war
# Copy WIPP backend application exec WAR from the previous stage
COPY --from=0 /usr/local/${BACKEND_ROOT}/${BACKEND_APP}/target/${BACKEND_APP}-*-exec.war ${EXEC_DIR}/wipp-backend.war

# Copy properties and entrypoint script
COPY deploy/docker/application.properties ${EXEC_DIR}/config
Expand Down
38 changes: 38 additions & 0 deletions Dockerfile.localdev
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM openjdk:8-jdk-alpine
LABEL org.opencontainers.image.authors="National Institute of Standards and Technology"

EXPOSE 8080

ARG BACKEND_NAME="wipp-backend-application"
ARG EXEC_DIR="/opt/wipp"
ARG DATA_DIR="/data/WIPP-plugins"
ARG ARGO_VERSION="v2.3.0"
ARG APM_VERSION="1.9.0"

COPY deploy/docker/VERSION /VERSION

# Create exec and data folders
RUN mkdir -p \
${EXEC_DIR}/config \
${DATA_DIR}

# Download Elastic APM Java Agent
RUN wget https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/${APM_VERSION}/elastic-apm-agent-${APM_VERSION}.jar -O ${EXEC_DIR}/elastic-apm-agent.jar

# Install Argo CLI executable
RUN wget https://github.com/argoproj/argo-workflows/releases/download/${ARGO_VERSION}/argo-linux-amd64 && \
chmod +x argo-linux-amd64 && \
mv argo-linux-amd64 /usr/local/bin/argo

# Copy WIPP backend application exec WAR
COPY ${BACKEND_NAME}/target/${BACKEND_NAME}-*-exec.war ${EXEC_DIR}/wipp-backend.war

# Copy properties and entrypoint script
COPY deploy/docker/application.properties ${EXEC_DIR}/config
COPY deploy/docker/entrypoint.sh /usr/local/bin

# Set working directory
WORKDIR ${EXEC_DIR}

# Entrypoint
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,22 @@ mvn spring-boot:run
- http://localhost:8080/v2/api-docs (OpenAPI spec)

## Docker packaging
There are two ways to build Docker images for WIPP-backend:

- For local development, first compile the project (so it produces `wipp-backend-application/target/wipp-backend-application-...-exec.war`), then build Docker image from `Dockerfile.localdev`.

The Maven `prod` profile should be used for Docker packaging, even for testing/development purposes:
```sh
mvn clean package -P prod
docker build --no-cache -f Dockerfile.localdev . -t wipp_backend
```

- For CI builds or if you don't have Java/Maven installed on host, simply build Docker image from `Dockerfile`
```sh
docker build --no-cache . -t wipp_backend
```


For a Docker deployment of WIPP on a Kubernetes cluster, scripts and configuration files are available in the [WIPP repository](https://github.com/usnistgov/WIPP/tree/master/deployment).

## Deployment
Expand Down
15 changes: 15 additions & 0 deletions deploy/docker/maven-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>