Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shollingsworth/df26e2af55ae913e53f6b42b2925ce21 to your computer and use it in GitHub Desktop.
Save shollingsworth/df26e2af55ae913e53f6b42b2925ce21 to your computer and use it in GitHub Desktop.
sync frontend files to cloudfront enabled s3 bucket and invalidate cache
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
TAG="cf-frontend:latest"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUCKET="cf-bucket"
CF_DIST_ID="d-xxxxxxxxxxxx"
FRONTEND_DIR="${DIR}/../frontend"
pushd "${FRONTEND_DIR}"
docker build -t "${TAG}" \
-f "../localdev/frontend-build.Dockerfile" \
.
docker run --rm -it \
-v "${FRONTEND_DIR}:/frontend" \
--workdir /frontend \
"${TAG}" \
quasar build
aws s3 sync \
--delete \
--acl public-read \
"${FRONTEND_DIR}/dist/spa" \
"s3://${BUCKET}"
aws cloudfront create-invalidation --distribution-id "${CF_DIST_ID}" --paths "/*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment