Skip to content

Flowmotion Pipeline #8843

Flowmotion Pipeline

Flowmotion Pipeline #8843

Workflow file for this run

#
# Flowmotion
# Pipeline
# Scheduled Workflow
#
name: Flowmotion Pipeline
on:
schedule:
# run every 10 minutes
- cron: "*/10 * * * *"
permissions:
# needed to push docker images to GHCR
packages: write
jobs:
run-pipeline:
name: Run Flowmotion Pipeline
env:
OSRM_IMAGE: ghcr.io/zhixin18/flowmotion/osrm-congestion
runs-on: ubuntu-22.04
steps:
# setup dependencies & source code
- uses: actions/checkout@v4
- name: Install osmium CLI with APT
run: sudo apt-get update && sudo apt-get install -y osmium-tool
- uses: actions/setup-python@v5
with:
python-version: "3.10.13"
- name: Cache Pip dependencies
id: cache-pip
uses: actions/cache@v3
with:
path: venv
key: pip-${{ hashFiles('pipeline/requirements.txt') }}
- name: Install Pip dependencies
if: steps.cache-pip.outputs.cache-hit != 'true'
run: |
set -ex -o pipefail
python -m venv venv
source venv/bin/activate
pip install -r pipeline/requirements.txt
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}"
# run congestion model to rate congestion points
- name: Run Congestion Model Pipeline
run: source venv/bin/activate && python pipeline/pipeline.py
# download & customize OSM map data with congestion ratings
- name: Cache OSM Map Data
id: cache-map
uses: actions/cache@v3
with:
path: map_bbox.osm.pbf
key: map-${{ hashFiles('.github/workflows/pipeline.yaml') }}
- name: Download & Extract OSM Map data
if: ${{ steps.cache-map.outputs.cache-hit != 'true' }}
run: |
set -ex -o pipefail
# download map data
curl https://download.geofabrik.de/asia/malaysia-singapore-brunei-latest.osm.pbf -o map.osm.pbf
# limit map data to bounding box for singapore to speed up processing
osmium extract --bbox=103.590088,1.210466,104.037094,1.475438 map.osm.pbf -o map_bbox.osm.pbf
- name: Tag OSM Map Data with Congestion Ratings
run: source venv/bin/activate && python pipeline/tag.py map_bbox.osm.pbf osrm/map_tagged.osm.pbf
# publish OSRM container with custom congestion profile
- name: Docker Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate OSRM container tags
id: osrm-meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: ${{ env.OSRM_IMAGE }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build and Push OSRM with Custom Congestion Profile
id: osrm-build
uses: docker/build-push-action@v6
with:
push: true
context: osrm
tags: ${{ steps.osrm-meta.outputs.tags }}
labels: ${{ steps.osrm-meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.OSRM_IMAGE }}:buildcache
cache-to: type=registry,ref=${{ env.OSRM_IMAGE }}:buildcache,mode=max
# deploy custom OSRM container
- name: Deploy custom OSRM container to GCP Cloud run
if: github.ref == 'refs/heads/master'
run: |
gcloud run deploy osrm-congestion \
--image asia-southeast1-docker.pkg.dev/flowmotion-4e268/ghcr/zhixin18/flowmotion/osrm-congestion@${{ steps.osrm-build.outputs.imageid }} \
--platform managed \
--region=asia-southeast1 \
--allow-unauthenticated \
--port 5000 \
--cpu 1 \
--memory 1Gi \
--cpu-boost