Skip to content

Instantly share code, notes, and snippets.

@gioragutt
Created May 9, 2021 19:59
Show Gist options
  • Save gioragutt/14f46bfce38dad34d09f02cbcab58523 to your computer and use it in GitHub Desktop.
Save gioragutt/14f46bfce38dad34d09f02cbcab58523 to your computer and use it in GitHub Desktop.
Example of distributing a website with S3+CloudFront via CI
version: '1.0'
kind: pipeline
metadata:
name: my-website/publish
project: my-website
spec:
triggers:
- name: master_commit
type: git
repo: my-org/my-website
events:
- push.heads
pullRequestAllowForkEvents: false
commentRegex: /.*/gi
branchRegex: /^((master)$).*/gi
branchRegexInput: multiselect
provider: github
disabled: false
verified: true
options:
resetVolume: true
context: github-verified
contexts: []
variables: []
contexts:
- aws_tlv_prod_serverless # this is what gave our CI access to AWS
stages:
- "clone"
- "test"
- "build"
- "publish"
steps:
clone:
title: "Cloning repository"
type: "git-clone"
repo: "my-org/my-website"
revision: 'master'
git: "github-verified"
stage: "clone"
install:
title: Install
stage: "build"
image: 'node:12'
commands:
- cd my-website
- yarn
build:
title: "Build"
image: node:12
stage: "build"
commands:
- cd my-website
- yarn build
publish:
title: Publish
image: 'mesosphere/aws-cli'
stage: publish
commands:
- cd my-website
- aws s3 cp build "s3://$BUCKET_NAME/" --recursive --exclude "static/*" --cache-control max-age=60,s-maxage=31536000
- aws s3 cp build "s3://$BUCKET_NAME/" --recursive --exclude "*" --include "static/*" --cache-control max-age=31536000,s-maxage=31536000
- aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths "/index.html" "/manifest.json" "/asset-manifest.json" "/service-worker.js" "/logo192.png" "/logo512.png" "/favicon.ico"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment