Last active
May 13, 2022 04:53
-
-
Save Mazuh/4b7a275ded38e2e031a5d40e28d1984d to your computer and use it in GitHub Desktop.
Example of gitlab CI/CD for a create-react-app application on Amazon S3 Bucket.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Statement": { | |
"Sid": "PublicReadGetObject", | |
"Effect": "Allow", | |
"Principal": "*", | |
"Action": ["s3:GetObject"], | |
"Resource": ["arn:aws:s3:::my-app-dev/*"] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Statement": { | |
"Sid": "PublicReadGetObject", | |
"Effect": "Allow", | |
"Principal": "*", | |
"Action": ["s3:GetObject"], | |
"Resource": ["arn:aws:s3:::my-app-prod/*"] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"IndexDocument": { | |
"Suffix": "index.html" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment