Merge pull request 'fix(ci): make deploy SSH commands non-interactive and fail fast' (#53) from fix/cl9-noninteractive-ssh-deploy into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/53
This commit was merged in pull request #53.
This commit is contained in:
27
Jenkinsfile
vendored
27
Jenkinsfile
vendored
@@ -93,18 +93,23 @@ stage('Deploy') {
|
|||||||
bash <<EOF
|
bash <<EOF
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
||||||
|
SSH_OPTS="-i ${SSH_KEY} -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
|
||||||
|
|
||||||
|
echo "Testing remote SSH connectivity"
|
||||||
|
ssh ${SSH_OPTS} "${APP_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 -i "$SSH_KEY" "$APP_USER@$APP_HOST" "mkdir -p $DEPLOY_PATH/scripts"
|
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "mkdir -p $DEPLOY_PATH/scripts"
|
||||||
|
|
||||||
rsync -az \
|
rsync -az \
|
||||||
-e "ssh -i $SSH_KEY" \
|
-e "ssh ${SSH_OPTS}" \
|
||||||
docker-compose.prod.yml \
|
docker-compose.prod.yml \
|
||||||
"$APP_USER@$APP_HOST:$DEPLOY_PATH/"
|
"$APP_USER@$APP_HOST:$DEPLOY_PATH/"
|
||||||
|
|
||||||
rsync -az \
|
rsync -az \
|
||||||
-e "ssh -i $SSH_KEY" \
|
-e "ssh ${SSH_OPTS}" \
|
||||||
scripts/ \
|
scripts/ \
|
||||||
"$APP_USER@$APP_HOST:$DEPLOY_PATH/scripts/"
|
"$APP_USER@$APP_HOST:$DEPLOY_PATH/scripts/"
|
||||||
|
|
||||||
@@ -115,27 +120,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 -i "$SSH_KEY" "${IMAGE_TAR}" "$APP_USER@$APP_HOST:$DEPLOY_PATH/"
|
scp ${SSH_OPTS} "${IMAGE_TAR}" "$APP_USER@$APP_HOST:$DEPLOY_PATH/"
|
||||||
|
|
||||||
echo "Verifying image archive exists on remote host"
|
echo "Verifying image archive exists on remote host"
|
||||||
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" "ls -lh $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "ls -lh $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
||||||
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" "sha256sum $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
ssh ${SSH_OPTS} "$APP_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 -i "$SSH_KEY" "$APP_USER@$APP_HOST" "docker load -i $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
ssh ${SSH_OPTS} "$APP_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 -i "$SSH_KEY" "$APP_USER@$APP_HOST" "docker image inspect ${IMAGE_BUILD} --format='{{.Id}} {{.RepoTags}}'"
|
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "docker image inspect ${IMAGE_BUILD} --format='{{.Id}} {{.RepoTags}}'"
|
||||||
|
|
||||||
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" \
|
ssh ${SSH_OPTS} "$APP_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 -i "$SSH_KEY" "$APP_USER@$APP_HOST" \
|
ssh ${SSH_OPTS} "$APP_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 -i "$SSH_KEY" "$APP_USER@$APP_HOST" "docker inspect plesk-agency-portal --format='{{.Image}} {{.Created}}'"
|
ssh ${SSH_OPTS} "$APP_USER@$APP_HOST" "docker inspect plesk-agency-portal --format='{{.Image}} {{.Created}}'"
|
||||||
EOF
|
EOF
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user