Skip to content
Snippets Groups Projects
Commit 011b7564 authored by Lene Wasskog's avatar Lene Wasskog
Browse files

chore: Document (and reorganise) ci/cd deploy

parent d968b7d5
No related branches found
No related tags found
No related merge requests found
Pipeline #2496 passed
...@@ -55,14 +55,21 @@ test: ...@@ -55,14 +55,21 @@ test:
deploy-to-staging: deploy-to-staging:
stage: deploy stage: deploy
script: script:
# Authentication setup
- mkdir -p ~/.ssh - mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa - echo "$SSH_PRIVATE_KEY" >> ~/.ssh/id_dsa
- chmod 600 ~/.ssh/id_dsa - chmod 600 ~/.ssh/id_dsa
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
# Find name of war file in target folder (built previously in build stage), exit if none exists
- WAR_FILE=$(find target -maxdepth 1 -type f -name "*.war" | sort -n | tail -1 | xargs basename) - WAR_FILE=$(find target -maxdepth 1 -type f -name "*.war" | sort -n | tail -1 | xargs basename)
- if [ -z "$WAR_FILE" ]; then echo "No war file found in target directory"; exit 1; fi - if [ -z "$WAR_FILE" ]; then echo "No war file found in target directory"; exit 1; fi
# Create temporary directory on server, copy war file and deployment script there
- echo "Create temporary directory on the server" - echo "Create temporary directory on the server"
- ssh $SERVER_USER@$SERVER_IP "mkdir -p $TMP_PATH" - ssh $SERVER_USER@$SERVER_IP "mkdir -p $TMP_PATH"
- scp target/$WAR_FILE $SERVER_USER@$SERVER_IP:$TMP_PATH
- echo "deploy $TMP_PATH/$WAR_FILE --force" > deploy.cli
- scp deploy.cli $SERVER_USER@$SERVER_IP:$TMP_PATH
# Find version of currently deployed appliation, archive timestamped war file. Skip if no deployed war file is found.
- echo "Archive currently deployed application" - echo "Archive currently deployed application"
- CURRENT_VERSION=$(ssh $SERVER_USER@$SERVER_IP "ls $DEPLOYMENT_PATH/VIPSCore-*.war | head -n 1 | sed -n 's/.*VIPSCore-\(.*\)\.war/\1/p'") - CURRENT_VERSION=$(ssh $SERVER_USER@$SERVER_IP "ls $DEPLOYMENT_PATH/VIPSCore-*.war | head -n 1 | sed -n 's/.*VIPSCore-\(.*\)\.war/\1/p'")
- | - |
...@@ -70,17 +77,19 @@ deploy-to-staging: ...@@ -70,17 +77,19 @@ deploy-to-staging:
TIMESTAMP=$(date +'%Y%m%d%H%M%S') TIMESTAMP=$(date +'%Y%m%d%H%M%S')
ssh $SERVER_USER@$SERVER_IP "mv $DEPLOYMENT_PATH/VIPSCore-${CURRENT_VERSION}.war $ARCHIVE_PATH/VIPSCore-${CURRENT_VERSION}-${TIMESTAMP}.war" ssh $SERVER_USER@$SERVER_IP "mv $DEPLOYMENT_PATH/VIPSCore-${CURRENT_VERSION}.war $ARCHIVE_PATH/VIPSCore-${CURRENT_VERSION}-${TIMESTAMP}.war"
else else
echo "No matching file found. Skipping archive step." echo "No matching war file found. Skip archive step."
fi fi
# Deploy war file using JBoss CLI and credentials given in CI/CD variables
- echo "Deploy $WAR_FILE using JBoss CLI" - echo "Deploy $WAR_FILE using JBoss CLI"
- scp target/$WAR_FILE $SERVER_USER@$SERVER_IP:$TMP_PATH
- echo "deploy $TMP_PATH/$WAR_FILE --force" > deploy.cli
- scp deploy.cli $SERVER_USER@$SERVER_IP:$TMP_PATH
- ssh $SERVER_USER@$SERVER_IP "/disks/data01/wildfly/wildfly-25.0.1.Final/bin/jboss-cli.sh --user=$WILDFLY_ADMIN_USERNAME --password=$WILDFLY_ADMIN_PASSWORD --connect --file=$TMP_PATH/deploy.cli" - ssh $SERVER_USER@$SERVER_IP "/disks/data01/wildfly/wildfly-25.0.1.Final/bin/jboss-cli.sh --user=$WILDFLY_ADMIN_USERNAME --password=$WILDFLY_ADMIN_PASSWORD --connect --file=$TMP_PATH/deploy.cli"
# Restart should not be necessary
- echo "Restart WildFly" - echo "Restart WildFly"
- ssh $SERVER_USER@$SERVER_IP "sudo systemctl restart wildfly" - ssh $SERVER_USER@$SERVER_IP "sudo systemctl restart wildfly"
# Delete temporary directory on server
- echo "Delete temporary directory" - echo "Delete temporary directory"
- ssh $SERVER_USER@$SERVER_IP "rm -rf $TMP_PATH" - ssh $SERVER_USER@$SERVER_IP "rm -rf $TMP_PATH"
after_script:
- echo "Deployment complete"
tags: tags:
- vips-java - vips-java
rules: rules:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment