fix(deploy): add explicit image transfer verification to Jenkins deploy stage #51
18
Jenkinsfile
vendored
18
Jenkinsfile
vendored
@@ -90,8 +90,10 @@ stage('Deploy') {
|
||||
keyFileVariable: 'SSH_KEY'
|
||||
)]) {
|
||||
sh '''
|
||||
bash -eo pipefail <<EOF
|
||||
set -euo pipefail
|
||||
set -euxo pipefail
|
||||
|
||||
echo "Deploying image tag: ${IMAGE_BUILD}"
|
||||
docker image inspect "${IMAGE_BUILD}" --format='{{.Id}} {{.RepoTags}}'
|
||||
|
||||
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" "mkdir -p $DEPLOY_PATH/scripts"
|
||||
|
||||
@@ -105,30 +107,34 @@ rsync -az \
|
||||
scripts/ \
|
||||
"$APP_USER@$APP_HOST:$DEPLOY_PATH/scripts/"
|
||||
|
||||
echo "Deploying image tag: ${IMAGE_BUILD}"
|
||||
|
||||
IMAGE_TAR="plesk-agency-portal-build.tar"
|
||||
echo "Creating image archive: ${IMAGE_TAR}"
|
||||
docker save -o "${IMAGE_TAR}" "${IMAGE_BUILD}"
|
||||
ls -lh "${IMAGE_TAR}"
|
||||
sha256sum "${IMAGE_TAR}"
|
||||
|
||||
echo "Copying image archive to remote host via scp"
|
||||
scp -i "$SSH_KEY" "${IMAGE_TAR}" "$APP_USER@$APP_HOST:$DEPLOY_PATH/"
|
||||
|
||||
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 -i "$SSH_KEY" "$APP_USER@$APP_HOST" "sha256sum $DEPLOY_PATH/plesk-agency-portal-build.tar"
|
||||
|
||||
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 -i "$SSH_KEY" "$APP_USER@$APP_HOST" "docker images | grep plesk-agency-portal || true"
|
||||
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 -i "$SSH_KEY" "$APP_USER@$APP_HOST" \
|
||||
"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"
|
||||
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" \
|
||||
"cd $DEPLOY_PATH && APP_IMAGE='${IMAGE_BUILD}' ./scripts/deploy-prod.sh"
|
||||
EOF
|
||||
|
||||
echo "Printing final running container image metadata"
|
||||
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" "docker inspect plesk-agency-portal --format='{{.Image}} {{.Created}}'"
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user