Skip to content

Commit

Permalink
Merge pull request #3 from opensrp/dockerize-app
Browse files Browse the repository at this point in the history
Dockerize app
  • Loading branch information
dubdabasoduba authored May 17, 2022
2 parents 6b07f07 + 68fe926 commit e29d531
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 26 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Dockerfile
*.md
.git
/app/target/
/common/target/
/dhis/target/
/fhir/target/
/fhir-dstu3/target/
/fhir-r4/target/
/metadata-sheet/target/
/summary/target/
/.idea/
103 changes: 103 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Docker

on:
push:
# Publish `master` as Docker `master` tag.
# See also https://github.com/crazy-max/ghaction-docker-meta#basic
branches:
- master

# 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/[email protected]
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Buildx
uses: docker/[email protected]

- 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/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push to Docker Image Repositories
uses: docker/[email protected]
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 }}
24 changes: 24 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v1
with:
java-version: 8
- name: Build with Maven
run: mvn -B package -DskipTests --file pom.xml
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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-jre-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
26 changes: 0 additions & 26 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,6 @@

<plugins>

<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<configuration>
<dotGitDirectory>${project.basedir}/../.git</dotGitDirectory>
<prefix>git</prefix>
<verbose>false</verbose>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<dateFormat>yyyy-MM-dd'T'HH:mm:ss.SSSXXX</dateFormat>
<dateFormatTimeZone>UTC</dateFormatTimeZone>
<includeOnlyProperties>
<includeOnlyProperty>branch</includeOnlyProperty>
<includeOnlyProperty>commit.id</includeOnlyProperty>
<includeOnlyProperty>commit.time</includeOnlyProperty>
</includeOnlyProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand All @@ -161,13 +142,6 @@
</goals>
</execution>
</executions>
<configuration>
<additionalProperties>
<git.branch>${git.branch}</git.branch>
<git.commit.id>${git.commit.id}</git.commit.id>
<git.commit.time>${git.commit.time}</git.commit.time>
</additionalProperties>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
Expand Down

0 comments on commit e29d531

Please sign in to comment.