From 456efc2e8b1b23673d260153a691744b65e89235 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sat, 6 Feb 2021 13:19:30 +0100 Subject: [PATCH] simplify S3 backup deployment --- .github/workflows/ci.yml | 4 +-- README.md | 14 +++------ package.json | 2 +- scripts/{deploy.sh => deploy-s3.sh} | 46 +++-------------------------- 4 files changed, 11 insertions(+), 55 deletions(-) rename scripts/{deploy.sh => deploy-s3.sh} (58%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b90579..c533239 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,7 +75,7 @@ jobs: deploy: needs: build - if: success() && (github.event_name == 'pull_request' || github.ref == 'refs/heads/main') + if: success() && github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: @@ -84,7 +84,7 @@ jobs: with: name: public - name: Deploy to S3 - run: ./scripts/deploy.sh + run: npm run deploy:s3 env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/README.md b/README.md index 08e51cc..c0b7d5e 100644 --- a/README.md +++ b/README.md @@ -212,25 +212,19 @@ SLUG-03.png ## 🚚 Deployment -Automatic deployments are triggered upon successful tests & builds via GitHub Actions: +Every branch or Pull Request is automatically deployed by [Vercel](https://vercel.com) with their GitHub integration, where the `main` branch is automatically aliased to `matthiaskretschmann.com`. A link to a preview deployment will appear under each Pull Request. -- push to `main` initiates a live deployment -- any Pull Request, and subsequent pushes to it, initiates a beta deployment - -The deploy command simply calls the [`scripts/deploy.sh`](scripts/deploy.sh) script, syncing the contents of the `public/` folder to S3: +A backup deployment is also happening to a S3 bucket, triggered by pushes to `main` and executed via GitHub Actions. The deploy command simply calls the [`scripts/deploy-s3.sh`](scripts/deploy-s3.sh) script, syncing the contents of the `public/` folder to S3: ```bash -npm run deploy +npm run deploy:s3 ``` -Upon live deployment, deploy script also purges the Cloudflare cache, and pings search engines. GitHub requires the following environment variables to be setup for successful deployments in the repository secrets: +Upon live deployment, deploy script also pings search engines. GitHub requires the following environment variables to be setup for successful deployments in the repository secrets: - `AWS_ACCESS_KEY_ID` - `AWS_SECRET_ACCESS_KEY` - `AWS_DEFAULT_REGION` -- `CLOUDFLARE_EMAIL` -- `CLOUDFLARE_ZONE` -- `CLOUDFLARE_KEY` ## 🏛 Licenses diff --git a/package.json b/package.json index 9cbb9c4..6d1f556 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "format": "prettier --write 'src/**/*.{js,jsx,css,scss}'", "test": "npm run lint && jest --coverage --silent", "test:watch": "npm run lint && jest --coverage --watch", - "deploy": "./scripts/deploy.sh", + "deploy:s3": "./scripts/deploy-s3.sh", "new": "babel-node ./scripts/new.js" }, "dependencies": { diff --git a/scripts/deploy.sh b/scripts/deploy-s3.sh similarity index 58% rename from scripts/deploy.sh rename to scripts/deploy-s3.sh index c385bcf..26e09d1 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy-s3.sh @@ -5,9 +5,8 @@ # AWS_SECRET_ACCESS_KEY # AWS_DEFAULT_REGION AWS_S3_BUCKET="matthiaskretschmann.com" -AWS_S3_BUCKET_BETA="beta.matthiaskretschmann.com" SITEMAP_URL="https%3A%2F%2Fmatthiaskretschmann.com%2Fsitemap.xml" -# + set -e; function s3sync { @@ -42,16 +41,6 @@ function s3sync { --acl public-read } -# purge full Cloudflare cache -# https://api.cloudflare.com/#zone-purge-all-files -function purge { - curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/purge_cache" \ - -H "X-Auth-Email: $CLOUDFLARE_EMAIL" \ - -H "X-Auth-Key: $CLOUDFLARE_KEY" \ - -H "Content-Type: application/json" \ - --data '{"purge_everything":true}' -} - # ping search engines # returns: HTTP_STATUSCODE URL function ping { @@ -60,34 +49,7 @@ function ping { "http://www.bing.com/webmaster/ping.aspx?siteMap=$SITEMAP_URL" -o /dev/null } -## -## check for pull request against main -## -if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then +# start deployment +s3sync $AWS_S3_BUCKET - s3sync $AWS_S3_BUCKET_BETA - -## -## check for main push which is no pull request -## -elif [ "$GITHUB_REF" == "refs/heads/main" ]; then - - s3sync $AWS_S3_BUCKET - - # purge - - ping - - echo "---------------------------------------------" - echo " ✓ done deployment " - echo "---------------------------------------------" - - exit; - -else - - echo "---------------------------------------------" - echo " nothing to deploy " - echo "---------------------------------------------" - -fi +ping