Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

Let stock self-hosted images link to Stirling with no extra config (#8338)

ConnorYoh65fb769c4b3a
diff --git a/.github/workflows/PR-Auto-Deploy-V2.yml b/.github/workflows/PR-Auto-Deploy-V2.yml
index bc6b28123d..713f6080c6 100644
--- a/.github/workflows/PR-Auto-Deploy-V2.yml
+++ b/.github/workflows/PR-Auto-Deploy-V2.yml
@@ -230,29 +230,23 @@ jobs:
PROJECT_REF: ${{ secrets.SAAS_DB_PROJECT_REF }}
API_BASE_OVERRIDE: ${{ vars.SAAS_API_BASE_URL }}
run: |
- # Set, this is the one value both halves use: the browser's portal reads and the backend's
+ # The one value both halves use: the browser's portal reads and the backend's
# register/entitlement calls have to land on the same SaaS, and nothing checks that they
- # do. Unset, only the backend gets a base, from its own compiled-in default.
- API_BASE="${API_BASE_OVERRIDE:-https://stirling.com/app}"
- echo "backend_base=${API_BASE}" >> "$GITHUB_OUTPUT"
+ # do. Unset falls back to production Stirling, which both halves also default to.
+ API_BASE="${API_BASE_OVERRIDE:-https://api2.stirling.com}"
+ echo "api_base=${API_BASE}" >> "$GITHUB_OUTPUT"
if [ -z "${PROJECT_REF}" ]; then
- echo "Not configured for this environment: the preview will build without a Stirling"
- echo "account, and the connect dialog will say so. To wire one up, set on the"
- echo "pr-preview environment the secrets SAAS_DB_PROJECT_REF and"
- echo "SAAS_SUPABASE_PUBLISHABLE_KEY, both from the same Supabase project."
+ echo "No Supabase project configured: the preview keeps the image's built-in production"
+ echo "Stirling account. To use another, set on the pr-preview environment the secrets"
+ echo "SAAS_DB_PROJECT_REF and SAAS_SUPABASE_PUBLISHABLE_KEY, both from the same Supabase"
+ echo "project, and SAAS_API_BASE_URL to its API."
echo "supabase_url=" >> "$GITHUB_OUTPUT"
- echo "frontend_base=" >> "$GITHUB_OUTPUT"
else
# Only whether, not which: the ref is a secret here, so Actions masks it out of any
# line it appears in, derived URL included.
echo "Stirling account configured, at ${API_BASE}."
echo "supabase_url=https://${PROJECT_REF}.supabase.co" >> "$GITHUB_OUTPUT"
- # Deliberately the override and not API_BASE: the backend's default is a subpath URL
- # nobody has confirmed answers /api/v1, and prod CORS does not list preview hostnames,
- # so portal reads stay off until someone sets a base they have checked. Empty leaves the
- # committed .env default alone, which is the clean "not configured" state.
- echo "frontend_base=${API_BASE_OVERRIDE}" >> "$GITHUB_OUTPUT"
fi
- name: Check if image exists
@@ -285,7 +279,7 @@ jobs:
BUILD_PORTAL=${{ env.BUILD_PORTAL }}
VITE_SUPABASE_URL=${{ steps.saas.outputs.supabase_url }}
VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY=${{ secrets.SAAS_SUPABASE_PUBLISHABLE_KEY }}
- VITE_SAAS_API_URL=${{ steps.saas.outputs.frontend_base }}
+ VITE_SAAS_API_URL=${{ steps.saas.outputs.api_base }}
platforms: linux/amd64
- name: Set up SSH
@@ -319,7 +313,7 @@ jobs:
environment:
DISABLE_ADDITIONAL_FEATURES: "false"
STIRLING_BILLING_ACCOUNT_LINK_ENABLED: "true"
- STIRLING_BILLING_ACCOUNT_LINK_SAAS_BASE_URL: "${{ steps.saas.outputs.backend_base }}"
+ STIRLING_BILLING_ACCOUNT_LINK_SAAS_BASE_URL: "${{ steps.saas.outputs.api_base }}"
# Off so preview traffic never accrues against a real wallet or trips its cap. The
# 402 gate is separate and stays on, so gating is still testable here.
STIRLING_BILLING_ACCOUNT_LINK_METERING_ENABLED: "false"
diff --git a/app/.env.proprietary b/app/.env.proprietary
index b608beaf1c..4859643239 100644
--- a/app/.env.proprietary
+++ b/app/.env.proprietary
@@ -1,10 +1,7 @@
# Committed defaults for `task backend:dev:proprietary` (self-hosted / proprietary
# flavor). Local overrides + secrets live in app/.env.proprietary.local (ignored).
-# Combined-billing account link (Mode A). On by default: the free tier is metered locally and
-# needs no Stirling account, so this gates linking rather than the feature.
-STIRLING_BILLING_ACCOUNT_LINK_ENABLED=true
-# SaaS base URL the linked instance calls (register + entitlement).
-STIRLING_BILLING_ACCOUNT_LINK_SAAS_BASE_URL=https://api2.stirling.com
-# Accrual against a linked team's cloud wallet. The local free-tier meter runs either way.
-STIRLING_BILLING_ACCOUNT_LINK_METERING_ENABLED=true
+# Account linking needs nothing here. AccountLinkProperties compiles in production Stirling
+# (linking and metering on, api2.stirling.com), the same defaults a Docker image runs with, so
+# dev exercises what ships. To link against another SaaS, set
+# STIRLING_BILLING_ACCOUNT_LINK_SAAS_BASE_URL in the .local file.
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/AccountLinkProperties.java b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/AccountLinkProperties.java
index 6f26e3cc40..6f4441aaef 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/AccountLinkProperties.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/AccountLinkProperties.java
@@ -25,8 +25,11 @@ public class AccountLinkProperties {
*/
private boolean enabled = true;
- /** Base URL of the SaaS backend this instance links to (register + entitlement live there). */
- private String saasBaseUrl = "https://stirling.com/app";
+ /**
+ * Base URL of the SaaS backend this instance links to (register + entitlement live there). The
+ * API host, not the web app: stirling.com/app answers /api/v1 with the SPA's HTML.
+ */
+ private String saasBaseUrl = "https://api2.stirling.com";
/** Cached entitlement is reused for this long before a refresh is attempted. */
private long entitlementCacheSeconds = 300;
@@ -51,8 +54,12 @@ public class AccountLinkProperties {
@Setter
public static class Metering {
- /** Turns on usage metering, the daily sync, and cap enforcement. */
- private boolean enabled = false;
+ /**
+ * Accrues a linked instance's billable usage for the sync to report to its team's wallet.
+ * Off leaves linked usage unbilled. {@link UsageMeterService} also treats a missing
+ * property as on, so keep the two defaults together.
+ */
+ private boolean enabled = true;
/**
* How often the instance syncs usage + refreshes entitlement (matches the licence sync).
diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/UsageMeterService.java b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/UsageMeterService.java
index 8e7db81453..a488382dd4 100644
--- a/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/UsageMeterService.java
+++ b/app/proprietary/src/main/java/stirling/software/proprietary/accountlink/UsageMeterService.java
@@ -26,7 +26,8 @@ import stirling.software.proprietary.billing.BillingStepLimit;
@Profile("!saas")
@ConditionalOnProperty(
name = "stirling.billing.account-link.metering.enabled",
- havingValue = "true")
+ havingValue = "true",
+ matchIfMissing = true)
public class UsageMeterService {
private final UsageCounterRepository repo;
diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/UsageMeterServiceConditionTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/UsageMeterServiceConditionTest.java
new file mode 100644
index 0000000000..3ea3a45467
--- /dev/null
+++ b/app/proprietary/src/test/java/stirling/software/proprietary/accountlink/UsageMeterServiceConditionTest.java
@@ -0,0 +1,59 @@
+package stirling.software.proprietary.accountlink;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * A stock install sets no metering property, so the bean condition and the bound default have to
+ * agree on "on" by themselves: the meter accrues and the sync reports, or linked usage goes
+ * unbilled.
+ */
+class UsageMeterServiceConditionTest {
+
+ private final ApplicationContextRunner runner =
+ new ApplicationContextRunner()
+ .withBean(
+ UsageCounterRepository.class, () -> mock(UsageCounterRepository.class))
+ .withBean(
+ MeteredInputSignatureRepository.class,
+ () -> mock(MeteredInputSignatureRepository.class))
+ .withUserConfiguration(BoundProperties.class, UsageMeterService.class);
+
+ @Test
+ void metersWhenThePropertyIsAbsent() {
+ runner.run(
+ context -> {
+ assertThat(context).hasNotFailed().hasSingleBean(UsageMeterService.class);
+ assertThat(
+ context.getBean(AccountLinkProperties.class)
+ .getMetering()
+ .isEnabled())
+ .isTrue();
+ });
+ }
+
+ @Test
+ void turnsOffTogether() {
+ runner.withPropertyValues("stirling.billing.account-link.metering.enabled=false")
+ .run(
+ context -> {
+ assertThat(context)
+ .hasNotFailed()
+ .doesNotHaveBean(UsageMeterService.class);
+ assertThat(
+ context.getBean(AccountLinkProperties.class)
+ .getMetering()
+ .isEnabled())
+ .isFalse();
+ });
+ }
+
+ @Configuration(proxyBeanMethods = false)
+ @EnableConfigurationProperties(AccountLinkProperties.class)
+ static class BoundProperties {}
+}
diff --git a/docker/embedded/Dockerfile b/docker/embedded/Dockerfile
index e7e236b799..c33b967b87 100644
--- a/docker/embedded/Dockerfile
+++ b/docker/embedded/Dockerfile
@@ -62,22 +62,24 @@ ENV STIRLING_FLAVOR=${STIRLING_FLAVOR}
ARG BUILD_PORTAL=true
# Which Stirling account the portal connects to. Build-time because Vite inlines VITE_* into the
-# bundle; there is no runtime override. Empty leaves the committed .env.proprietary defaults, which
-# is what an ordinary image wants: no Stirling account and no connect flow. The publishable key is
-# client-side by design, not a secret. Pass the URL and the key from the same Supabase project or
-# the browser accepts the pair and Supabase rejects it, which surfaces later as "session expired".
+# bundle; there is no runtime override. Empty keeps the committed frontend .env defaults, which are
+# production Stirling, so a stock image links with no build args. Overriding VITE_SAAS_API_URL
+# also means setting STIRLING_BILLING_ACCOUNT_LINK_SAAS_BASE_URL on the container, or the browser
+# and the server link against different SaaS. The publishable key is client-side by design, not a
+# secret. Pass the URL and the key from the same Supabase project or the browser accepts the pair
+# and Supabase rejects it, which surfaces later as "session expired".
ARG VITE_SUPABASE_URL=""
ARG VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY=""
ARG VITE_SAAS_API_URL=""
# Bundle only the JPDFium native for this image's target arch.
ARG TARGETARCH
-# Exported only when non-empty: Vite reads process.env ahead of the .env files, so exporting an
-# empty value would blank the committed default rather than fall back to it.
+# Every ARG reaches RUN as an environment variable, empty ones included, and Vite lets any VITE_*
+# in process.env beat the .env files. Unset the empty ones or they blank the committed defaults.
RUN JPDFIUM_PLATFORM="$([ "$TARGETARCH" = arm64 ] && echo linux-arm64 || echo linux-x64)" && \
- if [ -n "${VITE_SUPABASE_URL}" ]; then export VITE_SUPABASE_URL="${VITE_SUPABASE_URL}"; fi; \
- if [ -n "${VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY}" ]; then export VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY="${VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY}"; fi; \
- if [ -n "${VITE_SAAS_API_URL}" ]; then export VITE_SAAS_API_URL="${VITE_SAAS_API_URL}"; fi; \
+ if [ -z "${VITE_SUPABASE_URL}" ]; then unset VITE_SUPABASE_URL; fi; \
+ if [ -z "${VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY}" ]; then unset VITE_SUPABASE_PUBLISHABLE_DEFAULT_KEY; fi; \
+ if [ -z "${VITE_SAAS_API_URL}" ]; then unset VITE_SAAS_API_URL; fi; \
STIRLING_FLAVOR=${STIRLING_FLAVOR} \
gradle clean build \
-PbuildWithFrontend=true \
diff --git a/frontend/editor/.env.proprietary b/frontend/editor/.env.proprietary
index 141fe3d4e2..378198f53c 100644
--- a/frontend/editor/.env.proprietary
+++ b/frontend/editor/.env.proprietary
@@ -13,17 +13,11 @@
# VITE_EDITOR_URL=http://localhost:5173/).
VITE_EDITOR_URL=/
-# Hosted SaaS Supabase project for the self-hosted portal's IN-APP account
-# linking (both values are public). Set per deploy; absent -> the account-link
-# UI shows a "configure" state. For local e2e, point these at the SaaS Supabase
-# project the local backend links against.
-VITE_SAAS_SUPABASE_URL=
-VITE_SAAS_SUPABASE_ANON_KEY=
-
-# Hosted SaaS Java backend base URL (e.g. https://api.stirlingpdf.com). Used for
-# ATTENDED portal -> SaaS reads (wallet, billing, plans, checkout) with the
-# admin's Supabase JWT. Distinct from the local backend (reached same-origin via
-# the editor's vite proxy). Absent -> wallet/billing surfaces stay on the mock.
+# Hosted SaaS Java backend, for ATTENDED portal -> SaaS reads (wallet, billing,
+# plans, checkout) with the admin's Supabase JWT. Distinct from the local
+# backend (reached same-origin via the editor's vite proxy). Must be the SaaS
+# the backend links to: stirling.billing.account-link.saas-base-url defaults to
+# this host, and nothing checks that the two agree.
VITE_SAAS_API_URL=https://api2.stirling.com
# Browser destination for cloud account management, including the app base path.