Created
March 18, 2021 10:19
-
-
Save brunosmm/44aea2e5c8752180a103f077ae6a23de to your computer and use it in GitHub Desktop.
CircleCI configuration to deploy an Vue App into cloudfront and execute migrations with fauna-schema-migrations lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2.1 | |
x_filter_dev: &dev_filter | |
filters: | |
branches: | |
only: /develop/ | |
x_filter_sta: &sta_filter | |
filters: | |
branches: | |
only: /master/ | |
x_filter_prod: &prod_filter | |
filters: | |
branches: | |
ignore: /.*/ | |
tags: | |
only: /^\d+\.\d+\.\d+/ | |
orbs: | |
node: circleci/node@1.1.6 | |
aws-s3: circleci/aws-s3@2.0.0 | |
jobs: | |
build: | |
parameters: | |
fauna-secret: | |
type: string | |
default: '' | |
env: | |
type: string | |
default: '' | |
executor: node/default | |
working_directory: ~/repo | |
steps: | |
- checkout | |
- run: yarn install | |
- run: | |
name: "Execute Migration" | |
command: | | |
FAUNA_SETUP=$(node_modules/.bin/fauna-schema-migrate apply all -k << parameters.fauna-secret >> -n) | |
echo "$FAUNA_SETUP" | |
if [[ ${FAUNA_SETUP} == *"Error"* ]]; then | |
exit 2 | |
fi | |
- run: | |
name: "Get Login Key & Prepare Env" | |
command: yarn run keys << parameters.fauna-secret >> << parameters.env >> | |
- node/with-cache: | |
steps: | |
- run: yarn run build --mode << parameters.env >> | |
- persist_to_workspace: | |
root: ~/repo | |
paths: | |
- dist | |
deploy-aws: | |
parameters: | |
s3-bucket: | |
type: string | |
default: '' | |
cloudfront-id: | |
type: string | |
default: '' | |
executor: node/default | |
working_directory: ~/repo | |
steps: | |
- attach_workspace: | |
at: ~/repo | |
- aws-s3/sync: | |
arguments: | # Optional arguments | |
--acl public-read \ | |
--cache-control "max-age=86400" \ | |
--delete | |
from: dist | |
to: << parameters.s3-bucket >> | |
- run: | |
name: "Invalidate CloudFront Cache" | |
command: | | |
aws cloudfront create-invalidation --distribution-id << parameters.cloudfront-id >> --paths "/*" | |
workflows: | |
deploy-prod: | |
jobs: | |
- build: | |
fauna-secret: $FAUNA_SECRET_PROD | |
env: 'prod' | |
<<: *prod_filter | |
- deploy-aws: | |
cloudfront-id: 'CLOUDFRONT-ID' | |
s3-bucket: 's3://s3-url' | |
<<: *prod_filter | |
requires: | |
- build | |
deploy-sta: | |
jobs: | |
- build: | |
fauna-secret: $FAUNA_SECRET_STA | |
env: 'sta' | |
<<: *sta_filter | |
- deploy-aws: | |
cloudfront-id: 'CLOUDFRONT-ID' | |
s3-bucket: 's3://s3-url' | |
<<: *sta_filter | |
requires: | |
- build | |
deploy-dev: | |
jobs: | |
- build: | |
fauna-secret: $FAUNA_SECRET_DEV | |
env: 'dev' | |
<<: *dev_filter | |
- deploy-aws: | |
cloudfront-id: 'CLOUDFRONT-ID' | |
s3-bucket: 's3://s3-url' | |
<<: *dev_filter | |
requires: | |
- build |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment