Skip to content

Commit 390d324

Browse files
authored
Merge pull request #70 from kit-data-manager/dev_dockerize
Dockerization
2 parents 31b679d + 724edc2 commit 390d324

File tree

7 files changed

+277
-1
lines changed

7 files changed

+277
-1
lines changed

.dockerignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#git
2+
.git
3+
.gitattributes
4+
.gitignore
5+
.github/
6+
#IDE
7+
.idea
8+
#build
9+
.gradle/
10+
build
11+
#data
12+
production_db
13+
#misc
14+
CHANGELOG
15+
LICENSE
16+
temp
17+
docker
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Create and publish a Docker image
2+
3+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
4+
on:
5+
push:
6+
branches: ['main']
7+
8+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-and-push-image:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Log in to the Container registry
21+
uses: docker/login-action@v3
22+
with:
23+
registry: ${{ env.REGISTRY }}
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Extract metadata (tags, labels) for Docker
28+
id: meta
29+
uses: docker/metadata-action@v5
30+
with:
31+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
32+
33+
- name: Set up QEMU
34+
uses: docker/setup-qemu-action@v3
35+
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@v3
38+
39+
- name: Build and push Docker image
40+
uses: docker/build-push-action@v5
41+
with:
42+
context: ./docker
43+
push: true
44+
tags: ${{ steps.meta.outputs.tags }}
45+
labels: ${{ steps.meta.outputs.labels }}
46+
platforms: linux/amd64,linux/arm64
47+
48+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
49+
- name: Generate artifact attestation
50+
uses: actions/attest-build-provenance@v3
51+
with:
52+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
53+
subject-digest: ${{ steps.push.outputs.digest }}
54+
push-to-registry: true
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Build and Test Dockerized App
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches: [ main, development ]
7+
8+
jobs:
9+
build-and-test:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest]
14+
java: [17, 21]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up JDK ${{ matrix.java }}
21+
uses: actions/setup-java@v4
22+
with:
23+
distribution: 'temurin'
24+
java-version: ${{ matrix.java }}
25+
26+
- name: Grant execute permission for Gradle wrapper (Unix)
27+
if: runner.os != 'Windows'
28+
run: chmod +x gradlew
29+
30+
# Build Docker image instead of bootable JAR
31+
- name: Build Docker image
32+
run: |
33+
docker build -f docker/Dockerfile -t wap-server:${{ matrix.os }}-${{ matrix.java }} .
34+
35+
# Run Docker container (detached, expose port 8080)
36+
- name: Run Docker container
37+
run: |
38+
docker run -d -p 8080:8080 --name wap-server \
39+
wap-server:${{ matrix.os }}-${{ matrix.java }}
40+
echo "Wait for wap server to be healthy before proceeding to tests"
41+
while true; do
42+
docker ps -a
43+
if ! docker ps | grep -q wap-server; then
44+
echo "Docker container stopped unexpectedly. Aborting."
45+
exit 1
46+
fi
47+
if curl -f http://localhost:8080; then
48+
echo "Service is running."
49+
break
50+
fi
51+
echo "Waiting for the service to be ready..."
52+
docker logs --tail 20 wap-server
53+
sleep 5
54+
done
55+
56+
- name: hurl install
57+
uses: gacts/[email protected]
58+
with: {disable-cache: true}
59+
60+
- name: hurl CRUD tests (windows)
61+
if: runner.os == 'Windows'
62+
shell: bash
63+
run: |
64+
for file in ./integration_tests/CRUD/*.hurl; do
65+
hurl --variable host=http://localhost:8080 --test "$file" --verbose --error-format=long --continue-on-error --report-html hurlreports
66+
done
67+
68+
- name: hurl tests (other)
69+
if: runner.os != 'Windows'
70+
run: hurl --variable host=http://localhost:8080 --test ./integration_tests/CRUD/*.hurl --verbose --error-format=long --continue-on-error --report-html hurlreports
71+
72+
# Stop and clean up container
73+
- name: Stop Docker container
74+
if: always()
75+
run: |
76+
docker logs wap-server
77+
docker stop wap-server
78+
docker rm wap-server
79+
80+
# Upload artifacts (optional: you may want to upload Docker logs instead of JARs)
81+
- name: Upload Docker logs
82+
if: always()
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: docker_logs_jdk${{ matrix.java }}_${{ matrix.os }}
86+
path: ./hurlreports

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@ This project contains a server for creating and managing annotations based on th
77
the complete Web Annotation Protocol (WAP). The service is realized as microservice using Spring Boot and can be operated standalone.
88

99

10-
## How to build
10+
## How to build and use
11+
12+
### Docker
13+
14+
```
15+
docker build -f docker/Dockerfile -t wap-server .
16+
```
17+
18+
To run the application at `http://localhost:<host port>`, use:
19+
20+
```
21+
docker run -d -p <host port>:8080 -e WAPBASEPATH=http://localhost:<host port> wap-server
22+
```
23+
24+
### From source
1125

1226
To install the application from source, see [howtos](howtos/summary.md).
1327

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,7 @@ tasks.register('printProjectName') {
188188
println "${project.name}"
189189
}
190190
}
191+
192+
gradleLint {
193+
skipForTask('printProjectName')
194+
}

build.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
# Check no of parameters.
4+
if [ "$#" -ne 1 ]; then
5+
echo "Illegal number of parameters!"
6+
usage
7+
fi
8+
9+
INSTALLATION_DIRECTORY=$1
10+
ACTUAL_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
11+
12+
# Check if directory exists
13+
if [ ! -d "$INSTALLATION_DIRECTORY" ]; then
14+
# Create directory if it doesn't exists.
15+
mkdir -p "$INSTALLATION_DIRECTORY"
16+
if [ $? -ne 0 ]; then
17+
echo "Error creating directory '$INSTALLATION_DIRECTORY'!"
18+
echo "Please make sure that you have the correct access permissions for the specified directory."
19+
exit 1
20+
fi
21+
fi
22+
# Check if directory is empty
23+
if [ ! -z "$(ls -A "$INSTALLATION_DIRECTORY")" ]; then
24+
echo "Directory '$INSTALLATION_DIRECTORY' is not empty!"
25+
echo "Please enter an empty or a new directory!"
26+
exit 1
27+
fi
28+
# Convert variable of installation directory to an absolute path
29+
cd "$INSTALLATION_DIRECTORY"
30+
INSTALLATION_DIRECTORY=`pwd`
31+
cd "$ACTUAL_DIR"
32+
33+
APP_NAME=`./gradlew -q printProjectName`
34+
APP_NAME=${APP_NAME##*$'\n'}
35+
echo "$APP_NAME"
36+
37+
echo Build service...
38+
./gradlew -Dprofile=minimal clean build
39+
40+
echo "Copy jar file to '$INSTALLATION_DIRECTORY'..."
41+
find . -name "$APP_NAME.jar" -exec cp '{}' "$INSTALLATION_DIRECTORY" \;
42+
43+
# Create run script
44+
echo "$INSTALLATION_DIRECTORY"
45+
cd "$INSTALLATION_DIRECTORY"
46+
47+
# Determine name of jar file.
48+
jarFile=(`ls $APP_NAME.jar`)
49+
50+
java -jar $jarFile "--create-config"
51+
52+
echo '#!/bin/sh' >> run.sh
53+
echo 'pwd' >> run.sh
54+
echo 'ls' >> run.sh
55+
echo 'cat run.sh' >> run.sh
56+
echo "################################################################################" >> run.sh
57+
echo "# Define jar file" >> run.sh
58+
echo "################################################################################" >> run.sh
59+
echo jarFile=$jarFile >> run.sh
60+
echo " " >> run.sh
61+
echo "################################################################################" >> run.sh
62+
echo "# Start micro service" >> run.sh
63+
echo "################################################################################" >> run.sh
64+
echo 'java -jar $jarFile' >> run.sh
65+
66+
# make script executable
67+
chmod 755 run.sh

docker/Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM eclipse-temurin:17-jdk
2+
ARG SERVER_NAME_DEFAULT=wapserver
3+
4+
ARG PORT_DEFAULT=8080
5+
ARG SPARQ_DEFAULT=3330
6+
ARG HOST_DEFAULT=localhost
7+
ARG ROOT_DIRECTORY_DEFAULT=/spring
8+
9+
# Install git as additional requirement
10+
RUN apt-get -y update && \
11+
apt-get -y upgrade && \
12+
apt-get install -y --no-install-recommends git bash && \
13+
apt-get clean \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
ENV SERVICE_DIRECTORY=${ROOT_DIRECTORY_DEFAULT}/${SERVER_NAME_DEFAULT}
17+
RUN mkdir -p /git
18+
WORKDIR /git
19+
COPY .. .
20+
# Build service in given directory
21+
RUN echo $SERVICE_DIRECTORY
22+
RUN bash ./build.sh $SERVICE_DIRECTORY
23+
24+
#You can use this to set config variables or mount in an application.properties file
25+
ENV SPRING_APPLICATION_JSON "{\"WapPort\": ${PORT_DEFAULT}, \"Hostname\": \"${HOST_DEFAULT}\"}"
26+
27+
EXPOSE ${PORT_DEFAULT}
28+
EXPOSE ${SPARQL_DEFAULT}
29+
WORKDIR $SERVICE_DIRECTORY
30+
COPY ../profiles ./profiles/
31+
COPY ../schemas ./schemas/
32+
COPY ../webcontent ./webcontent/
33+
COPY ../doc ./doc/
34+
ENTRYPOINT ["/spring/wapserver/run.sh"]

0 commit comments

Comments
 (0)