Skip to content

Commit

Permalink
Upgrading Docker setup\n* Updated Dockerfiles with multi-stage build\…
Browse files Browse the repository at this point in the history
…n*Created github action to publish binlog image
  • Loading branch information
pmanko committed Dec 16, 2021
1 parent 3c04db6 commit 5ff0966
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ on:
pull_request:
branches: [ master ]
workflow_dispatch:


env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:

build:
Expand All @@ -24,6 +28,7 @@ jobs:
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Log in to the Container registry
uses: docker/login-action@v1
with:
Expand All @@ -34,11 +39,10 @@ jobs:
- name: Publish Docker image
uses: docker/build-push-action@v2
with:
context: .
file: pipelines/streaming-binlog/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }},${{ env.REGISTRY }}/${{ steps.string.outputs.lowercase }}:${{steps.package-version.outputs.current-version}}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: NODE_AUTH_TOKEN=${{ secrets.NPM_TOKEN }}

2 changes: 1 addition & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ services:

streaming-binlog: # To run independently: docker-compose up --build streaming-binlog
build:
context: ../streaming-binlog
context: ../pipelines/streaming-binlog
image: openmrs-fhir-analytics/streaming-binlog:latest
container_name: streaming-pipeline
network_mode: host
Expand Down
33 changes: 22 additions & 11 deletions pipelines/streaming-atomfeed/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
FROM maven:3.6.3-openjdk-8
FROM adoptopenjdk/maven-openjdk8 as build

WORKDIR /app/openmrs-fhir-analytics
WORKDIR /app

COPY ./pom.xml /app/openmrs-fhir-analytics/pom.xml
COPY ./streaming-atomfeed/pom.xml /app/openmrs-fhir-analytics/streaming-atomfeed/pom.xml
COPY ./streaming-binlog/pom.xml /app/openmrs-fhir-analytics/streaming-binlog/pom.xml
COPY ./common/pom.xml /app/openmrs-fhir-analytics/common/pom.xml
COPY ./batch/pom.xml /app/openmrs-fhir-analytics/batch/pom.xml
# Selective Adds to Speed Up Build
ADD ../pipelines/common ./pipelines/common
ADD ../pipelines/streaming-binlog/pom.xml ./pipelines/streaming-binlog/pom.xml
ADD ../pipelines/batch/pom.xml ./pipelines/batch/pom.xml
ADD ../pipelines/streaming-atomfeed/pom.xml ./pipelines/streaming-atomfeed/pom.xml
ADD ../pipelines/batch/pom.xml ./pipelines/batch/pom.xml
ADD ../pipelines/pom.xml ./pipelines/pom.xml
ADD ../bunsen ./bunsen

RUN mvn -B -pl streaming-atomfeed -am verify --fail-never

COPY ./common /app/openmrs-fhir-analytics/common
COPY ./streaming-atomfeed /app/openmrs-fhir-analytics/streaming-atomfeed
COPY ./batch /app/openmrs-fhir-analytics/batch
COPY ./streaming-binlog /app/openmrs-fhir-analytics/streaming-binlog
ADD ../pipelines/streaming-atomfeed/src ./pipelines/streaming-atomfeed/src


RUN mvn -B install -DskipTests -Dlicense.skip=true -pl streaming-atomfeed -am

FROM adoptopenjdk/maven-openjdk8 as run

WORKDIR /app/openmrs-fhir-analytics

COPY --from=build /app/openmrs-fhir-analytics/pom.xml ${WORK_DIR}/pom.xml

RUN /bin/bash -l -c 'echo export POM_VERSION="$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout=true)" > /etc/profile.d/docker_init.sh'

COPY --from=build /app/openmrs-fhir-analytics/pipelines/streaming-atomfeed/target/streaming-atomfeed-bundled-${POM_VERSION}.jar /app.jar

ENV OPENMRS_URL=""
ENV OPENMRS_USERNAME=""
ENV OPENMRS_PASSWORD=""
Expand Down
37 changes: 33 additions & 4 deletions pipelines/streaming-binlog/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,40 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM adoptopenjdk/maven-openjdk8
# BUILD STAGE
FROM adoptopenjdk/maven-openjdk8 as build
WORKDIR "/usr/src"

ARG WORK_DIR="/usr/src/Main"
COPY target/streaming-binlog-bundled-0.1.0-SNAPSHOT.jar ${WORK_DIR}/app.jar
WORKDIR ${WORK_DIR}
# Selective Adds to Speed Up Build
ADD ../pipelines/common ./pipelines/common
ADD ../pipelines/streaming-binlog/src ./pipelines/streaming-binlog/src
ADD ../pipelines/streaming-binlog/pom.xml ./pipelines/streaming-binlog/pom.xml
ADD ../pipelines/batch/pom.xml ./pipelines/batch/pom.xml
ADD ../pipelines/streaming-atomfeed/pom.xml ./pipelines/streaming-atomfeed/pom.xml
ADD ../pipelines/batch/pom.xml ./pipelines/batch/pom.xml
ADD ../pipelines/pom.xml ./pipelines/pom.xml
ADD ../pipelines/license-format.xml ./pipelines/license-format.xml
ADD ../pipelines/license-header.txt ./pipelines/license-header.txt
ADD ../bunsen ./bunsen
ADD ../pom.xml ./

RUN mvn clean package -DskipTests -Dlicense.skip=true -pl pipelines/streaming-binlog -am -B -q

RUN /bin/bash -l -c 'echo echo "$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout=true)" > /etc/profile.d/pom_version.sh'

RUN chmod u+x /etc/profile.d/pom_version.sh

RUN POM_VERSION=`/etc/profile.d/pom_version.sh` && cp /usr/src/pipelines/streaming-binlog/target/streaming-binlog-bundled-$POM_VERSION.jar /usr/src/app.jar

# RUN STAGE
FROM adoptopenjdk/maven-openjdk8 as run

WORKDIR /usr/src

# Copy over JAR file
COPY --from=build /usr/src/app.jar app.jar

# Default ENV settings
ENV OPENMRS_URL="http://openmrs:8080/openmrs"
ENV OPENMRS_USERNAME="admin"
ENV OPENMRS_PASSWORD="Admin123"
Expand Down

0 comments on commit 5ff0966

Please sign in to comment.