Skip to content
Snippets Groups Projects
Commit 87825655 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Make use of environments for CI deployment

Refactored deployment script to allow flexible deployments for different
hosts and environments.
parent 732ccd6d
Branches
Tags
No related merge requests found
......@@ -65,20 +65,50 @@ package:
script:
- mvn package -DskipTests
tomcat_production:
.deploy: &deploy
stage: deploy
only:
- production
tags:
- curl
- python
when: manual
variables:
DEPLOY_CONTEXT: api
GIT_STRATEGY: none
script:
- curl --fail --upload-file $WAR_FILE "https://$PROD_TOMCAT_USER:$PROD_TOMCAT_PASSWORD@$PROD_TOMCAT_HOST/manager/text/deploy?path=%2Fapi&update=true"
# Do some variable magic to access host-specific variables
- PREFIX=$(echo $CI_ENVIRONMENT_NAME | tr '.:/-' '_')
- HOST_VAR=${PREFIX}__HOST TOMCAT_PASSWORD_VAR=${PREFIX}__TOMCAT_PASSWORD TOMCAT_USER_VAR=${PREFIX}__TOMCAT_USER
- "[ -z \"${!HOST_VAR}\" ] && echo \"No configuration for $DEPLOY_HOST found.\" && exit 1"
# Abort if there are too many users online
- USER_COUNT=$(curl -fsSL ${CI_ENVIRONMENT_URL}statistics | python -c "import sys, json; data=json.loads(sys.stdin.read()); print(data['activeUsers']);")
- "[ \"$USER_COUNT\" -ge 10 ] && [ -z \"$FORCE\" ] && echo \"Too many users ($USER_COUNT) online.\" && exit 1"
# Deploy .war file to Tomcat
- curl -fsS --upload-file $WAR_FILE "https://${!TOMCAT_USER_VAR}:${!TOMCAT_PASSWORD_VAR}@${!HOST_VAR}/manager/text/deploy?path=%2F${DEPLOY_CONTEXT}&update=true"
tomcat_production:
<<: *deploy
environment:
name: production/$PROD_DEPLOY_HOST
url: https://$PROD_DEPLOY_HOST/$DEPLOY_CONTEXT/
only:
variables:
- $PROD_DEPLOY_HOST
# GitLab 11.0+
#- $PROD_DEPLOY_HOST =~ /^([a-z0-9-]+\.)*[a-z0-9-]+(:[0-9]+)?$/
refs:
- /^v[0-9]+/
- /^[0-9]+\.[0-9]+$/
before_script:
- DEPLOY_HOST=$PROD_DEPLOY_HOST
tomcat_development:
stage: deploy
<<: *deploy
environment:
name: development/$DEV_DEPLOY_HOST
url: https://$DEV_DEPLOY_HOST/api/
only:
- staging
tags:
- curl
script:
- curl --fail --upload-file $WAR_FILE "https://$DEV_TOMCAT_USER:$DEV_TOMCAT_PASSWORD@$DEV_TOMCAT_HOST/manager/text/deploy?path=%2Fapi&update=true"
variables:
- $DEV_DEPLOY_HOST
# GitLab 11.0+
#- $DEV_DEPLOY_HOST =~ /^([a-z0-9-]+\.)*[a-z0-9-]+(:[0-9]+)?$/
before_script:
- DEPLOY_HOST=$DEV_DEPLOY_HOST
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment