Skip to content

Instantly share code, notes, and snippets.

@Sauloxd
Last active March 30, 2019 11:43
Show Gist options
  • Save Sauloxd/12e4ef644dd2030fe439f47e474d2aa3 to your computer and use it in GitHub Desktop.
Save Sauloxd/12e4ef644dd2030fe439f47e474d2aa3 to your computer and use it in GitHub Desktop.
How to deploy your static asset to S3 using travis CD
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
@Sauloxd
Copy link
Author

Sauloxd commented Mar 30, 2019

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