Last active
March 30, 2019 11:43
-
-
Save Sauloxd/12e4ef644dd2030fe439f47e474d2aa3 to your computer and use it in GitHub Desktop.
How to deploy your static asset to S3 using travis CD
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
language: node_js | |
cache: | |
directories: | |
- node_modules | |
script: | |
- npm test | |
- npm run build | |
before_deploy: pip install --user awscli | |
deploy: | |
provider: script | |
script: ~/.local/bin/aws s3 sync build s3://$BUCKET_NAME --region=$BUCKET_REGION --delete && ~/.local/bin/aws s3 cp s3://$BUCKET_NAME/index.html s3://$BUCKET_NAME/index.html --metadata-directive REPLACE --cache-control max-age=0 --region=$BUCKET_REGION | |
acl: public_read | |
bucket: "$BUCKET_NAME" | |
region: "$BUCKET_REGION" | |
local_dir: build | |
skip_cleanup: true | |
on: | |
branch: master | |
env: | |
global: | |
- BUCKET_NAME=saulo.dev | |
- BUCKET_REGION=us-east-1 | |
- secure: [encrypt AWS_ACCESS_KEY_ID] # travis login --pro && travis encrypt AWS_ACCESS_KEY_ID=<<replace-here>> --add --com | |
- secure: [encrypt AWS_SECRET_ACCESS_KEY] # travis login --pro && travis encrypt AWS_SECRET_ACCESS_KEY=<<replace-here>> --add --com |
Also ~/.local/bin/aws
is only available due to before_deploy: pip install --user awscli
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script meaning:
Uploads all in build directory (mine is
build
, yours can bedist
,lib
,bleus
, change accordingly), in the proper bucket region,--delet
ing everything in the bucket beforehand.This is used to update the
index.html
cache-control metadata so whenever a user requestsindex.html
it will always get a fresh one (instead of the cached version)