From 53bbb853b523942a458ddf7a9e2003d9ddedcaac Mon Sep 17 00:00:00 2001 From: bennsimon Date: Thu, 7 Apr 2022 15:51:13 +0300 Subject: [PATCH 1/9] add Dockerfile and .dockerignore --- .dockerignore | 13 +++++++++++++ Dockerfile | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..92f3cf02 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +/docs/ +Dockerfile +*.md +.git +/app/target/ +/common/target/ +/dhis/target/ +/fhir/target/ +/fhir-dstu3/target/ +/fhir-r4/target/ +/metadata-sheet/target/ +/summary/target/ +/.idea/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..2db7367f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM maven:3-openjdk-8-slim AS build +WORKDIR /tmp/dhis2-fhir-adapter +ARG DHIS2_HOME=/app + +COPY . /tmp/dhis2-fhir-adapter + +# create package +RUN mvn clean package -DskipTests + +# create DHIS2_HOME/services/fhir-adapter configuration folder here https://github.com/opensrp/dhis2-fhir-adapter#configuration +RUN mkdir -p ${DHIS2_HOME}/services/fhir-adapter \ + && cp /tmp/dhis2-fhir-adapter/app/target/dhis2-fhir-adapter.war ${DHIS2_HOME}/main.war + +FROM openjdk:8-jdk-slim AS deploy + +# specify the DHIS2_HOME environment variable +ENV DHIS2_HOME=/app + +# create opensrp user +ARG UID=10001 +ARG GID=${UID} +RUN groupadd -g ${GID} opensrp \ + && useradd -u ${UID} -g ${GID} opensrp + +COPY --chown=opensrp:opensrp --from=build ${DHIS2_HOME} ${DHIS2_HOME} + +USER opensrp + +WORKDIR ${DHIS2_HOME} + +CMD java -jar ${DHIS2_HOME}/main.war From 40b7a97c74822edd90e5396e74b2f85292784d7c Mon Sep 17 00:00:00 2001 From: bennsimon Date: Thu, 7 Apr 2022 15:51:44 +0300 Subject: [PATCH 2/9] add docker and maven workflows --- .github/workflows/docker-publish.yml | 104 +++++++++++++++++++++++++++ .github/workflows/maven.yml | 25 +++++++ 2 files changed, 129 insertions(+) create mode 100644 .github/workflows/docker-publish.yml create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 00000000..650d4509 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,104 @@ +name: Docker + +on: + push: + # Publish `master` as Docker `master` tag. + # See also https://github.com/crazy-max/ghaction-docker-meta#basic + branches: + - master + - dockerize-app + + # Publish `v1.2.3` tags as releases. + tags: + - v* + + pull_request: + # Run Tests when changes are made to the Docker file + paths: + - 'Dockerfile' + + workflow_dispatch: + inputs: + customTag: + description: "Includes the specified tag to docker image tags" + required: false + +jobs: + # Run image build test + test: + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Run Build tests + run: docker build . --file Dockerfile + + push: + runs-on: ubuntu-latest + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' + + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2.1.6 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1.3.0 + + - name: Docker meta + id: docker_meta + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: opensrp/dhis2-fhir-adapter + tag-custom: ${{ github.event.inputs.customTag }} + + - name: Login to DockerHub + uses: docker/login-action@v1.10.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1.10.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Push to Docker Image Repositories + uses: docker/build-push-action@v2.5.0 + id: docker_build + with: + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ${{ steps.docker_meta.outputs.tags }} + ghcr.io/${{ steps.docker_meta.outputs.tags }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 00000000..435d58b3 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,25 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: + - '**' + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Build with Maven + run: mvn -B package --file pom.xml From 2add21d0b5fa5c0f4fd0f44db8ea35ab563d0c66 Mon Sep 17 00:00:00 2001 From: bennsimon Date: Thu, 7 Apr 2022 15:54:03 +0300 Subject: [PATCH 3/9] remove maven git plugin (.git is ignored in docker images) --- app/pom.xml | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/app/pom.xml b/app/pom.xml index bb203037..5befea36 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -132,25 +132,6 @@ - - pl.project13.maven - git-commit-id-plugin - - ${project.basedir}/../.git - git - false - true - ${project.build.outputDirectory}/git.properties - false - yyyy-MM-dd'T'HH:mm:ss.SSSXXX - UTC - - branch - commit.id - commit.time - - - org.springframework.boot spring-boot-maven-plugin @@ -161,13 +142,6 @@ - - - ${git.branch} - ${git.commit.id} - ${git.commit.time} - - maven-war-plugin From 2da0450cbeecf72784d2b7f7926e556a4eba0795 Mon Sep 17 00:00:00 2001 From: bennsimon Date: Thu, 7 Apr 2022 16:02:40 +0300 Subject: [PATCH 4/9] skip tests on maven workflow --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 435d58b3..38e19d60 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -22,4 +22,4 @@ jobs: with: java-version: 11 - name: Build with Maven - run: mvn -B package --file pom.xml + run: mvn -B package -DskipTests --file pom.xml From 4443d122989687c548759dcf3bca31d33ac4d644 Mon Sep 17 00:00:00 2001 From: bennsimon Date: Thu, 7 Apr 2022 16:10:54 +0300 Subject: [PATCH 5/9] use java 8 --- .github/workflows/maven.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 38e19d60..7d16ed8b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -5,8 +5,7 @@ name: Java CI with Maven on: push: - branches: - - '**' + branches: [ master ] pull_request: branches: [ master ] @@ -17,9 +16,9 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 8 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 8 - name: Build with Maven run: mvn -B package -DskipTests --file pom.xml From 898f046d9b95c9906b15400d7c8ddd9d40a98d16 Mon Sep 17 00:00:00 2001 From: bennsimon Date: Fri, 8 Apr 2022 09:06:53 +0300 Subject: [PATCH 6/9] replace jdk with jre image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2db7367f..7888f133 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN mvn clean package -DskipTests RUN mkdir -p ${DHIS2_HOME}/services/fhir-adapter \ && cp /tmp/dhis2-fhir-adapter/app/target/dhis2-fhir-adapter.war ${DHIS2_HOME}/main.war -FROM openjdk:8-jdk-slim AS deploy +FROM openjdk:8-jre-slim AS deploy # specify the DHIS2_HOME environment variable ENV DHIS2_HOME=/app From ffd057716faa6b14d1e7224b80f26e17ee43c67a Mon Sep 17 00:00:00 2001 From: bennsimon Date: Mon, 11 Apr 2022 12:15:00 +0300 Subject: [PATCH 7/9] trigger workflow From 1d49e72157c5b699fd9674ba11cffbf14c7efe87 Mon Sep 17 00:00:00 2001 From: bennsimon Date: Wed, 13 Apr 2022 16:08:20 +0300 Subject: [PATCH 8/9] remove docs folder from dockerignore --- .dockerignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.dockerignore b/.dockerignore index 92f3cf02..92e9e8c4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ -/docs/ Dockerfile *.md .git From 68fe92618ab8ad856311931d014b00d42abe10b0 Mon Sep 17 00:00:00 2001 From: bennsimon Date: Wed, 13 Apr 2022 18:55:47 +0300 Subject: [PATCH 9/9] remove test branch --- .github/workflows/docker-publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 650d4509..3cbb9d90 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -6,7 +6,6 @@ on: # See also https://github.com/crazy-max/ghaction-docker-meta#basic branches: - master - - dockerize-app # Publish `v1.2.3` tags as releases. tags: