Compare commits

..

9 Commits

Author SHA1 Message Date
7d5512230f fix(deploy): make image transfer explicit and verifiable in Jenkins deploy stage 2026-03-07 08:31:54 +00:00
2915f10315 Merge pull request 'fix(deploy): reliably transfer exact build image and simplify production deploy scripts' (#49) from fix/cl9-reliable-image-deploy-and-script-sync into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/49
2026-03-07 08:14:51 +00:00
23ad8af20e fix(deploy): reliably transfer exact build image and simplify production deploy scripts 2026-03-07 08:14:10 +00:00
ea57734fa8 Merge pull request 'fix(deploy): deploy exact Jenkins image tag and force container recreation' (#48) from fix/cl9-deploy-exact-image-tag into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/48
2026-03-07 08:00:12 +00:00
0efe1a5129 fix(deploy): deploy exact Jenkins image tag and force container recreation 2026-03-07 07:59:39 +00:00
18912934f8 Merge pull request 'fix(deploy): bust Docker build cache for Next.js client build' (#47) from fix/cl9-force-fresh-docker-client-build into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/47
2026-03-07 07:51:48 +00:00
4a8e5ae853 fix(deploy): bust Docker build cache for Next.js client build 2026-03-07 07:51:20 +00:00
a2d69f8210 update 2026-03-07 07:26:41 +00:00
74b1ab02b6 Merge pull request 'fix(deploy): add smoke check retries and pass public Supabase build env' (#45) from fix/cl9-smoke-check-retries-and-build-env into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/45
2026-03-07 07:20:41 +00:00
4 changed files with 53 additions and 12 deletions

View File

@@ -9,8 +9,10 @@ WORKDIR /app
ARG NEXT_PUBLIC_SUPABASE_URL ARG NEXT_PUBLIC_SUPABASE_URL
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
ARG BUILD_CACHE_BUSTER
ENV NEXT_PUBLIC_SUPABASE_URL=${NEXT_PUBLIC_SUPABASE_URL} ENV NEXT_PUBLIC_SUPABASE_URL=${NEXT_PUBLIC_SUPABASE_URL}
ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=${NEXT_PUBLIC_SUPABASE_ANON_KEY} ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=${NEXT_PUBLIC_SUPABASE_ANON_KEY}
ENV BUILD_CACHE_BUSTER=${BUILD_CACHE_BUSTER}
COPY --from=deps /app/node_modules ./node_modules COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .

40
Jenkinsfile vendored
View File

@@ -1,6 +1,7 @@
pipeline { pipeline {
// Build + deploy stages require Docker CLI/daemon access on the Jenkins node. // Build + deploy stages require Docker CLI/daemon access on the Jenkins node.
// Ensure this label maps to an agent with Docker installed and usable. // Ensure this label maps to an agent with Docker installed and usable.
//update
agent any agent any
environment { environment {
@@ -12,8 +13,6 @@ pipeline {
APP_USER = "${env.APP_USER ?: 'deploy'}" APP_USER = "${env.APP_USER ?: 'deploy'}"
DEPLOY_PATH = "${env.DEPLOY_PATH ?: '/opt/plesk-agency-portal'}" DEPLOY_PATH = "${env.DEPLOY_PATH ?: '/opt/plesk-agency-portal'}"
APP_BASE_URL = "${env.APP_BASE_URL ?: 'http://192.168.68.89:3000'}" APP_BASE_URL = "${env.APP_BASE_URL ?: 'http://192.168.68.89:3000'}"
NEXT_PUBLIC_SUPABASE_URL = "${env.NEXT_PUBLIC_SUPABASE_URL ?: ''}"
NEXT_PUBLIC_SUPABASE_ANON_KEY = "${env.NEXT_PUBLIC_SUPABASE_ANON_KEY ?: ''}"
} }
@@ -64,13 +63,23 @@ pipeline {
stage('Build application') { stage('Build application') {
steps { steps {
sh 'npm run build' withCredentials([
string(credentialsId: 'supabase-public-url', variable: 'NEXT_PUBLIC_SUPABASE_URL'),
string(credentialsId: 'supabase-public-anon-key', variable: 'NEXT_PUBLIC_SUPABASE_ANON_KEY')
]) {
sh 'npm run build'
}
} }
} }
stage('Build Docker image') { stage('Build Docker image') {
steps { steps {
sh 'docker build --build-arg NEXT_PUBLIC_SUPABASE_URL="${NEXT_PUBLIC_SUPABASE_URL}" --build-arg NEXT_PUBLIC_SUPABASE_ANON_KEY="${NEXT_PUBLIC_SUPABASE_ANON_KEY}" -t ${IMAGE_LATEST} -t ${IMAGE_BUILD} .' withCredentials([
string(credentialsId: 'supabase-public-url', variable: 'NEXT_PUBLIC_SUPABASE_URL'),
string(credentialsId: 'supabase-public-anon-key', variable: 'NEXT_PUBLIC_SUPABASE_ANON_KEY')
]) {
sh 'docker build --build-arg NEXT_PUBLIC_SUPABASE_URL="$NEXT_PUBLIC_SUPABASE_URL" --build-arg NEXT_PUBLIC_SUPABASE_ANON_KEY="$NEXT_PUBLIC_SUPABASE_ANON_KEY" --build-arg BUILD_CACHE_BUSTER="${BUILD_NUMBER}" -t ${IMAGE_LATEST} -t ${IMAGE_BUILD} .'
}
} }
} }
@@ -81,7 +90,7 @@ stage('Deploy') {
keyFileVariable: 'SSH_KEY' keyFileVariable: 'SSH_KEY'
)]) { )]) {
sh ''' sh '''
bash -eo pipefail << 'EOF' bash -eo pipefail <<EOF
set -euo pipefail set -euo pipefail
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" "mkdir -p $DEPLOY_PATH/scripts" ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" "mkdir -p $DEPLOY_PATH/scripts"
@@ -96,14 +105,29 @@ rsync -az \
scripts/ \ scripts/ \
"$APP_USER@$APP_HOST:$DEPLOY_PATH/scripts/" "$APP_USER@$APP_HOST:$DEPLOY_PATH/scripts/"
docker save ${IMAGE_LATEST} ${IMAGE_BUILD} \ echo "Deploying image tag: ${IMAGE_BUILD}"
| ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" 'docker load'
IMAGE_TAR="plesk-agency-portal-build.tar"
echo "Creating image archive: ${IMAGE_TAR}"
docker save -o "${IMAGE_TAR}" "${IMAGE_BUILD}"
ls -lh "${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"
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"
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" \ 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" "cd $DEPLOY_PATH && chmod +x ./scripts/deploy-prod.sh ./scripts/smoke-check.sh ./scripts/rollback-prod.sh"
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" \ ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" \
"cd $DEPLOY_PATH && ./scripts/deploy-prod.sh" "cd $DEPLOY_PATH && APP_IMAGE='${IMAGE_BUILD}' ./scripts/deploy-prod.sh"
EOF EOF
''' '''
} }

View File

@@ -12,8 +12,13 @@ if [ ! -f "${DEPLOY_PATH}/docker-compose.prod.yml" ]; then
exit 1 exit 1
fi fi
if [ ! -f "${DEPLOY_PATH}/.env" ]; then
echo "Missing .env in ${DEPLOY_PATH}" >&2
exit 1
fi
cd "${DEPLOY_PATH}" cd "${DEPLOY_PATH}"
APP_IMAGE="${APP_IMAGE}" docker compose -f docker-compose.prod.yml up -d APP_IMAGE="${APP_IMAGE}" docker compose -f docker-compose.prod.yml up -d --no-build --force-recreate
docker compose -f docker-compose.prod.yml ps APP_IMAGE="${APP_IMAGE}" docker compose -f docker-compose.prod.yml ps

View File

@@ -21,10 +21,20 @@ if [ ! -f "${DEPLOY_PATH}/docker-compose.prod.yml" ]; then
exit 1 exit 1
fi fi
if [ ! -f "${DEPLOY_PATH}/.env" ]; then
echo "Missing .env in ${DEPLOY_PATH}" >&2
exit 1
fi
if [ ! -f "${DEPLOY_PATH}/scripts/smoke-check.sh" ]; then
echo "Missing scripts/smoke-check.sh in ${DEPLOY_PATH}" >&2
exit 1
fi
cd "${DEPLOY_PATH}" cd "${DEPLOY_PATH}"
APP_IMAGE="${PREVIOUS_IMAGE_TAG}" docker compose -f docker-compose.prod.yml up -d --no-build APP_IMAGE="${PREVIOUS_IMAGE_TAG}" docker compose -f docker-compose.prod.yml up -d --no-build --force-recreate
"${DEPLOY_PATH}/smoke-check.sh" "${APP_BASE_URL}" "${DEPLOY_PATH}/scripts/smoke-check.sh" "${APP_BASE_URL}"
docker compose -f docker-compose.prod.yml ps docker compose -f docker-compose.prod.yml ps