-
Notifications
You must be signed in to change notification settings - Fork 403
166 lines (163 loc) · 6.6 KB
/
build-and-publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: Build and publish the nightly Docker image
on:
pull_request:
branches: [ "main" ]
types: [ opened, synchronize, ready_for_review ]
push:
branches: [ "main" ]
workflow_dispatch:
env:
TEST_IMAGE_NAME: 'local/openrouteservice:test'
PRODUCTION_IMAGE_NAME: 'openrouteservice/openrouteservice:nightly'
BUILD_PLATFORMS: 'linux/amd64,linux/arm64/v8'
jobs:
# This way the env variables are accessible in the individual jobs
prepare_environment:
name: Prepare the environment variables
runs-on: ubuntu-latest
outputs:
test_image_name: ${{ env.TEST_IMAGE_NAME }}
production_image_name: ${{ env.PRODUCTION_IMAGE_NAME }}
build_platforms: ${{ env.BUILD_PLATFORMS }}
steps:
- run: |
echo "Publish environment variables"
build_docker_images:
name: Build the docker images
runs-on: ubuntu-latest
needs:
- prepare_environment
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
id: buildx
with:
install: true
- name: Build image for platforms ${{ needs.prepare_environment.outputs.build_platforms }}
uses: docker/build-push-action@v4
with:
context: .
push: false
load: false
tags: ${{ needs.prepare_environment.outputs.test_image_name }}, ${{ needs.prepare_environment.outputs.production_image_name }}
platforms: "${{ needs.prepare_environment.outputs.build_platforms }}"
cache-from: type=gha
cache-to: type=gha,mode=max
run_docker_image_tests:
name: Run & test ${{ matrix.platform }}
runs-on: ${{ matrix.image }}
needs:
- prepare_environment
- build_docker_images
strategy:
matrix:
platform: [ linux/amd64,linux/arm64/v8 ]
image: [ ubuntu-latest ]
# linux/arm64/v8 is emulated with qemu and takes ages to build the graph.
# Only run linux/arm64/v8 tests on ready PR and main.
isDraftPR:
- ${{ github.event_name == 'pull_request' && github.event.pull_request.draft == true }}
exclude:
- isDraftPR: true
platform: linux/arm64/v8
steps:
- run: |
echo "Run docker test for platform ${{ matrix.platform }}"
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set the wait time for arm64
run: |
if [[ "${{ matrix.platform }}" == 'linux/arm64/v8' ]]; then
# arm64 is emulated and takes longer to build the graph
echo "Set HEALTH_WAIT_TIME to 600 for arm64"
echo "HEALTH_WAIT_TIME=600" >> $GITHUB_ENV
else
echo "Set HEALTH_WAIT_TIME to 260 for non-arm64"
echo "HEALTH_WAIT_TIME=260" >> $GITHUB_ENV
fi
- name: Set up QEMU for ${{ matrix.platform }}
uses: docker/setup-qemu-action@v2
with:
platforms: ${{ matrix.platform }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
id: buildx
with:
install: true
- name: Install jq
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq moreutils
version: 1.0
- name: Build image
uses: docker/build-push-action@v4
with:
context: .
push: false
load: true
tags: ${{ needs.prepare_environment.outputs.test_image_name }}
platforms: "${{ matrix.platform }}"
cache-from: type=gha
- name: Start container from previously build image and wait for successful checks
run: |
mkdir $(pwd)/graphs $(pwd)/conf
sudo chown 1000:1000 $(pwd)/graphs $(pwd)/conf
docker run -it -d -p 8080:8080 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }}
docker logs ors-instance
# 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
# Restart the container to apply the config changes
docker stop ors-instance
docker container prune -f
docker run -it -d -p 8080:8080 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf -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
# 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
publish_docker:
name: Publish the docker image to docker hub
runs-on: ubuntu-latest
needs:
- prepare_environment
- build_docker_images
- run_docker_image_tests
steps:
- run: |
echo "Publish image ${{ needs.prepare_environment.outputs.production_image_name }}"
- 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@v2
id: buildx
with:
install: true
- name: Login to DockerHub
if: ${{ success() && github.ref == 'refs/heads/main' }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Publish nightly
if: ${{ github.ref == 'refs/heads/main' }}
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ needs.prepare_environment.outputs.production_image_name }}
platforms: "${{ needs.prepare_environment.outputs.build_platforms }}"
cache-from: type=gha