Skip to content

Instantly share code, notes, and snippets.

@linuskohl
Created August 18, 2019 13:26
Show Gist options
  • Save linuskohl/3bcf7643f7f4a0ec589f86208aedfe3f to your computer and use it in GitHub Desktop.
Save linuskohl/3bcf7643f7f4a0ec589f86208aedfe3f to your computer and use it in GitHub Desktop.
GitLab CI/CD for deploying a React app to an AWS S3 bucket
# GitLab CI/CD Variables
# AWS_S3_BUCKET_PROD: S3 bucket that hosts production files
# AWS_S3_BUCKET_DEV: S3 bucket that hosts development files
# AWS_ACCESS_KEY_ID: AWS Key ID
# AWS_SECRET_ACCESS_KEY: AWS Secret
stages:
- build
- deploy
# Build
build:
stage: build
image: node:latest
script:
- echo "Building the app"
- npm install
- CI=false npm run build
artifacts:
name: react-build
paths:
- build
# Deploy Production
deploy production:
stage: deploy
image: python:latest
script:
- pip install awscli
- aws s3 cp ./build/ s3://$AWS_S3_BUCKET_PROD/ --recursive --include "*"
#- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*"
- echo "Deploy to https://PROD_URL"
environment:
name: production
url: https://PROD_URL
only:
- master
# Deploy Development
deploy development:
stage: deploy
image: python:latest
script:
- pip install awscli
- aws s3 cp ./build/ s3://$AWS_S3_BUCKET_DEV/ --recursive --include "*"
- echo "Deploy to https://DEV_URL
environment:
name: development
url: https://DEV_URL
only:
- dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment