From 5ff09666b1a01dcb02a9dbf4727f72d1f5db1efa Mon Sep 17 00:00:00 2001 From: pmanko Date: Wed, 15 Dec 2021 22:05:59 -0800 Subject: [PATCH] Upgrading Docker setup\n* Updated Dockerfiles with multi-stage build\n*Created github action to publish binlog image --- .github/workflows/docker-image.yml | 12 +++++--- docker/docker-compose.yaml | 2 +- pipelines/streaming-atomfeed/Dockerfile | 33 ++++++++++++++-------- pipelines/streaming-binlog/Dockerfile | 37 ++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index a86a56f2e..5046b3297 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -6,7 +6,11 @@ on: pull_request: branches: [ master ] workflow_dispatch: - + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: build: @@ -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: @@ -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 }} diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index cd494a1ae..e729e0944 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -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 diff --git a/pipelines/streaming-atomfeed/Dockerfile b/pipelines/streaming-atomfeed/Dockerfile index ab53ef860..41232c407 100644 --- a/pipelines/streaming-atomfeed/Dockerfile +++ b/pipelines/streaming-atomfeed/Dockerfile @@ -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="" diff --git a/pipelines/streaming-binlog/Dockerfile b/pipelines/streaming-binlog/Dockerfile index 2790e449e..8222bbf72 100644 --- a/pipelines/streaming-binlog/Dockerfile +++ b/pipelines/streaming-binlog/Dockerfile @@ -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"