geolexica / geolexica-server

Generalized backend for Geolexica sites
2 stars 1 forks source link

A more clever way to deploy to S3 #98

Closed skalee closed 4 years ago

skalee commented 4 years ago

Right now sites have deploy steps like this one:

- name: Deploy to geolexica.org
  env:
    AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
    AWS_REGION: ${{ secrets.AWS_REGION }}
    AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID_STAGING }}
    S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME_STAGING }}
  run: |
    aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*" --include "*.html" --content-type "text/html; charset=utf-8"
    aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*" --include "*.json" --content-type "application/json; charset=utf-8"
    aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*" --include "*.jsonld" --content-type "application/ld+json; charset=utf-8"
    aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --exclude "*" --include "*.ttl" --content-type "text/turtle; charset=utf-8"
    aws s3 sync _site s3://$S3_BUCKET_NAME --region=$AWS_REGION --delete --no-progress --include "*" --exclude "*.html" --exclude "*.json" --exclude "*.jsonld" --exclude "*.ttl"
    aws configure set preview.cloudfront true
    aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"

This isn't very maintainable. The configuration is repeated twice per site, and it needs to be updated every time another file type is added. And in fact, above example (taken from one of our sites) is missing TBX, which is a good example of bug we're risking here.

Something more reusable is needed. Perhaps we need to roll out our custom action. Perhaps we should aggregate all build and deploy steps in a single action.

I saw we had similar problem in the past, so maybe @ronaldtse has some good idea?