2021-12-10 16:30:16 +01:00

62 lines
2.7 KiB
YAML

include:
- project: "SharedLibraries/CommonCI/webservices-common-ci"
ref: 4.x
file: "webservices-gitlab-ci-template-dotnetcore.yml"
versionize:
before_script:
- VERSION=`echo -e "import yaml\nwith open('openapi.yaml') as f:d=yaml.load(f)\nprint d['info']['version']" | python`
extract_client_definition:
after_script:
- URL="/"
- if [[ "$CI_COMMIT_BRANCH" =~ ^test_deployment_v[[:digit:]] ]]; then URL="https://test.webservices.krohne.com/"; fi
- if [[ "$CI_COMMIT_BRANCH" =~ ^development_deployment_v[[:digit:]] ]]; then URL="https://dev.webservices.krohne.com/"; fi
- if [[ "$CI_COMMIT_BRANCH" =~ ^production_deployment_v[[:digit:]] ]]; then URL="https://prod.webservices.krohne.com/"; fi
- cat ws.json | jq 'setpath(["servers", 0, "url"]; "'$URL'")' > ws.json-new
- rm ws.json && mv ws.json-new ws.json
.deploy_test_dev:
extends: .deploy
tags:
- test-deployment-de01rdtst01
.deploy:
stage: deploy
image: devnexus.krohne.com:18079/repository/docker-krohne/krohnedockerbash:1.1.0
except:
- tags
artifacts:
paths:
- instance.txt
- api_major_version.txt
- api_version.txt
expire_in: 1 day
needs:
- dockerize
when: manual
allow_failure: false
variables:
WEBSERVICE_PORT: 8080
before_script:
- PKG_VERSION=$(echo -e "import yaml\nwith open('openapi.yaml') as f:d=yaml.load(f)\nprint(d['info']['version'])" | python)
- REFCNT=$(git rev-list --count ${CI_COMMIT_SHA})
- VERSION=${PKG_VERSION}.${REFCNT}.${CI_COMMIT_REF_NAME}
- API_VERSION=$PKG_VERSION
- API_MAJOR_VERSION=`echo $PKG_VERSION | awk -F. '{print $1}'`
script:
- echo $INSTANCE_SPECIFIER > instance.txt
- echo -n $API_VERSION > api_version.txt
- echo -n $API_MAJOR_VERSION > api_major_version.txt
- CONTAINER_NAME="${CI_PROJECT_PATH_SLUG}-${INSTANCE_SPECIFIER}-${API_MAJOR_VERSION}"
- SERVICE_VOLUME="${CONTAINER_NAME}-data"
- SERVICE_PORT=$((SERVICE_FIRST_PORT + SERVICE_PORT_OFFSET + (API_MAJOR_VERSION - 1) % 5))
- echo "Service port is ${SERVICE_PORT}"
- docker volume inspect $SERVICE_VOLUME || docker volume create $SERVICE_VOLUME
- docker stop $CONTAINER_NAME || echo "$CONTAINER_NAME not running, anyway okay"
- docker pull $IMAGE_NAME:$VERSION
- echo "docker run -d --rm -e TZ=Europe/Berlin -p $SERVICE_PORT:$WEBSERVICE_PORT --name $CONTAINER_NAME -v $SERVICE_VOLUME:/opt/service/config -e WEBSERVICE_INSTANCE=$INSTANCE_SPECIFIER $IMAGE_NAME:$VERSION" > /start-scripts/${CONTAINER_NAME}.sh
- chmod 755 /start-scripts/${CONTAINER_NAME}.sh
- /start-scripts/${CONTAINER_NAME}.sh