Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sean7218
Forked from Mazuh/.gitlab-ci.yml
Created October 30, 2019 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sean7218/f4edfc6d181647179e514e8f870c800d to your computer and use it in GitHub Desktop.
Save sean7218/f4edfc6d181647179e514e8f870c800d to your computer and use it in GitHub Desktop.
Example of gitlab CI/CD for a create-react-app application on Amazon S3 Bucket.
image: nikolaik/python-nodejs:latest
stages:
- install
- test
- deploy
prodInstall:
stage: install
script:
- npm install --production
artifacts:
untracked: true
unitTesting:
stage: test
dependencies:
- prodInstall
script:
- npm install
- npm run build
- npm test
artifacts:
untracked: true
deployingDev:
stage: deploy
only:
- dev
dependencies:
- prodInstall
- unitTesting
script:
- pip3 install awscli
- aws configure set profile bucket-dev
- aws configure set aws_access_key_id "$DEV_AWS_KEY"
- aws configure set aws_secret_access_key "$DEV_AWS_SECRET"
- ((aws s3api create-bucket --acl public-read --bucket my-app-dev && echo 'Created bucket.') || echo 'Already existing bucket.')
- aws s3api put-bucket-website --bucket my-app-dev --website-configuration file://website.json
- aws s3api put-bucket-policy --bucket my-app-dev --policy file://policy-dev.json
- aws s3 sync ./build/ s3://my-app-dev
deployingProd:
stage: deploy
only:
- master
dependencies:
- prodInstall
- unitTesting
script:
- pip3 install awscli
- aws configure set profile bucket-prod
- aws configure set aws_access_key_id "$PROD_AWS_KEY"
- aws configure set aws_secret_access_key "$PROD_AWS_SECRET"
- ((aws s3api create-bucket --acl public-read --bucket my-app-prod && echo 'Created bucket.') || echo 'Already existing bucket.')
- aws s3api put-bucket-website --bucket my-app-prod --website-configuration file://website.json
- aws s3api put-bucket-policy --bucket my-app-prod --policy file://policy-prod.json
- aws s3 sync ./build/ s3://my-app-prod
{
"Statement": {
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::my-app-dev/*"]
}
}
{
"Statement": {
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject"],
"Resource": ["arn:aws:s3:::my-app-prod/*"]
}
}
{
"IndexDocument": {
"Suffix": "index.html"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment