Skip to content

Commit

Permalink
feat: add osm-sync job, add external_id and location_geo to changing …
Browse files Browse the repository at this point in the history
…room

Adds new sync job to pull data from OpenStreetMap, and add new fields
to ChangingRoom doc to support this.
Updates room-api and review-api accordingly.
  • Loading branch information
christianfosli committed Nov 21, 2024
1 parent f96ed27 commit a0a7b71
Show file tree
Hide file tree
Showing 17 changed files with 3,318 additions and 16 deletions.
117 changes: 117 additions & 0 deletions .github/workflows/osm-sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: osm-sync-job-cicd

on:
push:
paths:
- osm-sync/**
- .github/workflows/osm-sync.yaml
- scripts/az-bootstrap-containerapp-job.bash
workflow_dispatch:

permissions:
# required for federated credentials to access azure
id-token: write
# required for federated credentials to access azure
contents: read
# required to push to ghcr
packages: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Login to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build
run: |
tags="-t ghcr.io/christianfosli/stellerom/osm-sync:${{ github.sha }}"
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
printf 'Banch is main! Tagging with latest\n'
tags="$tags -t ghcr.io/christianfosli/stellerom/osm-sync:latest"
fi
docker buildx build \
--cache-from "type=gha,scope=osm-sync" \
--cache-to "type=gha,mode=max,scope=osm-sync" \
-f osm-sync/Dockerfile \
$tags \
.
env:
DOCKER_BUILDKIT: "1"

- name: Push
run: |
docker push --all-tags ghcr.io/christianfosli/stellerom/osm-sync
deploy_dev:
needs: build
runs-on: ubuntu-latest
environment: Development
steps:
- uses: actions/checkout@v4

- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZ_CLIENT_ID }}
tenant-id: ${{ secrets.AZ_TENANT_ID }}
subscription-id: ${{ secrets.AZ_SUBS_ID }}

- name: Infra
run: ./scripts/az-bootstrap-containerapp-job.bash
env:
ENVIRONMENT: dev
SERVICE_NAME: osm-sync
CRON_EXPRESSION: '55 19 * * *'

- name: Deploy
run: |
set -eo pipefail
az containerapp job secret set -n caj-stellerom-osm-sync-dev -g rg-stellerom-dev \
--secrets "db-connstr=$DB_CONNSTR"
az containerapp job update -n caj-stellerom-osm-sync-dev -g rg-stellerom-dev \
--image ghcr.io/christianfosli/stellerom/osm-sync:${{ github.sha }} \
--set-env-vars "ROOM_API_DB_CONNSTR=secretref:db-connstr" "ROOM_API_DB_NAME=room-api-dev"
env:
DB_CONNSTR: "mongodb+srv://${{ secrets.ROOM_API_DB_USERNAME }}:${{ secrets.ROOM_API_DB_PASSWORD}}@azure-stellerom.au87e49.mongodb.net"

deploy_prod:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: deploy_dev
runs-on: ubuntu-latest
environment: Production
steps:
- uses: actions/checkout@v4

- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZ_CLIENT_ID }}
tenant-id: ${{ secrets.AZ_TENANT_ID }}
subscription-id: ${{ secrets.AZ_SUBS_ID }}

- name: Infra
run: ./scripts/az-bootstrap-containerapp-job.bash
env:
ENVIRONMENT: prod
SERVICE_NAME: osm-sync
CRON_EXPRESSION: '0 20 * * *'

- name: Deploy
run: |
az containerapp job secret set -n caj-stellerom-osm-sync-prod -g rg-stellerom-prod \
--secrets "db-connstr=$DB_CONNSTR"
az containerapp job update -n caj-stellerom-osm-sync-prod -g rg-stellerom-prod \
--image ghcr.io/christianfosli/stellerom/osm-sync:${{ github.sha }} \
--set-env-vars "ROOM_API_DB_CONNSTR=secretref:db-connstr" "ROOM_API_DB_NAME=room-api-prod"
env:
DB_CONNSTR: "mongodb+srv://${{ secrets.ROOM_API_DB_USERNAME }}:${{ secrets.ROOM_API_DB_PASSWORD}}@azure-stellerom.au87e49.mongodb.net"
4 changes: 4 additions & 0 deletions app/islands/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ export default function MyMap(props: MapProps) {
<h3 class="${tw`text-md font-bold`}">Nytt stellerom</h3>
<p>
Klikk på &quot;Fortsett&quot; om du er fornøyd med plasseringen.
</p>
<p class="${tw`fond-semibold`}">
Appen henter nå også data om stellerom fra <a href="https://www.openstreetmap.org/">OpenStreetMap</a>.
Vurder å legge inn stellerom der først, med &quot;changing_table=yes&quot; så vil den dukke opp her automatisk ila ett døgn.
</p>
<a href="/new-room?lat=${lat}&lng=${lng}">
<button class="${tw`bg-gray-300 p-2 rounded-md border border-gray-700`}">
Expand Down
16 changes: 0 additions & 16 deletions app/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@ export default function Home({ data }: PageProps<ChangingRoom[]>) {
return (
<div class="p-4 mx-auto max-w-screen-md">
<Header />
<div class="bg-red-900 p-2 text-white">
<details>
<summary>
<h3 class="inline-block text-md font-bold">
Driftsmeldinger og greit-å-vite
</h3>
</summary>
<ul class="list-disc p-4">
<li class="my-2">
Jeg har tenkt å skrive om siden til å hente posisjonsdata om stellerom fra
<a href="https://www.openstreetmap.org/">Open Street Map</a>. Det tar en stund siden jeg har prioritert
andre ting enn denne nettsiden, men det kan være lurt å legge inn nye og manglende stellerom der 😊.
</li>
</ul>
</details>
</div>
<main>
<Map apiKey={googleMapsApiKey} changingRooms={data} />
</main>
Expand Down
1 change: 1 addition & 0 deletions osm-sync/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
Loading

0 comments on commit a0a7b71

Please sign in to comment.