Skip to content

Instantly share code, notes, and snippets.

@ksatirli
Last active August 11, 2019 12:29
Show Gist options
  • Save ksatirli/cc6e12a92bcb9f7114a71952a10f6583 to your computer and use it in GitHub Desktop.
Save ksatirli/cc6e12a92bcb9f7114a71952a10f6583 to your computer and use it in GitHub Desktop.
Bitbucket: push assets to AWS CloudFront
---
pipelines:
cloudfront:
- step:
image: python:3.5.1
script:
- pip install awscli
# set up AWS access credentials incl. region
- export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
- export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
- export AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}"
# TODO: render Hugo site
- echo "rendering Hugo site"
# sync site content to S3 Bucket
- aws s3 sync "${S3_SOURCE}" s3://${S3_BUCKET_DEVELOP}/ --acl "public-read"
# trigger CloudFront refresh
# - aws cloudfront create-invalidation --distribution-id "${CLOUDFRONT_ID}" --paths "/*"
cloudfront_oldmaster:
- step:
image: python:3.5.1
script:
- pip install awscli
- export AWS_ACCESS_KEY_ID="$AWS_ACCESS_KEY_ID"
- export AWS_SECRET_ACCESS_KEY="$AWS_SECRET_ACCESS_KEY"
- export AWS_DEFAULT_REGION="$AWS_DEFAULT_REGION"
- aws configure set preview.cloudfront true
- aws cloudfront create-invalidation --distribution-id "${CLOUDFRONT_ID}" --paths "/*"
---
pipelines:
default:
- step:
image: centos:7
script:
# create variable shorthands
- export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
- export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
- export AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}"
# install AWS CLI and configure it
- yum install --assumeyes "epel-release"
- yum install --assumeyes "python-pip"
- pip install "awscli"
- aws configure set preview.cloudfront true
# push static files to AWS S3
- aws s3 sync "./" "s3://${S3_BUCKET}/" --exclude '.*' --exclude 'bitbucket-pipelines.yml' --acl "public-read"
# trigger CloudFront refresh
- aws cloudfront create-invalidation --distribution-id "${CLOUDFRONT_ID}" --paths "/*"
# notify!
- echo "Static files have been pushed to ${S3_BUCKET}."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment