Skip to content

Commit db83ab0

Browse files
authored
Merge pull request #7 from sharedRDM/6-instance-jku
Add JKU instance and improve Docker configuration
2 parents 849b897 + 87e775e commit db83ab0

9 files changed

Lines changed: 715 additions & 30 deletions

File tree

.github/workflows/instances.yml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ on:
2121
type: choice
2222
description: 'Choose the backend instance'
2323
options:
24-
- both
25-
- MUG
2624
- TUG
25+
- MUG
26+
- JKU
2727
required: false
28-
default: both
28+
default: 'TUG'
2929

3030
jobs:
3131
build-backend-mug:
@@ -128,3 +128,52 @@ jobs:
128128
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }}-tug
129129
labels: ${{ steps.meta.outputs.labels }}
130130

131+
build-backend-jku:
132+
runs-on: ubuntu-22.04
133+
if: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.instance == 'both' || github.event.inputs.instance == 'JKU' }}
134+
permissions:
135+
contents: read
136+
packages: write
137+
138+
steps:
139+
- name: Checkout
140+
uses: actions/checkout@v3
141+
with:
142+
ref: ${{ github.event.inputs.branch || github.ref }}
143+
144+
- name: Convert repository name to lowercase
145+
run: echo "IMAGE_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
146+
147+
- name: Determine Docker tag (from tag or branch)
148+
id: get_tag
149+
run: |
150+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
151+
TAG_NAME="${GITHUB_REF#refs/tags/}"
152+
else
153+
TAG_NAME="${GITHUB_REF#refs/heads/}"
154+
fi
155+
echo "DOCKER_TAG=$TAG_NAME" >> $GITHUB_ENV
156+
157+
- name: Log in to the Container registry
158+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
159+
with:
160+
registry: ${{ env.REGISTRY }}
161+
username: ${{ github.actor }}
162+
password: ${{ secrets.GITHUB_TOKEN }}
163+
164+
- name: Extract metadata (tags, labels) for Docker
165+
id: meta
166+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
167+
with:
168+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
169+
170+
- name: Build and push JKU Docker image
171+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
172+
with:
173+
context: .
174+
push: true
175+
build-args: |
176+
INSTANCE_NAME=JKU
177+
tags: |
178+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }}-jku
179+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,75 @@
11
# syntax=docker/dockerfile:1
2-
3-
# the runner is built
2+
#==============================================================================
3+
# STAGE 1: BUILD STAGE
4+
# Build the application using Maven in an Alpine-based container
5+
#==============================================================================
46
FROM maven:3.9.5-eclipse-temurin-17-alpine AS builder
57

68
ARG BUILD_HOME=/home/app
79
ARG BUILD_PROFILE=postgres
810

9-
# Name of the directory
11+
# instance configuration: JKU, MUG, TUG
1012
ARG INSTANCE_NAME
1113

12-
RUN mkdir $BUILD_HOME && mkdir -p $BUILD_HOME/.m2/repository && chown -R 1000:0 $BUILD_HOME
14+
# build directories with proper permissions for non-root user
15+
RUN mkdir $BUILD_HOME && \
16+
mkdir -p $BUILD_HOME/.m2/repository && \
17+
chown -R 1000:0 $BUILD_HOME
18+
19+
# Switch to non-root user for security
1320
USER 1000
1421
WORKDIR $BUILD_HOME
1522

23+
# copies from instances/${INSTANCE_NAME}/ directory
1624
COPY instances/${INSTANCE_NAME}/src ./src
1725
COPY instances/${INSTANCE_NAME}/pom.xml .
1826

27+
# Maven repository volume for caching dependencies
1928
VOLUME ["/home/app/.m2/repository"]
29+
30+
# build the application
2031
RUN mvn -Duser.home=$BUILD_HOME -B package -DskipTests -Dquarkus.profile=${BUILD_PROFILE}
2132

22-
# Create a second stage container which will only contain the runtime binaries without build dependencies
33+
#==============================================================================
34+
# STAGE 2: RUNTIME STAGE
35+
# Create a lightweight container with only the required dependencies to run the app
36+
#==============================================================================
2337
FROM rockylinux:8.5 AS runner
2438

2539
ARG JAVA_PACKAGE=java-17-openjdk-headless
2640
ARG RUN_JAVA_VERSION=1.3.8
27-
28-
# path to copy built binaries from builder container
2941
ARG BUILD_HOME=/home/app
3042

3143
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'
3244

33-
# install java and the run-java script and set up permissions for the unprivileged 1001 container user
34-
RUN dnf install -y openssl tzdata-java curl ca-certificates ${JAVA_PACKAGE} \
35-
&& dnf clean all -y \
36-
&& mkdir /deployments \
37-
&& chown 1001 /deployments \
38-
&& chmod "g+rwX" /deployments \
39-
&& chown 1001:root /deployments \
40-
&& curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \
41-
&& chown 1001 /deployments/run-java.sh \
42-
&& chmod 540 /deployments/run-java.sh \
43-
&& echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security
44-
45-
# configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size.
45+
# install runtime dependencies and set up deployment directory
46+
RUN dnf install -y openssl tzdata-java curl ca-certificates ${JAVA_PACKAGE} && \
47+
dnf clean all -y && \
48+
# Create deployment directory with proper permissions
49+
mkdir /deployments && \
50+
chown 1001 /deployments && \
51+
chmod "g+rwX" /deployments && \
52+
chown 1001:root /deployments && \
53+
# Download and install run-java script for optimized JVM startup
54+
curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh && \
55+
chown 1001 /deployments/run-java.sh && \
56+
chmod 540 /deployments/run-java.sh && \
57+
# Optimize JVM random number generation for faster startup
58+
echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security
59+
60+
# configure JVM options for Quarkus application
4661
ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Duser.home=/deployments"
4762

48-
# copy runtime binaries to /deployments folder on runner container, the run-java script will pick this up
49-
# and start the application
63+
# copy compiled application from builder stage
5064
COPY --from=builder $BUILD_HOME/target/quarkus-app/lib/ /deployments/lib/
5165
COPY --from=builder $BUILD_HOME/target/quarkus-app/*.jar /deployments/
5266
COPY --from=builder $BUILD_HOME/target/quarkus-app/app/ /deployments/app/
5367
COPY --from=builder $BUILD_HOME/target/quarkus-app/quarkus/ /deployments/quarkus/
5468

69+
# expose application port
5570
EXPOSE 8080
5671

57-
# for Openshift based unprivilegued Kubernetes environments, we will set the user to 1001
72+
# user 1001 is standard for OpenShift and Kubernetes environments
5873
USER 1001
5974

6075
ENTRYPOINT [ "/deployments/run-java.sh" ]

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@ This repository manages DAMAP backend deployments for different institutions usi
66

77
- **TUG** - Graz University of Technology
88
- **MUG** - Medical University of Graz
9+
- **JKU** - Johannes Kepler University Linz
910

1011
## Structure
1112

1213
```
1314
instances/
1415
├── TUG/
15-
│ ├── src/ # TUG-specific source code
16+
│ ├── src/
1617
│ │ ├── main/java/at/tugraz/damap/...
1718
│ │ └── main/resources/...
18-
│ └── pom.xml # TUG Maven configuration
19+
│ └── pom.xml
1920
├── MUG/
20-
│ ├── src/ # MUG-specific source code
21+
│ ├── src/
2122
│ │ ├── main/java/at/medunigraz/damap/...
2223
│ │ └── main/resources/...
23-
│ └── pom.xml # MUG Maven configuration
24+
│ └── pom.xml
25+
├── JKU/
26+
│ ├── src/
27+
│ │ ├── main/java/at/jku/damap/...
28+
│ │ └── main/resources/...
29+
│ └── pom.xml
2430
```
2531

2632
## Usage
@@ -34,6 +40,9 @@ docker build --build-arg INSTANCE_NAME=TUG -t damap-backend-tug .
3440

3541
# Build MUG backend
3642
docker build --build-arg INSTANCE_NAME=MUG -t damap-backend-mug .
43+
44+
# Build JKU backend
45+
docker build --build-arg INSTANCE_NAME=JKU -t damap-backend-jku .
3746
```
3847

3948
**On Mac (ARM64/M1/M2):**
@@ -43,5 +52,8 @@ docker build --platform linux/amd64 --build-arg INSTANCE_NAME=TUG -t damap-backe
4352

4453
# Build MUG backend
4554
docker build --platform linux/amd64 --build-arg INSTANCE_NAME=MUG -t damap-backend-mug .
55+
56+
# Build JKU backend
57+
docker build --platform linux/amd64 --build-arg INSTANCE_NAME=JKU -t damap-backend-jku .
4658
```
4759

0 commit comments

Comments
 (0)