mirror of
https://github.com/kremalicious/portfolio.git
synced 2024-11-13 16:45:12 +01:00
simplify S3 backup deployment
This commit is contained in:
parent
f1cf8cad61
commit
456efc2e8b
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -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 }}
|
||||
|
14
README.md
14
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
|
||||
|
||||
|
@ -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": {
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user