Last active
August 15, 2023 04:17
-
-
Save mtimbs/2f9446b93d2c1a1c4d384be1ad9aea0b to your computer and use it in GitHub Desktop.
Example Gitlab CI config for a typescript serverless proeject
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: docker:latest | |
cache: | |
paths: | |
- node_modules/ | |
stages: | |
- build | |
- precheck | |
- test | |
- deploy | |
build-docker-image: | |
stage: build | |
image: docker:latest | |
services: | |
- docker:dind | |
script: | |
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY | |
- docker build --pull -t "$CI_REGISTRY_IMAGE" -f Dockerfile.pipeline . | |
- docker push "$CI_REGISTRY_IMAGE" | |
only: | |
changes: | |
- Dockerfile.pipeline | |
has_lock_files: | |
stage: precheck | |
script: | |
- "if [[ -e 'package.json' && ! -e 'package-lock.json' ]]; then echo 'No lock file found. Please add a package-lock.json'; false; fi" | |
security_checker: | |
stage: precheck | |
image: $CI_REGISTRY_IMAGE:latest | |
script: | |
- npm audit --audit-level=moderate | |
eslint: | |
stage: precheck | |
image: $CI_REGISTRY_IMAGE:latest | |
script: | |
- npm i -D | |
- npm run lint | |
- npm run buildtest | |
tests: | |
stage: test | |
image: $CI_REGISTRY_IMAGE:latest | |
script: | |
- npm i -D | |
- npm run test | |
staging_deploy: | |
stage: deploy | |
image: $CI_REGISTRY_IMAGE:latest | |
only: | |
- develop | |
script: | |
- npm ci | |
- cd / && serverless config credentials --provider aws --key $AWS_ACCESS_KEY_ID_STAGING --secret $AWS_SECRET_ACCESS_KEY_STAGING && cd - | |
- SLS_DEBUG=* serverless --stage stage | |
- for r in $DEPLOY_REGIONS; do SLS_DEBUG=* serverless deploy --verbose --force --stage stage --region $r; done | |
production_deploy: | |
stage: deploy | |
image: $CI_REGISTRY_IMAGE:latest | |
only: | |
- master | |
script: | |
- npm ci | |
- cd / && serverless config credentials --provider aws --key $AWS_ACCESS_KEY_ID_PRODUCTION --secret $AWS_SECRET_ACCESS_KEY_PRODUCTION && cd - | |
- SLS_DEBUG=* serverless --stage prod | |
- for r in $DEPLOY_REGIONS; do SLS_DEBUG=* serverless deploy --verbose --force --stage prod --region $r; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment