Skip to content

Merge pull request #102 from geolonia/add-geoloniamaps-smartcity-base #40

Merge pull request #102 from geolonia/add-geoloniamaps-smartcity-base

Merge pull request #102 from geolonia/add-geoloniamaps-smartcity-base #40

Workflow file for this run

name: Deploy to CDN
on:
push:
branches:
- master
- cdnv2
jobs:
build:
runs-on: ubuntu-latest
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Restore timestamps
uses: chetan/git-restore-mtime-action@v1
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ap-northeast-1
role-to-assume: arn:aws:iam::762706324393:role/github-actions-cdn-geolonia-deploy
- name: Deploy to S3
run: |
# Note: The default max-age is set at 3600 seconds or 1 hour. After 1 hour,
# the client will mark the resource as stale, and require a refresh.
# In most cases, this will result in a if-modified-since conditional request.
# For resources that are immutable (for example, embed-chunks), the max-age is set to immutable.
# For resources that will be manually invalidated, an addition s-maxage so CloudFront keeps the file in its cache as long as possible.
# Deploy most static files
aws s3 sync ./public s3://gl-cdn-ap-northeast-1 \
--delete \
--cache-control "public,max-age=3600" \
--exclude "_headers" \
--exclude "*.mvt" \
--exclude "dev/embed" --exclude "v1/embed" \
--exclude "dev/embed-chunks/*" --exclude "v1/embed-chunks/*"
# Deploy mvt tiles (requires special header for automatic compression)
# can set max-age to 1 day here because
aws s3 sync ./public s3://gl-cdn-ap-northeast-1 \
--delete \
--cache-control "public,max-age=86400" \
--content-type "application/vnd.mapbox-vector-tile" \
--exclude="*" --include="*.mvt"
# Deploy embed chunks -- because they have fingerprints in the filename, they're immutable
aws s3 sync ./public/dev/embed-chunks s3://gl-cdn-ap-northeast-1/dev/embed-chunks --cache-control "public,max-age=31536000,immutable"
aws s3 sync ./public/v1/embed-chunks s3://gl-cdn-ap-northeast-1/v1/embed-chunks --cache-control "public,max-age=31536000,immutable"
# Deploy main embed entrypoint
# I used to use s-maxage here, but after testing decided to revert back to only using max-age.
# If you use s-maxage that is much longer than max-age, the age header will be longer than
# max-age, and the browser will think that the file is expired. Using max-age will make
# CloudFront fetch a new file every 3600 seconds, resetting the Age header
aws s3 cp ./public/dev/embed s3://gl-cdn-ap-northeast-1/dev/embed --cache-control "public,max-age=3600" --content-type "application/javascript; charset=UTF-8"
aws s3 cp ./public/v1/embed s3://gl-cdn-ap-northeast-1/v1/embed --cache-control "public,max-age=3600" --content-type "application/javascript; charset=UTF-8"
aws cloudfront create-invalidation --distribution-id "E1ZFNBWBSCLVFC" --paths "/v1/embed" "/dev/embed"