mirror of
https://github.com/immich-app/geoshenanigans.git
synced 2026-09-30 13:23:08 +08:00
149 lines
5.3 KiB
YAML
149 lines
5.3 KiB
YAML
name: 'Tiles File'
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
file_name:
|
|
description: 'The name of the file to deploy, defaults to newest file'
|
|
required: false
|
|
# pull_request:
|
|
# branches: [ "main" ]
|
|
# paths:
|
|
# - ".github/workflows/tiles-file.yml"
|
|
# - "map-styles/**"
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
deploy_tiles:
|
|
name: Deploy Tiles & Styles
|
|
defaults:
|
|
run:
|
|
working-directory: 'map-styles'
|
|
runs-on: mich
|
|
outputs:
|
|
KEY: ${{ steps.latest_build.outputs.KEY }}
|
|
env:
|
|
RCLONE_CONFIG: ${{ github.workspace }}/rclone.conf
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
submodules: 'recursive'
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
|
with:
|
|
node-version-file: 'map-styles/.nvmrc'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Generate styles
|
|
run: npm run build
|
|
|
|
- name: Find latest pmtiles build
|
|
id: latest_build
|
|
env:
|
|
FILE_NAME: ${{ github.event.inputs.file_name }}
|
|
run: |
|
|
if [ -z "$FILE_NAME" ]; then
|
|
build=$(curl -s https://build-metadata.protomaps.dev/builds.json | jq -r 'map(.key) | sort | last')
|
|
else
|
|
build=$FILE_NAME
|
|
fi
|
|
export build=${build%.pmtiles}
|
|
echo "KEY=$build"
|
|
echo "KEY=$build" >> $GITHUB_OUTPUT
|
|
|
|
- id: token
|
|
uses: immich-app/devtools/actions/create-workflow-token@df46d635b905e618b88fc4c95baa920aeb30b309 # create-workflow-token-action-v3.0.1
|
|
with:
|
|
client-id: ${{ secrets.PUSH_O_MATIC_APP_CLIENT_ID }}
|
|
private-key: ${{ secrets.PUSH_O_MATIC_APP_KEY }}
|
|
permission-contents: read
|
|
|
|
- name: Setup Mise
|
|
uses: immich-app/devtools/actions/use-mise@06a9ef925332c91be647d6256642b86b398592c8 # use-mise-action-v3.2.1
|
|
with:
|
|
github_token: ${{ steps.token.outputs.token }}
|
|
|
|
- name: Configure Rclone
|
|
env:
|
|
ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_TILES_R2_KV_TOKEN_ID }}
|
|
SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_TILES_R2_KV_TOKEN_HASHED_VALUE }}
|
|
run: |
|
|
cat > "$RCLONE_CONFIG" <<EOF
|
|
[r2]
|
|
type = s3
|
|
provider = Cloudflare
|
|
region = auto
|
|
endpoint = https://601adaaa1eab190cdfe2945f9a6c89d0.r2.cloudflarestorage.com
|
|
access_key_id = $ACCESS_KEY_ID
|
|
secret_access_key = $SECRET_ACCESS_KEY
|
|
[pmtiles]
|
|
type = http
|
|
url = https://build.protomaps.com/
|
|
EOF
|
|
|
|
- name: Download latest tiles from build server
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install aria2 -y
|
|
aria2c --continue=true -s16 -x16 -j16 --summary-interval=10 --remote-time=true --file-allocation=none https://build.protomaps.com/${{ steps.latest_build.outputs.KEY }}.pmtiles -d ./dist/ -o tiles.pmtiles
|
|
|
|
- name: Copy latest tiles to R2
|
|
run: |
|
|
regions="wnam oc weur apac eeur enam"
|
|
key="${{ steps.latest_build.outputs.KEY }}"
|
|
source_folder="./dist/"
|
|
|
|
for region in $regions; do
|
|
dest="r2:/tiles-${region}/${key}/"
|
|
echo "--- Starting parallel upload to $dest ---"
|
|
(
|
|
rclone --progress copyto "$source_folder" "$dest" \
|
|
--s3-no-check-bucket \
|
|
--ignore-checksum \
|
|
--s3-disable-checksum \
|
|
--s3-upload-cutoff=100M \
|
|
--transfers 1 \
|
|
--s3-upload-concurrency 25 \
|
|
--s3-chunk-size=100M \
|
|
--multi-thread-streams=25 \
|
|
--checkers=64 2>&1 | sed "s/^/[${region}] /"
|
|
) &
|
|
done
|
|
|
|
wait # Wait for all background rclone processes to finish
|
|
echo "--- All parallel uploads completed. ---"
|
|
update_tile_ref:
|
|
name: Update tile server file reference
|
|
needs: [deploy_tiles]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Generate a token
|
|
id: generate-token
|
|
uses: immich-app/devtools/actions/create-workflow-token@df46d635b905e618b88fc4c95baa920aeb30b309 # create-workflow-token-action-v3.0.1
|
|
with:
|
|
client-id: ${{ secrets.PUSH_O_MATIC_APP_CLIENT_ID }}
|
|
private-key: ${{ secrets.PUSH_O_MATIC_APP_KEY }}
|
|
permission-contents: write
|
|
- name: 'Checkout'
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
ref: ${{ github.event.pull_request.head.ref }}
|
|
token: ${{ steps.generate-token.outputs.token }}
|
|
|
|
- name: Update deployment file name
|
|
run: |
|
|
sed -i -E 's/"pmtiles_deployment_key": "(.*)"/"pmtiles_deployment_key": "${{ needs.deploy_tiles.outputs.KEY }}"/' deployment/modules/cloudflare/tiles-worker/tiles.tfvars.json
|
|
|
|
- name: Push updated tiles.tfvars to repo
|
|
uses: EndBug/add-and-commit@cc9c08ba6c8df3b93a8f2db63e89b98368ae2ae8 # v11.1.1
|
|
with:
|
|
add: deployment/modules/cloudflare/tiles-worker/tiles.tfvars.json
|
|
message: Update tile server file to ${{ needs.deploy_tiles.outputs.KEY }}
|
|
push: ${{ github.event_name == 'workflow_dispatch' }}
|