291st/.gitlab/.gitlab-ci.yml

102 lines
2.6 KiB
YAML
Raw Normal View History

2022-09-20 13:57:30 -04:00
image: node:16
stages:
- build
- test
2023-08-01 11:00:19 -04:00
- publish
2022-09-20 13:57:30 -04:00
- deploy
npm:
stage: build
cache:
- key:
files:
2023-03-20 16:15:24 -04:00
- package-lock.json
2022-09-20 13:57:30 -04:00
paths:
2022-09-20 14:32:46 -04:00
- node_modules
2022-09-20 13:57:30 -04:00
policy: pull-push
- key: $CI_PIPELINE_ID
paths:
- dist
policy: push
script:
2023-03-20 16:15:24 -04:00
- npm install
2022-09-20 13:57:30 -04:00
- npm run build
2023-03-20 16:15:24 -04:00
artifacts:
paths:
- dist
expire_in: 1 week
2022-09-20 13:57:30 -04:00
rules:
- if: $CI_COMMIT_BRANCH
audit:
stage: test
2023-03-20 16:15:24 -04:00
cache:
- key:
files:
- package-lock.json
paths:
- node_modules
policy: pull
2022-09-20 13:57:30 -04:00
script:
2023-03-20 16:15:24 -04:00
- echo "vulnerabilities_high $(npm audit | grep -oE '[0-9]+ high' | grep -oE '[0-9]+' || echo 0)" > metrics.txt
- echo "vulnerabilities_medium $(npm audit | grep -oE '[0-9]+ moderate' | grep -oE '[0-9]+' || echo 0)" >> metrics.txt
- echo "vulnerabilities_low $(npm audit | grep -oE '[0-9]+ low' | grep -oE '[0-9]+' || echo 0)" >> metrics.txt
2022-09-20 13:57:30 -04:00
artifacts:
reports:
metrics: metrics.txt
rules:
- if: $CI_COMMIT_BRANCH
registry:
2023-08-01 11:00:19 -04:00
stage: publish
2022-09-20 13:57:30 -04:00
image: docker
cache:
- key: $CI_PIPELINE_ID
paths:
- dist
policy: pull
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- TAG=$([ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ] && echo "latest" || echo "$CI_COMMIT_BRANCH" | sed -E "s/[_/]/-/g")
- docker build --no-cache -t "$CI_REGISTRY_IMAGE:$TAG" .
- docker push "$CI_REGISTRY_IMAGE:$TAG"
rules:
- if: $CI_COMMIT_BRANCH
2022-09-20 14:32:46 -04:00
allow_failure: true
2022-09-20 13:57:30 -04:00
tag:
2023-08-01 11:00:19 -04:00
stage: publish
2022-09-20 13:57:30 -04:00
image:
name: alpine/git
entrypoint: [ "" ]
cache: [ ]
before_script:
2023-03-20 16:07:18 -04:00
- git remote set-url origin https://ReleaseBot:$DEPLOY_TOKEN@gitlab.zakscode.com/$CI_PROJECT_PATH.git
2022-09-20 13:57:30 -04:00
script:
- VERSION=$(cat package.json | grep version | grep -Eo ':.+' | grep -Eo '[[:alnum:]\.\/\-]+')
- git tag -f $VERSION $CI_COMMIT_SHA
- git push -f origin $VERSION
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
allow_failure: true
2023-08-01 11:00:19 -04:00
production:
stage: deploy
image: docker
cache: []
variables:
SERVICE_NAME: phone-reminders_api
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
- TAG=$([ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ] && echo "latest" || echo "$CI_COMMIT_BRANCH" | sed -E "s/[_/]/-/g")
script:
- docker pull "$CI_REGISTRY_IMAGE:$TAG"
- docker service update --force --with-registry-auth --image "$CI_REGISTRY_IMAGE:$TAG" "$SERVICE_NAME" || echo "Continuing in background"
allow_failure: true
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: manual