Skip to content

Commit

Permalink
ci(docker-nightly): move to separate build/publish from test (#1689)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGreatRefrigerator authored Feb 16, 2024
2 parents 3c9f57f + 0200279 commit 122298c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and publish the nightly Docker image
name: Build and test the Docker image
on:
pull_request:
types: [ opened, synchronize, ready_for_review ]
Expand All @@ -8,7 +8,6 @@ on:

env:
TEST_IMAGE_NAME: 'local/openrouteservice:test'
PRODUCTION_IMAGE_NAME: 'openrouteservice/openrouteservice:nightly'
BUILD_PLATFORMS: 'linux/amd64,linux/arm64/v8'


Expand All @@ -19,7 +18,6 @@ jobs:
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: |
Expand Down Expand Up @@ -47,7 +45,7 @@ jobs:
context: .
push: false
load: false
tags: ${{ needs.prepare_environment.outputs.test_image_name }}, ${{ needs.prepare_environment.outputs.production_image_name }}
tags: ${{ needs.prepare_environment.outputs.test_image_name }}
platforms: "${{ needs.prepare_environment.outputs.build_platforms }}"
cache-from: type=gha
cache-to: type=gha,mode=max
Expand Down Expand Up @@ -127,39 +125,3 @@ jobs:
./.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
87 changes: 87 additions & 0 deletions .github/workflows/docker-nightly-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Docker Nightly Image CI
run-name: Build ${{ inputs.branch }} - ${{ inputs.user }}

on:
schedule:
- cron: '15 1 * * *'
workflow_dispatch:
inputs:
repository:
description: 'GitHub repository to create image off.'
required: true
default: 'GIScience/openrouteservice'
branch:
description: 'GitHub branch to create image off.'
required: true
default: 'main'
tag:
description: 'Name of the docker tag to create.'
required: true
default: 'nightly'
ignore-24h-commit-check:
description: 'Build image regardless of last commit date.'
required: true
type: boolean
default: false
user:
description: ''
required: false
default: 'schedule'

jobs:
check-commits:
runs-on: ubuntu-latest
outputs:
new_commits: ${{ steps.check.outputs.NEW_COMMITS }}
steps:
- name: Checkout
uses: actions/[email protected]
with:
repository: ${{ inputs.repository || 'GIScience/openrouteservice' }}
ref: ${{ inputs.branch || 'main' }}

- name: Check for new commits since 24 h ago
id: check
run: |
export LOG_LINES=$(git log --oneline --since '24 hours ago')
export NUM_LINES=$(echo "$LOG_LINES" | grep -c .)
if [ "$NUM_LINES" -eq "0" ]; then
export NEW_COMMITS="false"
else
export NEW_COMMITS="true"
fi
echo "NEW_COMMITS=$NEW_COMMITS" >> "$GITHUB_OUTPUT"
build:
needs: check-commits
runs-on: ubuntu-latest
if: inputs.ignore-24h-commit-check || needs.check-commits.outputs.new_commits == 'true'
steps:
- name: Checkout
uses: actions/[email protected]
with:
repository: ${{ inputs.repository || 'GIScience/openrouteservice' }}
ref: ${{ inputs.branch || 'main' }}

- name: Set up QEMU
uses: docker/[email protected]

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Login to DockerHub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push
uses: docker/[email protected]
with:
context: .
platforms: linux/amd64,linux/arm64/v8
provenance: false
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ secrets.DOCKER_USERNAME }}/openrouteservice:${{ inputs.tag || 'nightly' }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ RELEASING:
- performance improvements to isochrone calculations ([#1607](https://github.com/GIScience/openrouteservice/pull/1607))
- do not apply speed penalty to roads tagged with "access=destination" when computing isochrones ([#1682](https://github.com/GIScience/openrouteservice/pull/1682))
- backend documentation overhaul ([#1651](https://github.com/GIScience/openrouteservice/pull/1651))
- separate docker image build from test workflow. Build nightly on schedule if there are changes to main ([#1689](https://github.com/GIScience/openrouteservice/pull/1689))

### Deprecated
- JSON configuration and related classes ([#1506](https://github.com/GIScience/openrouteservice/pull/1506))
Expand Down

0 comments on commit 122298c

Please sign in to comment.