Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate run tests at docker build #29

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,12 @@ jobs:
BUILD_VERSION=true
fi

curl -o fallback.oshdb.mv.db http://downloads.ohsome.org/v0.6/europe/germany/baden-wuerttemberg/heidelberg_68900_2020-07-23.oshdb.mv.db

echo ::set-output name=build_version::${BUILD_VERSION}
echo ::set-output name=buildx_args_version::--platform ${DOCKER_PLATFORMS} \
--build-arg OHSOMEAPI_VERSION=${DOCKER_VERSION} \
--build-arg FALLBACK_DATA_FILE=fallback.oshdb.mv.db \
${TAGS_VERSION} .
echo ::set-output name=buildx_args_latest::--platform ${DOCKER_PLATFORMS} \
--build-arg OHSOMEAPI_VERSION=latest \
--build-arg FALLBACK_DATA_FILE=fallback.oshdb.mv.db \
${TAGS_LATEST} .
- name: Build version if not present
if: ${{ steps.prepare.outputs.build_version == 'true' }}
Expand Down
35 changes: 32 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ name: Testing

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ "**" ]
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand All @@ -25,3 +23,34 @@ jobs:
uses: pre-commit/[email protected]
with:
extra_args: --all-files
test-docker-build:
needs:
- lint
name: Build docker image for testing
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
id: buildx
with:
install: true
- name: Prepare
id: prepare
run: |
DOCKER_IMAGE=dockertest/ohsome-api
DOCKER_PLATFORMS=linux/amd64

TAGS_LATEST="--tag ${DOCKER_IMAGE}:latest"

echo ::set-output name=buildx_args_latest::--platform ${DOCKER_PLATFORMS} \
--build-arg OHSOMEAPI_VERSION=latest \
${TAGS_LATEST} .
- name: Build latest
run: |
docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args_latest }}
28 changes: 14 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ ARG OHSOMEAPI_VERSION
WORKDIR /opt/app/

# System deps and get the ohsome-api repository data:
RUN apk add git bash maven && git clone https://github.com/GIScience/ohsome-api.git ./ && git fetch --all --tags
RUN apk add git bash maven \
&& if [ -z $OHSOMEAPI_VERSION ] || [ "$OHSOMEAPI_VERSION" = "latest" ] ; then echo Version not provided. Sticking to latest version. && export BRANCH_PARAMETER=""; else echo Version provided. Checkout $OHSOMEAPI_VERSION && export BRANCH_PARAMETER="-b $OHSOMEAPI_VERSION"; fi \
&& git clone https://github.com/GIScience/ohsome-api.git $BRANCH_PARAMETER --depth 1 .

COPY fallback_data/fallback.tar.xz /opt/app/

# Checkout version if provided
RUN if [ -z $OHSOMEAPI_VERSION ] || [ "$OHSOMEAPI_VERSION" = "latest" ] ; then echo Version not provided. Sticking to latest version.; else echo Version provided. Checkout $OHSOMEAPI_VERSION \
&& git checkout --quiet tags/$OHSOMEAPI_VERSION ; fi
RUN echo Extract the test data. \
&& tar -xf fallback.tar.xz \
&& rm -rf fallback.tar.xz

RUN echo Build and run the integration tests \
&& mvn -DskipTests=false -Dport_get=8081 -Dport_post=8082 -Dport_data=8083 -DdbFilePathProperty="--database.db=./fallback.oshdb.mv.db" package

# Make it executable
RUN mvn -DskipTests=true package

# 2. Preparation stage
FROM adoptopenjdk/openjdk11:jre-11.0.10_9-alpine as preparation-stage
Expand All @@ -26,18 +32,12 @@ WORKDIR /opt/
COPY --from=build-stage /opt/app/target/*.jar /opt/app/target/

# Copy the fallback data and entrypoint
COPY entrypoint.sh /opt/
COPY entrypoint.sh fallback_data/fallback.tar.xz /opt/

# Bootstrap the app os and compress the folder afterwards to reduce the image size.
RUN echo Prepare the app folder. \
&& apk add maven xz pv curl \
&& apk add maven xz \
MichaelsJP marked this conversation as resolved.
Show resolved Hide resolved
&& rm -rf /var/cache/apk/* \
&& echo Download the fallback database covering Heidelberg, Germany. \
&& curl -LJO https://github.com/MichaelsJP/ohsome-api-dockerized/raw/main/fallback_data/fallback.tar.xz \
&& echo Extract the fallback data. \
&& tar -xf fallback.tar.xz \
&& echo Copy the fallback data to the app folder. \
&& mv -f fallback.oshdb.mv.db /opt/app/ \
&& echo Copy the correct *.jar file to the app folder. \
&& mv /opt/app/target/*.jar /opt/app/ohsome-api.jar \
&& echo Remove unneeded folders. \
Expand All @@ -47,7 +47,7 @@ RUN echo Prepare the app folder. \
&& echo Compress the app folder at highest compression rate and with as much cores as possible. This may still take some time. \
&& tar -cf - app/ | xz -e -9 -T 0 -c - > app.tar.xz \
&& echo Clean the build environment from unneeded files. \
&& rm -rf app/ fallback.tar.xz \
&& rm -rf app/ \
&& echo Done!

# 3. Production stage
Expand Down
16 changes: 14 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,28 @@ elif ! [ -d "./app" ] && ! [ -f "./app.tar.xz" ]; then
exit
fi

if ! [ -f "./fallback.oshdb.mv.db" ] && [ -f "./fallback.tar.xz" ]; then
echo "===================================================="
echo "Fallback data still compressed. Decompressing it first."
echo "===================================================="
tar -xvf fallback.tar.xz
rm -rf fallback.tar.xz
else
echo "=================================================================================="
echo "No fallback data found. Skipping fallback setup"
echo "=================================================================================="
fi

if [ -f "./data/${DATA_FILE}" ]; then
echo "=================================================================="
echo "Custom database found. Using it instead of the fallback database."
echo "=================================================================="
java -jar app/ohsome-api.jar --database.db="./data/${DATA_FILE}"
elif [ -e "./app/fallback.oshdb.mv.db" ]; then
elif [ -e "./fallback.oshdb.mv.db" ]; then
echo "============================================================"
echo "No custom database found. Falling back to fallback database."
echo "============================================================"
java -jar app/ohsome-api.jar --database.db=./app/fallback.oshdb.mv.db
java -jar app/ohsome-api.jar --database.db=./fallback.oshdb.mv.db
else
echo "========================================================================"
echo "No custom database found and no fallback database initialized. Quitting."
Expand Down