Skip to content

Commit

Permalink
fix(docker): Repair the docker setup
Browse files Browse the repository at this point in the history
The docker setup is broken since the config migration and other changes.
This also adds a health check of the container at the default port 8082.
This also removes the old config migration notice. The notice is not necessary anymore for the next release.
  • Loading branch information
MichaelsJP committed Nov 24, 2024
1 parent b385f7b commit 2c9b937
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions .github/workflows/docker-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
workflow_dispatch:

env:
TEST_IMAGE_NAME: 'local/openrouteservice:latest'
TEST_IMAGE_NAME: 'local/openrouteservice:test'
BUILD_PLATFORMS: 'linux/amd64,linux/arm64'


Expand Down Expand Up @@ -37,6 +37,10 @@ jobs:
echo "UID=$(id -u)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ needs.prepare_environment.outputs.build_platforms }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up JDK 17
id: setup-java
uses: actions/setup-java@v4
Expand All @@ -49,8 +53,6 @@ jobs:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Prepare the maven cache dependencies
run: |
echo "Sync the maven dependencies"
Expand All @@ -65,10 +67,9 @@ jobs:
"/home/runner/.m2": "/root/.m2"
}
- name: Build image for platforms ${{ needs.prepare_environment.outputs.build_platforms }}
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
build-args: UID=${{ env.UID }}
push: false
load: false
tags: ${{ needs.prepare_environment.outputs.test_image_name }}
Expand Down Expand Up @@ -113,6 +114,7 @@ jobs:
echo "HEALTH_WAIT_TIME=260" >> $GITHUB_ENV
fi
- name: Set up QEMU for ${{ matrix.platform }}
if: ${{ matrix.platform == 'linux/arm64' }}
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform }}
Expand All @@ -136,7 +138,7 @@ jobs:
"/home/runner/.m2": "/root/.m2"
}
- name: Build image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
build-args: UID=${{ env.UID }}
Expand All @@ -147,42 +149,42 @@ jobs:
cache-from: type=gha
- name: Start container from previously build image and wait for successful checks
run: |
mkdir -p $(pwd)/graphs $(pwd)/config ./ors-docker/elevation_cache
chown -R $UID $(pwd)/graphs $(pwd)/config ./ors-docker ./ors-docker/elevation_cache
mkdir -p $(pwd)/ors-docker/graphs $(pwd)/ors-docker/config $(pwd)/ors-docker/elevation_cache
chown -R $UID $(pwd)/ors-docker/graphs $(pwd)/ors-docker/config $(pwd)/ors-docker $(pwd)/ors-docker/elevation_cache
# Place cached elevation file where docker compose expects it to mount into the image
cp ors-api/src/test/files/elevation/srtm_38_03.gh ./ors-docker/elevation_cache
cp ors-api/src/test/files/elevation/srtm_38_03.gh $(pwd)/ors-docker/elevation_cache
# Replace image: in the docker-compose.yml with the test image. The value of image: can vary.
sed -i "s|image:.*|image: ${{ needs.prepare_environment.outputs.test_image_name }}|" docker-compose.yml
sed -i "s|#logging.level.org.heigit: INFO|logging.level.org.heigit: DEBUG|" docker-compose.yml
# Start the first build with the docker-compose setup
docker compose up -d
# Wait for all logs to come in
sleep 5
docker compose logs ors-app
./.github/utils/url_check.sh 127.0.0.1 8080 /ors/v2/health 200 ${{ env.HEALTH_WAIT_TIME }}
# Check for health to turn 200 after the graphs are build and spring-boot completely started
./.github/utils/url_check.sh 127.0.0.1 8080 /ors/v2/health 200 ${{ env.HEALTH_WAIT_TIME }}
# Stop the compose setup and continue with docker run
docker compose down
# Set graphs data access to MMAPP
sudo yq '.ors.engine.graphs_data_access = "MMAP"' -i $(pwd)/ors-docker/config/ors-config.yml
# Start the container with the test image and the raw docker run command
docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/config:/home/ors/config -v $(pwd)/ors-api/src/test/files/elevation:/home/ors/elevation_cache --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }}
docker run -it -d -p 8080:8082 -v $(pwd)/ors-docker/graphs:/home/ors/graphs -v $(pwd)/ors-docker/config:/home/ors/config -v $(pwd)/ors-api/src/test/files/elevation:/home/ors/elevation_cache --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }}
# Check for health to turn 200 after the graphs are build and spring-boot completely started
./.github/utils/url_check.sh 127.0.0.1 8080 /ors/v2/health 200 ${{ env.HEALTH_WAIT_TIME }}
# Check for correct preflight settings to avoid CORS issues with ORIGIN wildcard from the example config
./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 10
./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.com" 200 10
echo "Adjust the config file and set ORIGIN to https://example.org"
sudo yq '.ors.cors.allowed_origins = "https://example.org, https://test.com, http://localhost:8080"' -i $(pwd)/config/ors-config.yml
sudo yq '.ors.cors.allowed_origins = "https://example.org, https://test.com, http://localhost:8080"' -i $(pwd)/ors-docker/config/ors-config.yml
# Restart the container to apply the config changes
docker restart ors-instance
# Request preflight with https://example.com and https://example.org to see if it gets applied correctly
./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 50
# If matrix platform is arm64, the health check will take longer
./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 ${{ env.HEALTH_WAIT_TIME }}
# It should fail with http code 403 for https://example.com since the Origin is not covered.
./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.com" 403 10
echo "Recreate the container to test if the graph can be properly read again"
docker stop ors-instance
docker container prune -f
chown -R $UID $(pwd)/graphs $(pwd)/config
docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/config:/home/ors/config -e ors.cors.allowed_origins=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }}
docker run -it -d -p 8080:8082 -v $(pwd)/ors-docker/graphs:/home/ors/graphs -v $(pwd)/ors-docker/config:/home/ors/config -e ors.cors.allowed_origins=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }}
# Request preflight with https://example.com and https://example.org to see if it gets applied correctly
./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 50
./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 ${{ env.HEALTH_WAIT_TIME }}
# It should fail with http code 403 for https://example.com since the Origin is not covered.
./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.com" 403 10

0 comments on commit 2c9b937

Please sign in to comment.