Compare commits
2 Commits
fix/cl9-no
...
fix/cl9-de
| Author | SHA1 | Date | |
|---|---|---|---|
| 173071cd5c | |||
| fc73bf422f |
32
Jenkinsfile
vendored
32
Jenkinsfile
vendored
@@ -87,7 +87,8 @@ stage('Deploy') {
|
|||||||
steps {
|
steps {
|
||||||
withCredentials([sshUserPrivateKey(
|
withCredentials([sshUserPrivateKey(
|
||||||
credentialsId: "${env.DEPLOY_SSH_CREDENTIAL_ID}",
|
credentialsId: "${env.DEPLOY_SSH_CREDENTIAL_ID}",
|
||||||
keyFileVariable: 'SSH_KEY'
|
keyFileVariable: 'SSH_KEY',
|
||||||
|
usernameVariable: 'SSH_USER'
|
||||||
)]) {
|
)]) {
|
||||||
sh '''
|
sh '''
|
||||||
bash <<EOF
|
bash <<EOF
|
||||||
@@ -95,23 +96,28 @@ set -euxo pipefail
|
|||||||
|
|
||||||
SSH_OPTS="-i ${SSH_KEY} -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
SSH_OPTS="-i ${SSH_KEY} -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
||||||
|
|
||||||
|
echo "SSH user from credential: ${SSH_USER}"
|
||||||
|
echo "SSH key file path: ${SSH_KEY}"
|
||||||
|
ls -l "${SSH_KEY}"
|
||||||
|
ssh-keygen -y -f "${SSH_KEY}"
|
||||||
|
|
||||||
echo "Testing remote SSH connectivity"
|
echo "Testing remote SSH connectivity"
|
||||||
ssh ${SSH_OPTS} "${APP_USER}@${APP_HOST}" "whoami && hostname && pwd"
|
ssh ${SSH_OPTS} "${SSH_USER}@${APP_HOST}" "whoami && hostname && pwd"
|
||||||
|
|
||||||
echo "Deploying image tag: ${IMAGE_BUILD}"
|
echo "Deploying image tag: ${IMAGE_BUILD}"
|
||||||
docker image inspect "${IMAGE_BUILD}" --format='{{.Id}} {{.RepoTags}}'
|
docker image inspect "${IMAGE_BUILD}" --format='{{.Id}} {{.RepoTags}}'
|
||||||
|
|
||||||
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "mkdir -p $DEPLOY_PATH/scripts"
|
ssh ${SSH_OPTS} "$SSH_USER@$APP_HOST" "mkdir -p $DEPLOY_PATH/scripts"
|
||||||
|
|
||||||
rsync -az \
|
rsync -az \
|
||||||
-e "ssh ${SSH_OPTS}" \
|
-e "ssh ${SSH_OPTS}" \
|
||||||
docker-compose.prod.yml \
|
docker-compose.prod.yml \
|
||||||
"$APP_USER@$APP_HOST:$DEPLOY_PATH/"
|
"$SSH_USER@$APP_HOST:$DEPLOY_PATH/"
|
||||||
|
|
||||||
rsync -az \
|
rsync -az \
|
||||||
-e "ssh ${SSH_OPTS}" \
|
-e "ssh ${SSH_OPTS}" \
|
||||||
scripts/ \
|
scripts/ \
|
||||||
"$APP_USER@$APP_HOST:$DEPLOY_PATH/scripts/"
|
"$SSH_USER@$APP_HOST:$DEPLOY_PATH/scripts/"
|
||||||
|
|
||||||
IMAGE_TAR="plesk-agency-portal-build.tar"
|
IMAGE_TAR="plesk-agency-portal-build.tar"
|
||||||
echo "Creating image archive: ${IMAGE_TAR}"
|
echo "Creating image archive: ${IMAGE_TAR}"
|
||||||
@@ -120,27 +126,27 @@ ls -lh "${IMAGE_TAR}"
|
|||||||
sha256sum "${IMAGE_TAR}"
|
sha256sum "${IMAGE_TAR}"
|
||||||
|
|
||||||
echo "Copying image archive to remote host via scp"
|
echo "Copying image archive to remote host via scp"
|
||||||
scp ${SSH_OPTS} "${IMAGE_TAR}" "$APP_USER@$APP_HOST:$DEPLOY_PATH/"
|
scp ${SSH_OPTS} "${IMAGE_TAR}" "$SSH_USER@$APP_HOST:$DEPLOY_PATH/"
|
||||||
|
|
||||||
echo "Verifying image archive exists on remote host"
|
echo "Verifying image archive exists on remote host"
|
||||||
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "ls -lh $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
ssh ${SSH_OPTS} "$SSH_USER@$APP_HOST" "ls -lh $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
||||||
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "sha256sum $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
ssh ${SSH_OPTS} "$SSH_USER@$APP_HOST" "sha256sum $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
||||||
|
|
||||||
echo "Loading image archive on remote host"
|
echo "Loading image archive on remote host"
|
||||||
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "docker load -i $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
ssh ${SSH_OPTS} "$SSH_USER@$APP_HOST" "docker load -i $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
||||||
|
|
||||||
echo "Verifying exact image tag is available on remote host"
|
echo "Verifying exact image tag is available on remote host"
|
||||||
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "docker image inspect ${IMAGE_BUILD} --format='{{.Id}} {{.RepoTags}}'"
|
ssh ${SSH_OPTS} "$SSH_USER@$APP_HOST" "docker image inspect ${IMAGE_BUILD} --format='{{.Id}} {{.RepoTags}}'"
|
||||||
|
|
||||||
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" \
|
ssh ${SSH_OPTS} "$SSH_USER@$APP_HOST" \
|
||||||
"cd $DEPLOY_PATH && chmod +x ./scripts/deploy-prod.sh ./scripts/smoke-check.sh ./scripts/rollback-prod.sh"
|
"cd $DEPLOY_PATH && chmod +x ./scripts/deploy-prod.sh ./scripts/smoke-check.sh ./scripts/rollback-prod.sh"
|
||||||
|
|
||||||
echo "Running remote deploy script with exact image tag"
|
echo "Running remote deploy script with exact image tag"
|
||||||
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" \
|
ssh ${SSH_OPTS} "$SSH_USER@$APP_HOST" \
|
||||||
"cd $DEPLOY_PATH && APP_IMAGE='${IMAGE_BUILD}' ./scripts/deploy-prod.sh"
|
"cd $DEPLOY_PATH && APP_IMAGE='${IMAGE_BUILD}' ./scripts/deploy-prod.sh"
|
||||||
|
|
||||||
echo "Printing final running container image metadata"
|
echo "Printing final running container image metadata"
|
||||||
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "docker inspect plesk-agency-portal --format='{{.Image}} {{.Created}}'"
|
ssh ${SSH_OPTS} "$SSH_USER@$APP_HOST" "docker inspect plesk-agency-portal --format='{{.Image}} {{.Created}}'"
|
||||||
EOF
|
EOF
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user