Skip to content

Instantly share code, notes, and snippets.

@zuffik
Created August 18, 2019 07:11
Show Gist options
  • Save zuffik/4942f97437e13022062106095511085a to your computer and use it in GitHub Desktop.
Save zuffik/4942f97437e13022062106095511085a to your computer and use it in GitHub Desktop.
Gitlab CI config for s3 bucket and react app using cloudfront cache
image: node:12
stages:
- build
- test
- deploy
cache:
paths:
- node_modules
build:front:
stage: build
before_script:
- yarn install
script:
- yarn build
- mv build react-build
artifacts:
paths:
- react-build
test:
stage: test
artifacts:
paths:
- coverage
dependencies:
- build:front
before_script:
- yarn install
script:
- yarn test
deploy:prod:
image: python:latest
stage: deploy
allow_failure: false
artifacts:
paths:
- build
before_script:
- mkdir build
- mv react-build build/react
- pip install awscli
- mkdir ~/.aws/
- touch ~/.aws/credentials
- printf "[eb-cli]\naws_access_key_id = %s\naws_secret_access_key = %s\n" "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" >> ~/.aws/credentials
dependencies:
- test
- build:front
script:
- aws s3 rm "s3://${ASW_S3_BUCKET}/" --exclude "*" --include "precache-manifest.*"
- aws s3 rm "s3://${ASW_S3_BUCKET}/static" --recursive
- aws s3 sync build/react "s3://${ASW_S3_BUCKET}/" --acl public-read
- aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths '/*'
only:
- master
when: manual
environment:
name: production
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment