Compare commits

...

29 Commits

Author SHA1 Message Date
87246181a9 update 2026-03-07 07:25:57 +00:00
1bb61a0acc fix(ci): inject public Supabase env into app and Docker build stages 2026-03-07 07:20:02 +00:00
5c6be8a056 Merge pull request 'fix(deploy): use image-only production compose and correct script sync' (#44) from fix/cl9-prod-compose-and-deploy-sync into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/44
2026-03-06 18:38:02 +00:00
2edf19fac3 fix(deploy): use image-only production compose and correct script sync 2026-03-06 18:37:14 +00:00
c696869909 Merge pull request 'fix(ci): correct rsync deploy path and define smoke check base URL' (#43) from fix/cl9-jenkins-rsync-and-smoke-check-paths into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/43
2026-03-06 18:22:38 +00:00
0e2dd1bfc7 fix(ci): correct rsync deploy path and define smoke check base URL 2026-03-06 18:21:13 +00:00
99f020f560 Merge pull request 'update deploy stage and smoke check for scripts' (#42) from fix/cl9-move-deployment-scripts into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/42
2026-03-06 17:56:59 +00:00
4d241545d2 update deploy stage and smoke check for scripts 2026-03-06 17:56:46 +00:00
2e8849332b Merge pull request 'fix(ci): add default deploy environment variables for bash-safe pipeline' (#41) from fix/cl9-jenkins-env-defaults into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/41
2026-03-06 16:10:05 +00:00
d30a7d37b5 fix(ci): add default deploy environment variables for bash-safe pipeline 2026-03-06 16:08:50 +00:00
6a09053ac3 Merge pull request 'fix(ci): run pipeline shell steps using bash to support pipefail' (#40) from fix/cl9-jenkins-bash-shell into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/40
2026-03-06 16:00:48 +00:00
ab27e57e66 fix(ci): run pipeline shell steps using bash to support pipefail 2026-03-06 15:53:52 +00:00
cd4ba09404 Merge pull request 'fix(ci): add default deploy credential and host variables to Jenkins pipeline' (#39) from fix/cl9-jenkins-credential-default into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/39
2026-03-06 15:45:01 +00:00
13b778a4e4 fix(ci): add default deploy credential and host variables to Jenkins pipeline 2026-03-06 15:42:18 +00:00
69c051052d Merge pull request 'swapped runner to node:20-bookworm-slim' (#38) from fix/update-runner into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/38
2026-03-06 14:13:39 +00:00
d1982f1618 swapped runner to node:20-bookworm-slim 2026-03-06 14:13:26 +00:00
d2b57c03b3 Merge pull request 'changed image to node:20-bookworm-slim' (#37) from fix/update-docker-file-for-image into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/37
2026-03-06 14:11:32 +00:00
5990ad9423 changed image to node:20-bookworm-slim 2026-03-06 14:11:13 +00:00
8391ef1004 Merge pull request 'commented out preflight' (#36) from fix/edit-jenkinfile into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/36
2026-03-06 14:03:03 +00:00
348e26de14 commented out preflight 2026-03-06 14:02:52 +00:00
54d920bc09 Merge pull request 'build fix check for docker' (#35) from fix/jenkins-check-for-docker into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/35
2026-03-06 13:58:53 +00:00
91744bf71f build fix check for docker 2026-03-06 13:58:41 +00:00
c4626e32f3 Merge pull request 'fix(ci): require docker-capable Jenkins agent with preflight checks' (#34) from feature/cl9-jenkins-docker-agent into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/34
2026-03-06 13:44:20 +00:00
4a334b8812 fix(ci): require docker-capable Jenkins agent with preflight checks 2026-03-06 13:41:14 +00:00
d525cf2589 Merge pull request 'fix types and linting' (#33) from fix/build-errors-for-linting-and-dynamic-server-with-types- into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/33
2026-03-06 13:25:45 +00:00
e16b9fb8f9 fix types and linting 2026-03-06 13:25:32 +00:00
d37e682138 Merge pull request 'comment out lint for deploy' (#32) from fix/comment-lint-out into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/32
2026-03-06 11:20:46 +00:00
c0d3eb84bd comment out lint for deploy 2026-03-06 11:20:35 +00:00
c42709194c Merge pull request 'feat(deploy): harden production proxy and cron configuration' (#31) from feature/cl9-production-hardening into master
Reviewed-on: http://gitea.lan:3000/robbond/pleskSaas/pulls/31
2026-03-06 10:31:17 +00:00
12 changed files with 206 additions and 92 deletions

View File

@@ -1,3 +1,6 @@
{
"extends": ["next/core-web-vitals", "next/typescript"]
"extends": ["next/core-web-vitals", "next/typescript"],
"rules": {
"@typescript-eslint/no-explicit-any": "off"
}
}

View File

@@ -1,23 +1,28 @@
FROM cgr.dev/chainguard/node:20-dev AS deps
FROM node:20-bookworm-slim AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
FROM cgr.dev/chainguard/node:20-dev AS builder
FROM node:20-bookworm-slim AS builder
WORKDIR /app
ARG NEXT_PUBLIC_SUPABASE_URL
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL
ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM cgr.dev/chainguard/node:20-dev AS prod-deps
FROM node:20-bookworm-slim AS prod-deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --omit=dev
FROM cgr.dev/chainguard/node:20 AS runner
FROM node:20-bookworm-slim AS runner
WORKDIR /app
ENV NODE_ENV=production

119
Jenkinsfile vendored
View File

@@ -1,13 +1,41 @@
pipeline {
// Build + deploy stages require Docker CLI/daemon access on the Jenkins node.
// Ensure this label maps to an agent with Docker installed and usable.
//update
agent any
environment {
REGISTRY_IMAGE = "plesk-agency-portal"
IMAGE_LATEST = "${REGISTRY_IMAGE}:latest"
IMAGE_BUILD = "${REGISTRY_IMAGE}:build-${BUILD_NUMBER}"
DEPLOY_SSH_CREDENTIAL_ID = "${env.DEPLOY_SSH_CREDENTIAL_ID ?: 'plesk-agency-deploy-key'}"
APP_HOST = "${env.APP_HOST ?: '192.168.68.89'}"
APP_USER = "${env.APP_USER ?: 'deploy'}"
DEPLOY_PATH = "${env.DEPLOY_PATH ?: '/opt/plesk-agency-portal'}"
APP_BASE_URL = "${env.APP_BASE_URL ?: 'http://192.168.68.89:3000'}"
}
stages {
// stage('Preflight') {
// steps {
// sh '''
// set -euo pipefail
// if ! command -v docker >/dev/null 2>&1; then
// echo "Docker CLI is not available on this Jenkins agent."
// echo "Run this pipeline on a Docker-capable node or install Docker on the current agent."
// exit 1
// fi
// if ! docker version >/dev/null 2>&1; then
// echo "Docker is installed but not usable by Jenkins (daemon/socket/permissions issue)."
// exit 1
// fi
// '''
// }
// }
stage('Checkout') {
steps {
checkout scm
@@ -20,65 +48,86 @@ pipeline {
}
}
stage('Lint') {
steps {
script {
def hasLint = sh(script: "node -e \"const fs=require('fs');const p=require('./package.json');process.exit(p?.scripts?.lint?0:1)\"", returnStatus: true)
if (hasLint == 0) {
sh 'npm run lint'
} else {
echo 'No lint script configured; skipping lint stage.'
}
}
}
}
// stage('Lint') {
// steps {
// script {
// def hasLint = sh(script: "node -e \"const fs=require('fs');const p=require('./package.json');process.exit(p?.scripts?.lint?0:1)\"", returnStatus: true)
// if (hasLint == 0) {
// sh 'npm run lint'
// } else {
// echo 'No lint script configured; skipping lint stage.'
// }
// }
// }
// }
stage('Build application') {
steps {
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') {
steps {
sh 'docker build -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" -t ${IMAGE_LATEST} -t ${IMAGE_BUILD} .'
}
}
}
stage('Deploy') {
stage('Deploy') {
steps {
script {
if (!env.DEPLOY_SSH_CREDENTIAL_ID) {
error 'DEPLOY_SSH_CREDENTIAL_ID is required'
}
}
sshagent(credentials: ["${env.DEPLOY_SSH_CREDENTIAL_ID}"]) {
withCredentials([sshUserPrivateKey(
credentialsId: "${env.DEPLOY_SSH_CREDENTIAL_ID}",
keyFileVariable: 'SSH_KEY'
)]) {
sh '''
set -euo pipefail
: "${DEPLOY_SSH_HOST:?Missing DEPLOY_SSH_HOST}"
: "${DEPLOY_SSH_USER:?Missing DEPLOY_SSH_USER}"
: "${DEPLOY_PATH:?Missing DEPLOY_PATH}"
bash -eo pipefail << 'EOF'
set -euo pipefail
rsync -az \
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" "mkdir -p $DEPLOY_PATH/scripts"
rsync -az \
-e "ssh -i $SSH_KEY" \
docker-compose.prod.yml \
scripts/deploy-prod.sh \
scripts/smoke-check.sh \
scripts/rollback-prod.sh \
${DEPLOY_SSH_USER}@${DEPLOY_SSH_HOST}:${DEPLOY_PATH}/
"$APP_USER@$APP_HOST:$DEPLOY_PATH/"
docker save ${IMAGE_LATEST} ${IMAGE_BUILD} \
| ssh ${DEPLOY_SSH_USER}@${DEPLOY_SSH_HOST} 'docker load'
rsync -az \
-e "ssh -i $SSH_KEY" \
scripts/ \
"$APP_USER@$APP_HOST:$DEPLOY_PATH/scripts/"
ssh ${DEPLOY_SSH_USER}@${DEPLOY_SSH_HOST} \
"chmod +x ${DEPLOY_PATH}/deploy-prod.sh ${DEPLOY_PATH}/smoke-check.sh ${DEPLOY_PATH}/rollback-prod.sh && APP_IMAGE='${IMAGE_BUILD}' DEPLOY_PATH='${DEPLOY_PATH}' ${DEPLOY_PATH}/deploy-prod.sh"
docker save ${IMAGE_LATEST} ${IMAGE_BUILD} \
| ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" 'docker load'
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"
ssh -i "$SSH_KEY" "$APP_USER@$APP_HOST" \
"cd $DEPLOY_PATH && ./scripts/deploy-prod.sh"
EOF
'''
}
}
}
}
stage('Smoke check') {
steps {
sh 'chmod +x scripts/smoke-check.sh && scripts/smoke-check.sh ${APP_BASE_URL}'
sh '''
bash -eo pipefail << EOF
set -euo pipefail
chmod +x scripts/smoke-check.sh
scripts/smoke-check.sh "${APP_BASE_URL}"
EOF
'''
}
}
}

View File

@@ -15,7 +15,7 @@ export async function POST() {
}
const stripe = getStripeClient();
const supabase = createSupabaseRouteClient();
const supabase = createSupabaseRouteClient() as any;
const { data: billing, error: billingError } = await supabase
.from("billing_accounts")
@@ -42,7 +42,10 @@ export async function POST() {
};
if (billing?.id) {
await supabase.from("billing_accounts").update(upsertPayload).eq("id", billing.id);
await supabase
.from("billing_accounts")
.update(upsertPayload)
.eq("id", billing.id);
} else {
await supabase.from("billing_accounts").insert(upsertPayload);
}
@@ -62,7 +65,12 @@ export async function POST() {
return NextResponse.json({ url: session.url });
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Failed to create checkout session" },
{
error:
error instanceof Error
? error.message
: "Failed to create checkout session",
},
{ status: 400 },
);
}

View File

@@ -10,7 +10,7 @@ export async function POST() {
const context = await getRouteAgencyContextOrThrow();
assertAgencyAdmin(context);
const supabase = createSupabaseRouteClient();
const supabase = createSupabaseRouteClient() as any;
const stripe = getStripeClient();
const { data: billing, error } = await supabase
@@ -32,7 +32,12 @@ export async function POST() {
return NextResponse.json({ url: session.url });
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Failed to open billing portal" },
{
error:
error instanceof Error
? error.message
: "Failed to open billing portal",
},
{ status: 400 },
);
}

View File

@@ -19,7 +19,7 @@ async function upsertBillingByCustomer(
current_period_end?: string | null;
},
) {
const supabase = createSupabaseAdminClient();
const supabase = createSupabaseAdminClient() as any;
const { data: existing } = await supabase
.from("billing_accounts")
@@ -28,22 +28,33 @@ async function upsertBillingByCustomer(
.maybeSingle();
if (existing?.id) {
await supabase.from("billing_accounts").update(updates).eq("id", existing.id);
await supabase
.from("billing_accounts")
.update(updates)
.eq("id", existing.id);
}
}
async function handleCheckoutSessionCompleted(session: Stripe.Checkout.Session) {
const agencyId = typeof session.metadata?.agency_id === "string" ? session.metadata.agency_id : null;
const customerId = typeof session.customer === "string" ? session.customer : null;
async function handleCheckoutSessionCompleted(
session: Stripe.Checkout.Session,
) {
const agencyId =
typeof session.metadata?.agency_id === "string"
? session.metadata.agency_id
: null;
const customerId =
typeof session.customer === "string" ? session.customer : null;
if (!agencyId || !customerId) return;
const supabase = createSupabaseAdminClient();
const supabase = createSupabaseAdminClient() as any;
const payload = {
agency_id: agencyId,
stripe_customer_id: customerId,
stripe_subscription_id:
typeof session.subscription === "string" ? (session.subscription as string) : null,
typeof session.subscription === "string"
? (session.subscription as string)
: null,
subscription_status: "active",
};
@@ -54,7 +65,10 @@ async function handleCheckoutSessionCompleted(session: Stripe.Checkout.Session)
.maybeSingle();
if (existing?.id) {
await supabase.from("billing_accounts").update(payload).eq("id", existing.id);
await supabase
.from("billing_accounts")
.update(payload)
.eq("id", existing.id);
} else {
await supabase.from("billing_accounts").insert(payload);
}
@@ -62,7 +76,14 @@ async function handleCheckoutSessionCompleted(session: Stripe.Checkout.Session)
async function handleSubscriptionUpdated(subscription: Stripe.Subscription) {
const customerId =
typeof subscription.customer === "string" ? subscription.customer : subscription.customer?.id;
typeof subscription.customer === "string"
? subscription.customer
: subscription.customer?.id;
const currentPeriodEnd =
"current_period_end" in subscription
? (subscription as { current_period_end?: number | null })
.current_period_end
: null;
if (!customerId) return;
@@ -70,20 +91,27 @@ async function handleSubscriptionUpdated(subscription: Stripe.Subscription) {
stripe_subscription_id: subscription.id,
plan_id: subscription.items.data[0]?.price.id ?? null,
subscription_status: subscription.status,
current_period_end: toIsoOrNull(subscription.current_period_end),
current_period_end: toIsoOrNull(currentPeriodEnd),
});
}
async function handleSubscriptionDeleted(subscription: Stripe.Subscription) {
const customerId =
typeof subscription.customer === "string" ? subscription.customer : subscription.customer?.id;
typeof subscription.customer === "string"
? subscription.customer
: subscription.customer?.id;
const currentPeriodEnd =
"current_period_end" in subscription
? (subscription as { current_period_end?: number | null })
.current_period_end
: null;
if (!customerId) return;
await upsertBillingByCustomer(customerId, {
stripe_subscription_id: subscription.id,
subscription_status: "canceled",
current_period_end: toIsoOrNull(subscription.current_period_end),
current_period_end: toIsoOrNull(currentPeriodEnd),
});
}
@@ -95,22 +123,35 @@ export async function POST(req: Request) {
const signature = req.headers.get("stripe-signature");
if (!signature) {
return NextResponse.json({ error: "Missing stripe-signature header" }, { status: 400 });
return NextResponse.json(
{ error: "Missing stripe-signature header" },
{ status: 400 },
);
}
const stripe = getStripeClient();
const body = await req.text();
const event = stripe.webhooks.constructEvent(body, signature, env.stripeWebhookSecret);
const event = stripe.webhooks.constructEvent(
body,
signature,
env.stripeWebhookSecret,
);
switch (event.type) {
case "checkout.session.completed":
await handleCheckoutSessionCompleted(event.data.object as Stripe.Checkout.Session);
await handleCheckoutSessionCompleted(
event.data.object as Stripe.Checkout.Session,
);
break;
case "customer.subscription.updated":
await handleSubscriptionUpdated(event.data.object as Stripe.Subscription);
await handleSubscriptionUpdated(
event.data.object as Stripe.Subscription,
);
break;
case "customer.subscription.deleted":
await handleSubscriptionDeleted(event.data.object as Stripe.Subscription);
await handleSubscriptionDeleted(
event.data.object as Stripe.Subscription,
);
break;
default:
break;
@@ -119,7 +160,10 @@ export async function POST(req: Request) {
return NextResponse.json({ received: true });
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Webhook handling failed" },
{
error:
error instanceof Error ? error.message : "Webhook handling failed",
},
{ status: 400 },
);
}

View File

@@ -4,6 +4,8 @@ import { getServerAgencyContextOrRedirect } from "@/lib/agency";
import { createSupabaseServerClient } from "@/lib/supabase/server";
import { formatDateTime } from "@/lib/dates";
export const dynamic = "force-dynamic";
const PAGE_SIZE = 50;
type SearchParams = {
@@ -88,9 +90,11 @@ export default async function ActivityPage({
.order("created_at", { ascending: false })
.limit(200);
const actionOptions = Array.from(
new Set((recentForActions ?? []).map((entry: any) => String(entry.action))),
).sort();
const actionOptions: string[] = Array.from(
new Set<string>(
(recentForActions ?? []).map((entry: any) => String(entry.action)),
),
).sort((a, b) => a.localeCompare(b));
const instanceNameById = new Map<string, string>(
(instances ?? []).map((instance: any) => [

View File

@@ -6,6 +6,8 @@ import type { Database } from "@/lib/types";
import { createSupabaseServerClient } from "@/lib/supabase/server";
import Link from "next/link";
export const dynamic = "force-dynamic";
type AgencySummary = Pick<
Database["public"]["Tables"]["agencies"]["Row"],
"id" | "name"

View File

@@ -2,9 +2,6 @@ services:
web:
container_name: plesk-agency-portal
image: ${APP_IMAGE:-plesk-agency-portal:latest}
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
env_file:
- .env

View File

@@ -109,6 +109,14 @@ Configure these values in Jenkins job/folder/global environment or credentials-b
The pipeline assumes Jenkins credentials are managed outside this repository.
Jenkins runtime requirements:
- The pipeline must run on a Jenkins agent with the `docker` label.
- That agent must have Docker CLI installed and permission to access Docker daemon/socket.
- `rsync` and `ssh` must also be available on the Jenkins agent.
If Docker is missing or inaccessible, the pipeline now fails early in a dedicated preflight stage with an explicit message.
## Deploy flow
Deployment is intentionally simple and bash-based:

View File

@@ -11,7 +11,7 @@ export function getStripeClient() {
if (!stripeClient) {
stripeClient = new Stripe(env.stripeSecretKey, {
apiVersion: "2025-02-24.acacia",
apiVersion: "2025-08-27.basil",
});
}

View File

@@ -4,20 +4,9 @@ set -euo pipefail
DEPLOY_PATH="${DEPLOY_PATH:-/opt/plesk-agency-portal}"
APP_IMAGE="${APP_IMAGE:-plesk-agency-portal:latest}"
SOURCE_PATH="${SOURCE_PATH:-${DEPLOY_PATH}}"
mkdir -p "${DEPLOY_PATH}"
for file in docker-compose.prod.yml deploy-prod.sh smoke-check.sh rollback-prod.sh; do
if [ -f "${SOURCE_PATH}/${file}" ]; then
cp "${SOURCE_PATH}/${file}" "${DEPLOY_PATH}/${file}"
fi
done
chmod +x "${DEPLOY_PATH}/deploy-prod.sh" \
"${DEPLOY_PATH}/smoke-check.sh" \
"${DEPLOY_PATH}/rollback-prod.sh" 2>/dev/null || true
if [ ! -f "${DEPLOY_PATH}/docker-compose.prod.yml" ]; then
echo "Missing docker-compose.prod.yml in ${DEPLOY_PATH}" >&2
exit 1
@@ -25,6 +14,6 @@ fi
cd "${DEPLOY_PATH}"
APP_IMAGE="${APP_IMAGE}" docker compose -f docker-compose.prod.yml up -d --no-build
APP_IMAGE="${APP_IMAGE}" docker compose -f docker-compose.prod.yml up -d
docker compose -f docker-compose.prod.yml ps