Skip to content

Instantly share code, notes, and snippets.

@maisnamraju
Forked from zuffik/.gitlab-ci.yml
Created November 25, 2021 14:13
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 maisnamraju/6623cfff8990b3a6923b363d0fc8130e to your computer and use it in GitHub Desktop.
Save maisnamraju/6623cfff8990b3a6923b363d0fc8130e to your computer and use it in GitHub Desktop.
Gitlab CI config for elastic beanstalk and nestjs app
image: node:10
stages:
- build
- test
- deploy
build:
stage: build
cache:
paths:
- node_modules
artifacts:
paths:
- dist
- static
- package.json
- .ebextensions
- .elasticbeanstalk
before_script:
- yarn install
script:
- yarn build
test:
stage: test
cache:
paths:
- node_modules
dependencies:
- build
before_script:
- yarn install
script:
- yarn lint
- yarn test --passWithNoTests
.deploy:
image: python:latest
stage: deploy
allow_failure: false
dependencies:
- test
- build
before_script:
- pip install awscli
- apt-get update -y
- apt-get install -y zip
- 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
script:
- export VERSION_LABEL="${CI_COMMIT_SHA}-$(date +%s)"
- zip -r "${CI_COMMIT_SHA}.zip" dist static package.json .ebextensions .elasticbeanstalk
- aws s3 cp "${CI_COMMIT_SHA}.zip" "s3://${AWS_EB_BUCKET_NAME}/${AWS_EB_APP_NAME}/${CI_COMMIT_SHA}.zip"
- aws elasticbeanstalk create-application-version --application-name "${AWS_EB_APP_NAME}" --version-label "$VERSION_LABEL" --source-bundle S3Bucket="${AWS_EB_BUCKET_NAME}",S3Key="${AWS_EB_APP_NAME}/${CI_COMMIT_SHA}.zip" --region "${AWS_REGION}"
- aws elasticbeanstalk update-environment --environment-name "${AWS_EB_APP_NAME}-${CI_ENVIRONMENT_NAME}-env" --application-name "${AWS_EB_APP_NAME}" --version-label "$VERSION_LABEL" --region "${AWS_REGION}"
deploy:prod:
extends: .deploy
environment:
name: production
when: manual
only:
- master
deploy:staging:
extends: .deploy
environment:
name: staging
only:
- develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment