Added redeploy

This commit is contained in:
Zakary Timson 2023-06-06 13:29:53 +00:00
parent 3ce0f7a418
commit 96c94d73c8

View File

@ -1,5 +1,11 @@
image: node:16 image: node:16
stages:
- build
- test
- publish
- deploy
npm: npm:
stage: build stage: build
cache: cache:
@ -43,7 +49,7 @@ audit:
- if: $CI_COMMIT_BRANCH - if: $CI_COMMIT_BRANCH
registry: registry:
stage: deploy stage: publish
image: docker image: docker
cache: cache:
- key: $CI_PIPELINE_ID - key: $CI_PIPELINE_ID
@ -56,12 +62,12 @@ registry:
- TAG=$([ "$CI_COMMIT_BRANCH" = "$CI_DEFAULT_BRANCH" ] && echo "latest" || echo "$CI_COMMIT_BRANCH" | sed -E "s/[_/]/-/g") - 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 build --no-cache -t "$CI_REGISTRY_IMAGE:$TAG" .
- docker push "$CI_REGISTRY_IMAGE:$TAG" - docker push "$CI_REGISTRY_IMAGE:$TAG"
allow_failure: true
rules: rules:
- if: $CI_COMMIT_BRANCH - if: $CI_COMMIT_BRANCH
allow_failure: true
tag: tag:
stage: deploy stage: publish
image: image:
name: alpine/git name: alpine/git
entrypoint: [""] entrypoint: [""]
@ -72,5 +78,20 @@ tag:
- VERSION=$(cat package.json | grep version | grep -Eo ':.+' | grep -Eo '[[:alnum:]\.\/\-]+') - VERSION=$(cat package.json | grep version | grep -Eo ':.+' | grep -Eo '[[:alnum:]\.\/\-]+')
- git tag -f $VERSION $CI_COMMIT_SHA - git tag -f $VERSION $CI_COMMIT_SHA
- git push -f origin $VERSION - git push -f origin $VERSION
allow_failure: true
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
swarm:
stage: deploy
image: docker
cache: []
variables:
SERVICE_NAME: legio-xxx_web
script:
- SCALE=$(docker service inspect "$SERVICE_NAME" | grep -m 1 Replicas | grep -oE "[0-9]")
- docker service update --force --with-registry-auth --image "$CI_REGISTRY_IMAGE:latest" "$SERVICE_NAME" || echo "Continuing in background"
- docker service scale "$SERVICE_NAME=0" && docker service scale "$SERVICE_NAME=$SCALE"
allow_failure: true
rules: rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'