@ankhorage/infra-supabase 0.0.0-stage → 0.5.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/dist/constants/infra.d.ts +11 -0
- package/dist/constants/infra.d.ts.map +1 -0
- package/dist/constants/infra.js +4 -0
- package/dist/constants/infra.js.map +1 -0
- package/dist/features/platform-infrastructure/adapters/outbound/createFetchSupabaseControlPlane.d.ts +9 -0
- package/dist/features/platform-infrastructure/adapters/outbound/createFetchSupabaseControlPlane.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/adapters/outbound/createFetchSupabaseControlPlane.js +89 -0
- package/dist/features/platform-infrastructure/adapters/outbound/createFetchSupabaseControlPlane.js.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/destroySupabaseAsync.d.ts +5 -0
- package/dist/features/platform-infrastructure/application/use-cases/destroySupabaseAsync.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/destroySupabaseAsync.js +64 -0
- package/dist/features/platform-infrastructure/application/use-cases/destroySupabaseAsync.js.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/getSupabaseStatusAsync.d.ts +5 -0
- package/dist/features/platform-infrastructure/application/use-cases/getSupabaseStatusAsync.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/getSupabaseStatusAsync.js +59 -0
- package/dist/features/platform-infrastructure/application/use-cases/getSupabaseStatusAsync.js.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/planSupabase.d.ts +4 -0
- package/dist/features/platform-infrastructure/application/use-cases/planSupabase.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/planSupabase.js +37 -0
- package/dist/features/platform-infrastructure/application/use-cases/planSupabase.js.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/prepareSupabaseBootstrapCredentialsAsync.d.ts +4 -0
- package/dist/features/platform-infrastructure/application/use-cases/prepareSupabaseBootstrapCredentialsAsync.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/prepareSupabaseBootstrapCredentialsAsync.js +63 -0
- package/dist/features/platform-infrastructure/application/use-cases/prepareSupabaseBootstrapCredentialsAsync.js.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/reconcileSupabaseAsync.d.ts +5 -0
- package/dist/features/platform-infrastructure/application/use-cases/reconcileSupabaseAsync.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/reconcileSupabaseAsync.js +66 -0
- package/dist/features/platform-infrastructure/application/use-cases/reconcileSupabaseAsync.js.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/resolveSupabaseBootstrapCredentialsAsync.d.ts +5 -0
- package/dist/features/platform-infrastructure/application/use-cases/resolveSupabaseBootstrapCredentialsAsync.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/resolveSupabaseBootstrapCredentialsAsync.js +8 -0
- package/dist/features/platform-infrastructure/application/use-cases/resolveSupabaseBootstrapCredentialsAsync.js.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/validateSupabaseAsync.d.ts +4 -0
- package/dist/features/platform-infrastructure/application/use-cases/validateSupabaseAsync.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/validateSupabaseAsync.js +26 -0
- package/dist/features/platform-infrastructure/application/use-cases/validateSupabaseAsync.js.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/validateSupabasePersistenceCredentialsAsync.d.ts +4 -0
- package/dist/features/platform-infrastructure/application/use-cases/validateSupabasePersistenceCredentialsAsync.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/application/use-cases/validateSupabasePersistenceCredentialsAsync.js +42 -0
- package/dist/features/platform-infrastructure/application/use-cases/validateSupabasePersistenceCredentialsAsync.js.map +1 -0
- package/dist/features/platform-infrastructure/composition/createInfraAdapter.d.ts +12 -0
- package/dist/features/platform-infrastructure/composition/createInfraAdapter.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/composition/createInfraAdapter.js +37 -0
- package/dist/features/platform-infrastructure/composition/createInfraAdapter.js.map +1 -0
- package/dist/features/platform-infrastructure/constants/databaseBootstrap.d.ts +5 -0
- package/dist/features/platform-infrastructure/constants/databaseBootstrap.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/constants/databaseBootstrap.js +233 -0
- package/dist/features/platform-infrastructure/constants/databaseBootstrap.js.map +1 -0
- package/dist/features/platform-infrastructure/constants/recovery.d.ts +4 -0
- package/dist/features/platform-infrastructure/constants/recovery.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/constants/recovery.js +4 -0
- package/dist/features/platform-infrastructure/constants/recovery.js.map +1 -0
- package/dist/features/platform-infrastructure/constants/supabase.d.ts +18 -0
- package/dist/features/platform-infrastructure/constants/supabase.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/constants/supabase.js +103 -0
- package/dist/features/platform-infrastructure/constants/supabase.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseAuthWorkload.d.ts +4 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseAuthWorkload.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseAuthWorkload.js +53 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseAuthWorkload.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseBackupWorkload.d.ts +4 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseBackupWorkload.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseBackupWorkload.js +212 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseBackupWorkload.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseDataRestoreWorkload.d.ts +4 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseDataRestoreWorkload.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseDataRestoreWorkload.js +111 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseDataRestoreWorkload.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabasePersistence.d.ts +4 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabasePersistence.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabasePersistence.js +19 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabasePersistence.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseRestore.d.ts +13 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseRestore.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseRestore.js +147 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseRestore.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseOperationalWorkloads.d.ts +4 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseOperationalWorkloads.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseOperationalWorkloads.js +103 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseOperationalWorkloads.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseS3Values.d.ts +14 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseS3Values.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseS3Values.js +30 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseS3Values.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseStorageWorkload.d.ts +4 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseStorageWorkload.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseStorageWorkload.js +100 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseStorageWorkload.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseWorkloads.d.ts +4 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseWorkloads.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseWorkloads.js +234 -0
- package/dist/features/platform-infrastructure/domain/createSupabaseWorkloads.js.map +1 -0
- package/dist/features/platform-infrastructure/domain/resolveSupabaseDesiredState.d.ts +5 -0
- package/dist/features/platform-infrastructure/domain/resolveSupabaseDesiredState.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/domain/resolveSupabaseDesiredState.js +88 -0
- package/dist/features/platform-infrastructure/domain/resolveSupabaseDesiredState.js.map +1 -0
- package/dist/features/platform-infrastructure/utils/resolveSupabaseControlPlaneUrl.d.ts +4 -0
- package/dist/features/platform-infrastructure/utils/resolveSupabaseControlPlaneUrl.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/utils/resolveSupabaseControlPlaneUrl.js +45 -0
- package/dist/features/platform-infrastructure/utils/resolveSupabaseControlPlaneUrl.js.map +1 -0
- package/dist/features/platform-infrastructure/utils/validateSupabaseBootstrapCredentials.d.ts +5 -0
- package/dist/features/platform-infrastructure/utils/validateSupabaseBootstrapCredentials.d.ts.map +1 -0
- package/dist/features/platform-infrastructure/utils/validateSupabaseBootstrapCredentials.js +66 -0
- package/dist/features/platform-infrastructure/utils/validateSupabaseBootstrapCredentials.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/types/supabase.d.ts +34 -0
- package/dist/types/supabase.d.ts.map +1 -0
- package/dist/types/supabase.js +2 -0
- package/dist/types/supabase.js.map +1 -0
- package/package.json +67 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseDatabaseRestore.d.ts","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseDatabaseRestore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AA6HpC,0FAA0F;AAC1F,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,iCAAiC,CAuBnC;AAED,UAAU,iCAAiC;IACzC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;IACnE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,QAAQ,CAAC,UAAU,CAAC,EAAE;QACpB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;QACpC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;KAClC,CAAC;CACH"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { SUPABASE_RECOVERY_SCHEMA, SUPABASE_RECOVERY_STATE_TABLE } from '../constants/recovery';
|
|
2
|
+
import { createSupabaseS3Values } from './createSupabaseS3Values';
|
|
3
|
+
const RESTORE_POINTER_ATTEMPTS = 60;
|
|
4
|
+
const RESTORE_POINTER_DELAY_SECONDS = 2;
|
|
5
|
+
const RESTORE_PENDING_FILE = '.ankhorage-restore-pending';
|
|
6
|
+
const RECOVERY_STATE_RELATION = `"${SUPABASE_RECOVERY_SCHEMA}"."${SUPABASE_RECOVERY_STATE_TABLE}"`;
|
|
7
|
+
const RESTORE_ENTRYPOINT_SCRIPT = `
|
|
8
|
+
set -eu
|
|
9
|
+
data="\${PGDATA:-/var/lib/postgresql/data}"
|
|
10
|
+
marker="$data/${RESTORE_PENDING_FILE}"
|
|
11
|
+
if [ -f "$marker" ]; then
|
|
12
|
+
echo 'Retrying an interrupted database restore from a fresh Postgres data directory.'
|
|
13
|
+
find "$data" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +
|
|
14
|
+
fi
|
|
15
|
+
exec /usr/local/bin/docker-entrypoint.sh "$@"
|
|
16
|
+
`;
|
|
17
|
+
const RESTORE_SCRIPT = `
|
|
18
|
+
set -eu
|
|
19
|
+
umask 077
|
|
20
|
+
data="\${PGDATA:-/var/lib/postgresql/data}"
|
|
21
|
+
marker="$data/${RESTORE_PENDING_FILE}"
|
|
22
|
+
cleanup() {
|
|
23
|
+
rm -f /tmp/ankhorage-s3-curl.conf /tmp/ankhorage-latest /tmp/ankhorage-roles.sql \
|
|
24
|
+
/tmp/ankhorage-schema.sql
|
|
25
|
+
}
|
|
26
|
+
download_file() {
|
|
27
|
+
key="$1"
|
|
28
|
+
file="$2"
|
|
29
|
+
status="$(curl --silent --show-error --connect-timeout 2 --max-time 30 \
|
|
30
|
+
--retry 10 --retry-all-errors --retry-delay 2 \
|
|
31
|
+
--config /tmp/ankhorage-s3-curl.conf \
|
|
32
|
+
--aws-sigv4 "aws:amz:\${S3_REGION}:s3" --output "$file" --write-out '%{http_code}' \
|
|
33
|
+
"\${S3_URL_PREFIX}/$key" || true)"
|
|
34
|
+
if [ "$status" != '200' ]; then
|
|
35
|
+
echo "Database backup file $key failed to download with HTTP $status." >&2
|
|
36
|
+
return 1
|
|
37
|
+
fi
|
|
38
|
+
}
|
|
39
|
+
create_recovery_state() {
|
|
40
|
+
psql --set ON_ERROR_STOP=1 --dbname "$POSTGRES_DB" <<'SQL'
|
|
41
|
+
CREATE SCHEMA IF NOT EXISTS "${SUPABASE_RECOVERY_SCHEMA}";
|
|
42
|
+
CREATE TABLE IF NOT EXISTS ${RECOVERY_STATE_RELATION} (
|
|
43
|
+
id text PRIMARY KEY,
|
|
44
|
+
backup_prefix text,
|
|
45
|
+
data_restored boolean NOT NULL
|
|
46
|
+
);
|
|
47
|
+
SQL
|
|
48
|
+
}
|
|
49
|
+
trap cleanup EXIT INT TERM
|
|
50
|
+
touch "$marker"
|
|
51
|
+
printf 'user = "%s:%s"\n' "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" > /tmp/ankhorage-s3-curl.conf
|
|
52
|
+
|
|
53
|
+
echo 'Checking for a database backup to restore.'
|
|
54
|
+
attempt=1
|
|
55
|
+
status='000'
|
|
56
|
+
while [ "$attempt" -le "${RESTORE_POINTER_ATTEMPTS}" ]; do
|
|
57
|
+
status="$(curl --silent --show-error --connect-timeout 2 --max-time 5 \
|
|
58
|
+
--config /tmp/ankhorage-s3-curl.conf \
|
|
59
|
+
--aws-sigv4 "aws:amz:\${S3_REGION}:s3" --output /tmp/ankhorage-latest --write-out '%{http_code}' \
|
|
60
|
+
"\${S3_URL_PREFIX}/database/latest" || true)"
|
|
61
|
+
case "$status" in
|
|
62
|
+
200|404) break ;;
|
|
63
|
+
401|403)
|
|
64
|
+
echo "Database backup pointer request failed with HTTP $status." >&2
|
|
65
|
+
return 1
|
|
66
|
+
;;
|
|
67
|
+
*)
|
|
68
|
+
echo "Database backup pointer is not reachable yet (HTTP $status); retrying."
|
|
69
|
+
sleep "${RESTORE_POINTER_DELAY_SECONDS}"
|
|
70
|
+
attempt="$((attempt + 1))"
|
|
71
|
+
;;
|
|
72
|
+
esac
|
|
73
|
+
done
|
|
74
|
+
|
|
75
|
+
create_recovery_state
|
|
76
|
+
if [ "$status" = '404' ]; then
|
|
77
|
+
echo 'No database backup exists yet; continuing with a fresh database.'
|
|
78
|
+
psql --set ON_ERROR_STOP=1 --dbname "$POSTGRES_DB" <<'SQL'
|
|
79
|
+
INSERT INTO ${RECOVERY_STATE_RELATION} (id, backup_prefix, data_restored)
|
|
80
|
+
VALUES ('latest', NULL, TRUE)
|
|
81
|
+
ON CONFLICT (id) DO UPDATE
|
|
82
|
+
SET backup_prefix = EXCLUDED.backup_prefix,
|
|
83
|
+
data_restored = EXCLUDED.data_restored;
|
|
84
|
+
SQL
|
|
85
|
+
elif [ "$status" != '200' ]; then
|
|
86
|
+
echo "Database backup pointer remained unavailable after ${RESTORE_POINTER_ATTEMPTS} attempts (HTTP $status)." >&2
|
|
87
|
+
return 1
|
|
88
|
+
else
|
|
89
|
+
prefix="$(cat /tmp/ankhorage-latest)"
|
|
90
|
+
suffix="\${prefix#database/}"
|
|
91
|
+
case "$prefix:$suffix" in
|
|
92
|
+
database/*:*/*|database/*:*..*|database/:*)
|
|
93
|
+
echo 'Database backup pointer is invalid.' >&2
|
|
94
|
+
return 1
|
|
95
|
+
;;
|
|
96
|
+
database/*:*) ;;
|
|
97
|
+
*)
|
|
98
|
+
echo 'Database backup pointer is invalid.' >&2
|
|
99
|
+
return 1
|
|
100
|
+
;;
|
|
101
|
+
esac
|
|
102
|
+
|
|
103
|
+
echo "Restoring database roles and schema from backup set $prefix."
|
|
104
|
+
download_file "$prefix/roles.sql" /tmp/ankhorage-roles.sql
|
|
105
|
+
download_file "$prefix/schema.sql" /tmp/ankhorage-schema.sql
|
|
106
|
+
|
|
107
|
+
psql --set ON_ERROR_STOP=1 --dbname "$POSTGRES_DB" --file /tmp/ankhorage-roles.sql
|
|
108
|
+
psql --set ON_ERROR_STOP=1 --dbname "$POSTGRES_DB" --file /tmp/ankhorage-schema.sql
|
|
109
|
+
psql --set ON_ERROR_STOP=1 --set=backup_prefix="$prefix" --dbname "$POSTGRES_DB" <<'SQL'
|
|
110
|
+
INSERT INTO ${RECOVERY_STATE_RELATION} (id, backup_prefix, data_restored)
|
|
111
|
+
VALUES ('latest', :'backup_prefix', FALSE)
|
|
112
|
+
ON CONFLICT (id) DO UPDATE
|
|
113
|
+
SET backup_prefix = EXCLUDED.backup_prefix,
|
|
114
|
+
data_restored = EXCLUDED.data_restored;
|
|
115
|
+
SQL
|
|
116
|
+
echo 'Database roles and schema restore completed; data restore is deferred until managed schema migrations finish.'
|
|
117
|
+
fi
|
|
118
|
+
rm -f "$marker"
|
|
119
|
+
cleanup
|
|
120
|
+
trap - EXIT INT TERM
|
|
121
|
+
`;
|
|
122
|
+
/*** Project first-boot restore state for a database protected by scheduled S3 backups. */
|
|
123
|
+
export function createSupabaseDatabaseRestore(context) {
|
|
124
|
+
const backup = context.desired.database?.provider === 'supabase' ? context.desired.database.backup : undefined;
|
|
125
|
+
if (backup === undefined)
|
|
126
|
+
return { environment: {}, files: {} };
|
|
127
|
+
const s3 = createSupabaseS3Values(backup.target);
|
|
128
|
+
return {
|
|
129
|
+
environment: {
|
|
130
|
+
S3_REGION: s3.region,
|
|
131
|
+
S3_URL_PREFIX: s3.urlPrefix,
|
|
132
|
+
AWS_ACCESS_KEY_ID: s3.accessKeyId,
|
|
133
|
+
AWS_SECRET_ACCESS_KEY: s3.secretAccessKey,
|
|
134
|
+
},
|
|
135
|
+
files: {
|
|
136
|
+
'/docker-entrypoint-initdb.d/zzzz-ankhorage-restore.sh': {
|
|
137
|
+
kind: 'literal',
|
|
138
|
+
value: RESTORE_SCRIPT,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
entrypoint: {
|
|
142
|
+
command: ['/bin/sh', '-c'],
|
|
143
|
+
args: [RESTORE_ENTRYPOINT_SCRIPT, 'ankhorage-restore-entrypoint'],
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=createSupabaseDatabaseRestore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseDatabaseRestore.js","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseDatabaseRestore.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,wBAAwB,GAAG,EAAE,CAAC;AACpC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AACxC,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;AAC1D,MAAM,uBAAuB,GAAG,IAAI,wBAAwB,MAAM,6BAA6B,GAAG,CAAC;AACnG,MAAM,yBAAyB,GAAG;;;gBAGlB,oBAAoB;;;;;;CAMnC,CAAC;AACF,MAAM,cAAc,GAAG;;;;gBAIP,oBAAoB;;;;;;;;;;;;;;;;;;;;+BAoBL,wBAAwB;6BAC1B,uBAAuB;;;;;;;;;;;;;;0BAc1B,wBAAwB;;;;;;;;;;;;;eAanC,6BAA6B;;;;;;;;;;cAU9B,uBAAuB;;;;;;;6DAOwB,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;cAwBvE,uBAAuB;;;;;;;;;;;CAWpC,CAAC;AAEF,0FAA0F;AAC1F,MAAM,UAAU,6BAA6B,CAC3C,OAA8B;IAE9B,MAAM,MAAM,GACV,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAClG,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;IAChE,MAAM,EAAE,GAAG,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO;QACL,WAAW,EAAE;YACX,SAAS,EAAE,EAAE,CAAC,MAAM;YACpB,aAAa,EAAE,EAAE,CAAC,SAAS;YAC3B,iBAAiB,EAAE,EAAE,CAAC,WAAW;YACjC,qBAAqB,EAAE,EAAE,CAAC,eAAe;SAC1C;QACD,KAAK,EAAE;YACL,uDAAuD,EAAE;gBACvD,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,cAAc;aACtB;SACF;QACD,UAAU,EAAE;YACV,OAAO,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;YAC1B,IAAI,EAAE,CAAC,yBAAyB,EAAE,8BAA8B,CAAC;SAClE;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n InfraExecutionContext,\n InfraWorkloadSpec,\n InfraWorkloadValue,\n} from '@ankhorage/contracts/infra';\n\nimport { SUPABASE_RECOVERY_SCHEMA, SUPABASE_RECOVERY_STATE_TABLE } from '../constants/recovery';\nimport { createSupabaseS3Values } from './createSupabaseS3Values';\n\nconst RESTORE_POINTER_ATTEMPTS = 60;\nconst RESTORE_POINTER_DELAY_SECONDS = 2;\nconst RESTORE_PENDING_FILE = '.ankhorage-restore-pending';\nconst RECOVERY_STATE_RELATION = `\"${SUPABASE_RECOVERY_SCHEMA}\".\"${SUPABASE_RECOVERY_STATE_TABLE}\"`;\nconst RESTORE_ENTRYPOINT_SCRIPT = `\nset -eu\ndata=\"\\${PGDATA:-/var/lib/postgresql/data}\"\nmarker=\"$data/${RESTORE_PENDING_FILE}\"\nif [ -f \"$marker\" ]; then\n echo 'Retrying an interrupted database restore from a fresh Postgres data directory.'\n find \"$data\" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +\nfi\nexec /usr/local/bin/docker-entrypoint.sh \"$@\"\n`;\nconst RESTORE_SCRIPT = `\nset -eu\numask 077\ndata=\"\\${PGDATA:-/var/lib/postgresql/data}\"\nmarker=\"$data/${RESTORE_PENDING_FILE}\"\ncleanup() {\n rm -f /tmp/ankhorage-s3-curl.conf /tmp/ankhorage-latest /tmp/ankhorage-roles.sql \\\n /tmp/ankhorage-schema.sql\n}\ndownload_file() {\n key=\"$1\"\n file=\"$2\"\n status=\"$(curl --silent --show-error --connect-timeout 2 --max-time 30 \\\n --retry 10 --retry-all-errors --retry-delay 2 \\\n --config /tmp/ankhorage-s3-curl.conf \\\n --aws-sigv4 \"aws:amz:\\${S3_REGION}:s3\" --output \"$file\" --write-out '%{http_code}' \\\n \"\\${S3_URL_PREFIX}/$key\" || true)\"\n if [ \"$status\" != '200' ]; then\n echo \"Database backup file $key failed to download with HTTP $status.\" >&2\n return 1\n fi\n}\ncreate_recovery_state() {\n psql --set ON_ERROR_STOP=1 --dbname \"$POSTGRES_DB\" <<'SQL'\nCREATE SCHEMA IF NOT EXISTS \"${SUPABASE_RECOVERY_SCHEMA}\";\nCREATE TABLE IF NOT EXISTS ${RECOVERY_STATE_RELATION} (\n id text PRIMARY KEY,\n backup_prefix text,\n data_restored boolean NOT NULL\n);\nSQL\n}\ntrap cleanup EXIT INT TERM\ntouch \"$marker\"\nprintf 'user = \"%s:%s\"\\n' \"$AWS_ACCESS_KEY_ID\" \"$AWS_SECRET_ACCESS_KEY\" > /tmp/ankhorage-s3-curl.conf\n\necho 'Checking for a database backup to restore.'\nattempt=1\nstatus='000'\nwhile [ \"$attempt\" -le \"${RESTORE_POINTER_ATTEMPTS}\" ]; do\n status=\"$(curl --silent --show-error --connect-timeout 2 --max-time 5 \\\n --config /tmp/ankhorage-s3-curl.conf \\\n --aws-sigv4 \"aws:amz:\\${S3_REGION}:s3\" --output /tmp/ankhorage-latest --write-out '%{http_code}' \\\n \"\\${S3_URL_PREFIX}/database/latest\" || true)\"\n case \"$status\" in\n 200|404) break ;;\n 401|403)\n echo \"Database backup pointer request failed with HTTP $status.\" >&2\n return 1\n ;;\n *)\n echo \"Database backup pointer is not reachable yet (HTTP $status); retrying.\"\n sleep \"${RESTORE_POINTER_DELAY_SECONDS}\"\n attempt=\"$((attempt + 1))\"\n ;;\n esac\ndone\n\ncreate_recovery_state\nif [ \"$status\" = '404' ]; then\n echo 'No database backup exists yet; continuing with a fresh database.'\n psql --set ON_ERROR_STOP=1 --dbname \"$POSTGRES_DB\" <<'SQL'\nINSERT INTO ${RECOVERY_STATE_RELATION} (id, backup_prefix, data_restored)\nVALUES ('latest', NULL, TRUE)\nON CONFLICT (id) DO UPDATE\nSET backup_prefix = EXCLUDED.backup_prefix,\n data_restored = EXCLUDED.data_restored;\nSQL\nelif [ \"$status\" != '200' ]; then\n echo \"Database backup pointer remained unavailable after ${RESTORE_POINTER_ATTEMPTS} attempts (HTTP $status).\" >&2\n return 1\nelse\n prefix=\"$(cat /tmp/ankhorage-latest)\"\n suffix=\"\\${prefix#database/}\"\n case \"$prefix:$suffix\" in\n database/*:*/*|database/*:*..*|database/:*)\n echo 'Database backup pointer is invalid.' >&2\n return 1\n ;;\n database/*:*) ;;\n *)\n echo 'Database backup pointer is invalid.' >&2\n return 1\n ;;\n esac\n\n echo \"Restoring database roles and schema from backup set $prefix.\"\n download_file \"$prefix/roles.sql\" /tmp/ankhorage-roles.sql\n download_file \"$prefix/schema.sql\" /tmp/ankhorage-schema.sql\n\n psql --set ON_ERROR_STOP=1 --dbname \"$POSTGRES_DB\" --file /tmp/ankhorage-roles.sql\n psql --set ON_ERROR_STOP=1 --dbname \"$POSTGRES_DB\" --file /tmp/ankhorage-schema.sql\n psql --set ON_ERROR_STOP=1 --set=backup_prefix=\"$prefix\" --dbname \"$POSTGRES_DB\" <<'SQL'\nINSERT INTO ${RECOVERY_STATE_RELATION} (id, backup_prefix, data_restored)\nVALUES ('latest', :'backup_prefix', FALSE)\nON CONFLICT (id) DO UPDATE\nSET backup_prefix = EXCLUDED.backup_prefix,\n data_restored = EXCLUDED.data_restored;\nSQL\n echo 'Database roles and schema restore completed; data restore is deferred until managed schema migrations finish.'\nfi\nrm -f \"$marker\"\ncleanup\ntrap - EXIT INT TERM\n`;\n\n/*** Project first-boot restore state for a database protected by scheduled S3 backups. */\nexport function createSupabaseDatabaseRestore(\n context: InfraExecutionContext,\n): SupabaseDatabaseRestoreProjection {\n const backup =\n context.desired.database?.provider === 'supabase' ? context.desired.database.backup : undefined;\n if (backup === undefined) return { environment: {}, files: {} };\n const s3 = createSupabaseS3Values(backup.target);\n return {\n environment: {\n S3_REGION: s3.region,\n S3_URL_PREFIX: s3.urlPrefix,\n AWS_ACCESS_KEY_ID: s3.accessKeyId,\n AWS_SECRET_ACCESS_KEY: s3.secretAccessKey,\n },\n files: {\n '/docker-entrypoint-initdb.d/zzzz-ankhorage-restore.sh': {\n kind: 'literal',\n value: RESTORE_SCRIPT,\n },\n },\n entrypoint: {\n command: ['/bin/sh', '-c'],\n args: [RESTORE_ENTRYPOINT_SCRIPT, 'ankhorage-restore-entrypoint'],\n },\n };\n}\n\ninterface SupabaseDatabaseRestoreProjection {\n readonly environment: Readonly<Record<string, InfraWorkloadValue>>;\n readonly files: NonNullable<InfraWorkloadSpec['files']>;\n readonly entrypoint?: {\n readonly command: readonly string[];\n readonly args: readonly string[];\n };\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InfraExecutionContext, InfraWorkloadSpec } from '@ankhorage/contracts/infra';
|
|
2
|
+
/*** Create the operational services supporting Storage and the self-hosted Studio. */
|
|
3
|
+
export declare function createSupabaseOperationalWorkloads(context: InfraExecutionContext, baseUrl: string): readonly [InfraWorkloadSpec, InfraWorkloadSpec, InfraWorkloadSpec];
|
|
4
|
+
//# sourceMappingURL=createSupabaseOperationalWorkloads.d.ts.map
|
package/dist/features/platform-infrastructure/domain/createSupabaseOperationalWorkloads.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseOperationalWorkloads.d.ts","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseOperationalWorkloads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAIpC,sFAAsF;AACtF,wBAAgB,kCAAkC,CAChD,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,MAAM,GACd,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAEpE"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';
|
|
2
|
+
/*** Create the operational services supporting Storage and the self-hosted Studio. */
|
|
3
|
+
export function createSupabaseOperationalWorkloads(context, baseUrl) {
|
|
4
|
+
return [createImgproxyWorkload(), createMetaWorkload(), createStudioWorkload(context, baseUrl)];
|
|
5
|
+
}
|
|
6
|
+
/*** Create the self-hosted image transformation workload required by Storage. */
|
|
7
|
+
function createImgproxyWorkload() {
|
|
8
|
+
return {
|
|
9
|
+
id: 'supabase-imgproxy',
|
|
10
|
+
artifact: { kind: 'image', image: SUPABASE_IMAGES.imgproxy },
|
|
11
|
+
ports: { http: { port: 5001 } },
|
|
12
|
+
environment: {
|
|
13
|
+
IMGPROXY_BIND: literal(':5001'),
|
|
14
|
+
IMGPROXY_LOCAL_FILESYSTEM_ROOT: literal('/'),
|
|
15
|
+
IMGPROXY_USE_ETAG: literal('true'),
|
|
16
|
+
IMGPROXY_AUTO_WEBP: literal('true'),
|
|
17
|
+
IMGPROXY_MAX_SRC_RESOLUTION: literal('16.8'),
|
|
18
|
+
},
|
|
19
|
+
health: { kind: 'command', command: ['imgproxy', 'health'] },
|
|
20
|
+
exposure: 'internal',
|
|
21
|
+
replicas: 1,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/*** Create the Postgres Meta workload used by the self-hosted Studio. */
|
|
25
|
+
function createMetaWorkload() {
|
|
26
|
+
return {
|
|
27
|
+
id: 'supabase-meta',
|
|
28
|
+
artifact: { kind: 'image', image: SUPABASE_IMAGES.meta },
|
|
29
|
+
ports: { http: { port: 8080 } },
|
|
30
|
+
environment: {
|
|
31
|
+
PG_META_PORT: literal('8080'),
|
|
32
|
+
PG_META_DB_HOST: literal('supabase-db'),
|
|
33
|
+
PG_META_DB_PORT: literal('5432'),
|
|
34
|
+
PG_META_DB_NAME: literal('postgres'),
|
|
35
|
+
PG_META_DB_USER: literal('postgres'),
|
|
36
|
+
PG_META_DB_PASSWORD: credential('postgresPassword'),
|
|
37
|
+
CRYPTO_KEY: credential('pgMetaCryptoKey'),
|
|
38
|
+
},
|
|
39
|
+
health: {
|
|
40
|
+
kind: 'command',
|
|
41
|
+
command: [
|
|
42
|
+
'node',
|
|
43
|
+
'-e',
|
|
44
|
+
"fetch('http://localhost:8080/health').then((r) => {if (r.status !== 200) throw new Error(r.status)})",
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
exposure: 'internal',
|
|
48
|
+
replicas: 1,
|
|
49
|
+
dependsOn: { 'supabase-db': true },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/*** Create the self-hosted Studio without exposing privileged credentials as outputs. */
|
|
53
|
+
function createStudioWorkload(context, baseUrl) {
|
|
54
|
+
return {
|
|
55
|
+
id: 'supabase-studio',
|
|
56
|
+
artifact: { kind: 'image', image: SUPABASE_IMAGES.studio },
|
|
57
|
+
ports: { http: { port: 3000 } },
|
|
58
|
+
environment: {
|
|
59
|
+
HOSTNAME: literal('0.0.0.0'),
|
|
60
|
+
STUDIO_PG_META_URL: literal('http://supabase-meta:8080'),
|
|
61
|
+
POSTGRES_PORT: literal('5432'),
|
|
62
|
+
POSTGRES_HOST: literal('supabase-db'),
|
|
63
|
+
POSTGRES_DB: literal('postgres'),
|
|
64
|
+
POSTGRES_PASSWORD: credential('postgresPassword'),
|
|
65
|
+
POSTGRES_USER_READ_WRITE: literal('postgres'),
|
|
66
|
+
PG_META_CRYPTO_KEY: credential('pgMetaCryptoKey'),
|
|
67
|
+
PGRST_DB_SCHEMAS: literal('public,storage,graphql_public'),
|
|
68
|
+
PGRST_DB_MAX_ROWS: literal('1000'),
|
|
69
|
+
PGRST_DB_EXTRA_SEARCH_PATH: literal('public'),
|
|
70
|
+
DEFAULT_ORGANIZATION_NAME: literal('Ankhorage'),
|
|
71
|
+
DEFAULT_PROJECT_NAME: literal(context.projectId),
|
|
72
|
+
SUPABASE_URL: literal('http://supabase-gateway:8000'),
|
|
73
|
+
SUPABASE_PUBLIC_URL: literal(baseUrl),
|
|
74
|
+
SUPABASE_ANON_KEY: credential('anonKey'),
|
|
75
|
+
SUPABASE_SERVICE_KEY: credential('serviceRoleKey'),
|
|
76
|
+
AUTH_JWT_SECRET: credential('jwtSecret'),
|
|
77
|
+
ENABLED_FEATURES_LOGS_ALL: literal('false'),
|
|
78
|
+
},
|
|
79
|
+
health: {
|
|
80
|
+
kind: 'command',
|
|
81
|
+
command: [
|
|
82
|
+
'node',
|
|
83
|
+
'-e',
|
|
84
|
+
"fetch('http://localhost:3000/api/platform/profile').then((r) => {if (r.status !== 200) throw new Error(r.status)})",
|
|
85
|
+
],
|
|
86
|
+
intervalSeconds: 5,
|
|
87
|
+
timeoutSeconds: 10,
|
|
88
|
+
failureThreshold: 3,
|
|
89
|
+
},
|
|
90
|
+
exposure: 'internal',
|
|
91
|
+
replicas: 1,
|
|
92
|
+
dependsOn: { 'supabase-db': true, 'supabase-meta': true },
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/*** Create one literal workload value. */
|
|
96
|
+
function literal(value) {
|
|
97
|
+
return { kind: 'literal', value };
|
|
98
|
+
}
|
|
99
|
+
/*** Create one execution-only control-plane credential field reference. */
|
|
100
|
+
function credential(key) {
|
|
101
|
+
return { kind: 'credential', reference: SUPABASE_BOOTSTRAP_CREDENTIAL, key };
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=createSupabaseOperationalWorkloads.js.map
|
package/dist/features/platform-infrastructure/domain/createSupabaseOperationalWorkloads.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseOperationalWorkloads.js","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseOperationalWorkloads.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEvF,sFAAsF;AACtF,MAAM,UAAU,kCAAkC,CAChD,OAA8B,EAC9B,OAAe;IAEf,OAAO,CAAC,sBAAsB,EAAE,EAAE,kBAAkB,EAAE,EAAE,oBAAoB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAClG,CAAC;AAED,iFAAiF;AACjF,SAAS,sBAAsB;IAC7B,OAAO;QACL,EAAE,EAAE,mBAAmB;QACvB,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,QAAQ,EAAE;QAC5D,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAC/B,WAAW,EAAE;YACX,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC;YAC/B,8BAA8B,EAAE,OAAO,CAAC,GAAG,CAAC;YAC5C,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAC;YAClC,kBA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AE,eAAe,EAAE,IAAI,EAAE;KAC1D,CAAC;AACJ,CAAC;AAED,0CAA0C;AAC1C,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACpC,CAAC;AAED,2EAA2E;AAC3E,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B,EAAE,GAAG,EAAE,CAAC;AAC/E,CAAC","sourcesContent":["import type {\n InfraExecutionContext,\n InfraWorkloadScalarValue,\n InfraWorkloadSpec,\n} from '@ankhorage/contracts/infra';\n\nimport { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';\n\n/*** Create the operational services supporting Storage and the self-hosted Studio. */\nexport function createSupabaseOperationalWorkloads(\n context: InfraExecutionContext,\n baseUrl: string,\n): readonly [InfraWorkloadSpec, InfraWorkloadSpec, InfraWorkloadSpec] {\n return [createImgproxyWorkload(), createMetaWorkload(), createStudioWorkload(context, baseUrl)];\n}\n\n/*** Create the self-hosted image transformation workload required by Storage. */\nfunction createImgproxyWorkload(): InfraWorkloadSpec {\n return {\n id: 'supabase-imgproxy',\n artifact: { kind: 'image', image: SUPABASE_IMAGES.imgproxy },\n ports: { http: { port: 5001 } },\n environment: {\n IMGPROXY_BIND: literal(':5001'),\n IMGPROXY_LOCAL_FILESYSTEM_ROOT: literal('/'),\n IMGPROXY_USE_ETAG: literal('true'),\n IMGPROXY_AUTO_WEBP: literal('true'),\n IMGPROXY_MAX_SRC_RESOLUTION: literal('16.8'),\n },\n health: { kind: 'command', command: ['imgproxy', 'health'] },\n exposure: 'internal',\n replicas: 1,\n };\n}\n\n/*** Create the Postgres Meta workload used by the self-hosted Studio. */\nfunction createMetaWorkload(): InfraWorkloadSpec {\n return {\n id: 'supabase-meta',\n artifact: { kind: 'image', image: SUPABASE_IMAGES.meta },\n ports: { http: { port: 8080 } },\n environment: {\n PG_META_PORT: literal('8080'),\n PG_META_DB_HOST: literal('supabase-db'),\n PG_META_DB_PORT: literal('5432'),\n PG_META_DB_NAME: literal('postgres'),\n PG_META_DB_USER: literal('postgres'),\n PG_META_DB_PASSWORD: credential('postgresPassword'),\n CRYPTO_KEY: credential('pgMetaCryptoKey'),\n },\n health: {\n kind: 'command',\n command: [\n 'node',\n '-e',\n \"fetch('http://localhost:8080/health').then((r) => {if (r.status !== 200) throw new Error(r.status)})\",\n ],\n },\n exposure: 'internal',\n replicas: 1,\n dependsOn: { 'supabase-db': true },\n };\n}\n\n/*** Create the self-hosted Studio without exposing privileged credentials as outputs. */\nfunction createStudioWorkload(context: InfraExecutionContext, baseUrl: string): InfraWorkloadSpec {\n return {\n id: 'supabase-studio',\n artifact: { kind: 'image', image: SUPABASE_IMAGES.studio },\n ports: { http: { port: 3000 } },\n environment: {\n HOSTNAME: literal('0.0.0.0'),\n STUDIO_PG_META_URL: literal('http://supabase-meta:8080'),\n POSTGRES_PORT: literal('5432'),\n POSTGRES_HOST: literal('supabase-db'),\n POSTGRES_DB: literal('postgres'),\n POSTGRES_PASSWORD: credential('postgresPassword'),\n POSTGRES_USER_READ_WRITE: literal('postgres'),\n PG_META_CRYPTO_KEY: credential('pgMetaCryptoKey'),\n PGRST_DB_SCHEMAS: literal('public,storage,graphql_public'),\n PGRST_DB_MAX_ROWS: literal('1000'),\n PGRST_DB_EXTRA_SEARCH_PATH: literal('public'),\n DEFAULT_ORGANIZATION_NAME: literal('Ankhorage'),\n DEFAULT_PROJECT_NAME: literal(context.projectId),\n SUPABASE_URL: literal('http://supabase-gateway:8000'),\n SUPABASE_PUBLIC_URL: literal(baseUrl),\n SUPABASE_ANON_KEY: credential('anonKey'),\n SUPABASE_SERVICE_KEY: credential('serviceRoleKey'),\n AUTH_JWT_SECRET: credential('jwtSecret'),\n ENABLED_FEATURES_LOGS_ALL: literal('false'),\n },\n health: {\n kind: 'command',\n command: [\n 'node',\n '-e',\n \"fetch('http://localhost:3000/api/platform/profile').then((r) => {if (r.status !== 200) throw new Error(r.status)})\",\n ],\n intervalSeconds: 5,\n timeoutSeconds: 10,\n failureThreshold: 3,\n },\n exposure: 'internal',\n replicas: 1,\n dependsOn: { 'supabase-db': true, 'supabase-meta': true },\n };\n}\n\n/*** Create one literal workload value. */\nfunction literal(value: string): InfraWorkloadScalarValue {\n return { kind: 'literal', value };\n}\n\n/*** Create one execution-only control-plane credential field reference. */\nfunction credential(key: string): InfraWorkloadScalarValue {\n return { kind: 'credential', reference: SUPABASE_BOOTSTRAP_CREDENTIAL, key };\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InfraS3PersistenceTarget, InfraWorkloadScalarValue } from '@ankhorage/contracts/infra';
|
|
2
|
+
/*** Project one portable S3 target into execution-only workload values and a concrete URL prefix. */
|
|
3
|
+
export declare function createSupabaseS3Values(target: InfraS3PersistenceTarget): SupabaseS3WorkloadValues;
|
|
4
|
+
interface SupabaseS3WorkloadValues {
|
|
5
|
+
readonly endpoint: InfraWorkloadScalarValue;
|
|
6
|
+
readonly region: InfraWorkloadScalarValue;
|
|
7
|
+
readonly bucket: InfraWorkloadScalarValue;
|
|
8
|
+
readonly forcePathStyle: InfraWorkloadScalarValue;
|
|
9
|
+
readonly accessKeyId: InfraWorkloadScalarValue;
|
|
10
|
+
readonly secretAccessKey: InfraWorkloadScalarValue;
|
|
11
|
+
readonly urlPrefix: InfraWorkloadScalarValue;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=createSupabaseS3Values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseS3Values.d.ts","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseS3Values.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,4BAA4B,CAAC;AAEpC,qGAAqG;AACrG,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,wBAAwB,GAAG,wBAAwB,CAUjG;AAED,UAAU,wBAAwB;IAChC,QAAQ,CAAC,QAAQ,EAAE,wBAAwB,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,QAAQ,CAAC,cAAc,EAAE,wBAAwB,CAAC;IAClD,QAAQ,CAAC,WAAW,EAAE,wBAAwB,CAAC;IAC/C,QAAQ,CAAC,eAAe,EAAE,wBAAwB,CAAC;IACnD,QAAQ,CAAC,SAAS,EAAE,wBAAwB,CAAC;CAC9C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*** Project one portable S3 target into execution-only workload values and a concrete URL prefix. */
|
|
2
|
+
export function createSupabaseS3Values(target) {
|
|
3
|
+
return {
|
|
4
|
+
endpoint: literal(target.endpoint),
|
|
5
|
+
region: literal(target.region),
|
|
6
|
+
bucket: literal(target.bucket),
|
|
7
|
+
forcePathStyle: literal(String(target.forcePathStyle ?? true)),
|
|
8
|
+
accessKeyId: credential(target, 'accessKeyId'),
|
|
9
|
+
secretAccessKey: credential(target, 'secretAccessKey'),
|
|
10
|
+
urlPrefix: literal(resolveS3UrlPrefix(target)),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/*** Resolve path-style by default while preserving explicit virtual-host addressing intent. */
|
|
14
|
+
function resolveS3UrlPrefix(target) {
|
|
15
|
+
const endpoint = new URL(target.endpoint);
|
|
16
|
+
if (target.forcePathStyle !== false) {
|
|
17
|
+
return `${endpoint.origin}/${encodeURIComponent(target.bucket)}`;
|
|
18
|
+
}
|
|
19
|
+
endpoint.hostname = `${target.bucket}.${endpoint.hostname}`;
|
|
20
|
+
return endpoint.origin;
|
|
21
|
+
}
|
|
22
|
+
/*** Create one plain workload value. */
|
|
23
|
+
function literal(value) {
|
|
24
|
+
return { kind: 'literal', value };
|
|
25
|
+
}
|
|
26
|
+
/*** Create one execution-only S3 credential field reference. */
|
|
27
|
+
function credential(target, key) {
|
|
28
|
+
return { kind: 'credential', reference: target.credentials, key };
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=createSupabaseS3Values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseS3Values.js","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseS3Values.ts"],"names":[],"mappings":"AAKA,qGAAqG;AACrG,MAAM,UAAU,sBAAsB,CAAC,MAAgC;IACrE,OAAO;QACL,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;QAClC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;QAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;QAC9B,cAAc,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC,CAAC;QAC9D,WAAW,EAAE,UAAU,CAAC,MAAM,EAAE,aAAa,CAAC;QAC9C,eAAe,EAAE,UAAU,CAAC,MAAM,EAAE,iBAAiB,CAAC;QACtD,SAAS,EAAE,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;KAC/C,CAAC;AACJ,CAAC;AAYD,+FAA+F;AAC/F,SAAS,kBAAkB,CAAC,MAAgC;IAC1D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,MAAM,CAAC,cAAc,KAAK,KAAK,EAAE,CAAC;QACpC,OAAO,GAAG,QAAQ,CAAC,MAAM,IAAI,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IACnE,CAAC;IACD,QAAQ,CAAC,QAAQ,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAC5D,OAAO,QAAQ,CAAC,MAAM,CAAC;AACzB,CAAC;AAED,wCAAwC;AACxC,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACpC,CAAC;AAED,gEAAgE;AAChE,SAAS,UAAU,CACjB,MAAgC,EAChC,GAAsC;IAEtC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC;AACpE,CAAC","sourcesContent":["import type {\n InfraS3PersistenceTarget,\n InfraWorkloadScalarValue,\n} from '@ankhorage/contracts/infra';\n\n/*** Project one portable S3 target into execution-only workload values and a concrete URL prefix. */\nexport function createSupabaseS3Values(target: InfraS3PersistenceTarget): SupabaseS3WorkloadValues {\n return {\n endpoint: literal(target.endpoint),\n region: literal(target.region),\n bucket: literal(target.bucket),\n forcePathStyle: literal(String(target.forcePathStyle ?? true)),\n accessKeyId: credential(target, 'accessKeyId'),\n secretAccessKey: credential(target, 'secretAccessKey'),\n urlPrefix: literal(resolveS3UrlPrefix(target)),\n };\n}\n\ninterface SupabaseS3WorkloadValues {\n readonly endpoint: InfraWorkloadScalarValue;\n readonly region: InfraWorkloadScalarValue;\n readonly bucket: InfraWorkloadScalarValue;\n readonly forcePathStyle: InfraWorkloadScalarValue;\n readonly accessKeyId: InfraWorkloadScalarValue;\n readonly secretAccessKey: InfraWorkloadScalarValue;\n readonly urlPrefix: InfraWorkloadScalarValue;\n}\n\n/*** Resolve path-style by default while preserving explicit virtual-host addressing intent. */\nfunction resolveS3UrlPrefix(target: InfraS3PersistenceTarget): string {\n const endpoint = new URL(target.endpoint);\n if (target.forcePathStyle !== false) {\n return `${endpoint.origin}/${encodeURIComponent(target.bucket)}`;\n }\n endpoint.hostname = `${target.bucket}.${endpoint.hostname}`;\n return endpoint.origin;\n}\n\n/*** Create one plain workload value. */\nfunction literal(value: string): InfraWorkloadScalarValue {\n return { kind: 'literal', value };\n}\n\n/*** Create one execution-only S3 credential field reference. */\nfunction credential(\n target: InfraS3PersistenceTarget,\n key: 'accessKeyId' | 'secretAccessKey',\n): InfraWorkloadScalarValue {\n return { kind: 'credential', reference: target.credentials, key };\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InfraExecutionContext, InfraWorkloadSpec } from '@ankhorage/contracts/infra';
|
|
2
|
+
/*** Create Supabase Storage using either retained file storage or the selected S3 backend. */
|
|
3
|
+
export declare function createSupabaseStorageWorkload(context: InfraExecutionContext, baseUrl: string): InfraWorkloadSpec;
|
|
4
|
+
//# sourceMappingURL=createSupabaseStorageWorkload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseStorageWorkload.d.ts","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseStorageWorkload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,iBAAiB,EAElB,MAAM,4BAA4B,CAAC;AAKpC,8FAA8F;AAC9F,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,MAAM,GACd,iBAAiB,CAenB"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';
|
|
2
|
+
import { createSupabaseS3Values } from './createSupabaseS3Values';
|
|
3
|
+
/*** Create Supabase Storage using either retained file storage or the selected S3 backend. */
|
|
4
|
+
export function createSupabaseStorageWorkload(context, baseUrl) {
|
|
5
|
+
const prod = context.desired.database?.provider === 'supabase' && context.desired.database.tier === 'prod';
|
|
6
|
+
const backend = resolveStorageBackend(context);
|
|
7
|
+
return {
|
|
8
|
+
id: 'supabase-storage',
|
|
9
|
+
artifact: { kind: 'image', image: SUPABASE_IMAGES.storage },
|
|
10
|
+
ports: { http: { port: 5000 } },
|
|
11
|
+
environment: createStorageEnvironment(context, baseUrl, backend),
|
|
12
|
+
health: { kind: 'http', port: 5000, path: '/status' },
|
|
13
|
+
...(backend === undefined ? { persistence: createFileStoragePersistence(prod) } : {}),
|
|
14
|
+
exposure: 'internal',
|
|
15
|
+
replicas: 1,
|
|
16
|
+
dependsOn: { 'supabase-db': true, 'supabase-rest': true, 'supabase-imgproxy': true },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/*** Resolve an optional external Storage backend only when Supabase owns object storage. */
|
|
20
|
+
function resolveStorageBackend(context) {
|
|
21
|
+
return context.desired.objectStorage?.provider === 'supabase'
|
|
22
|
+
? context.desired.objectStorage.backend
|
|
23
|
+
: undefined;
|
|
24
|
+
}
|
|
25
|
+
/*** Project the stable Storage environment plus the selected persistence backend. */
|
|
26
|
+
function createStorageEnvironment(context, baseUrl, backend) {
|
|
27
|
+
return {
|
|
28
|
+
ANON_KEY: {
|
|
29
|
+
kind: 'credential',
|
|
30
|
+
reference: SUPABASE_BOOTSTRAP_CREDENTIAL,
|
|
31
|
+
key: 'anonKey',
|
|
32
|
+
},
|
|
33
|
+
SERVICE_KEY: {
|
|
34
|
+
kind: 'credential',
|
|
35
|
+
reference: SUPABASE_BOOTSTRAP_CREDENTIAL,
|
|
36
|
+
key: 'serviceRoleKey',
|
|
37
|
+
},
|
|
38
|
+
POSTGREST_URL: { kind: 'literal', value: 'http://supabase-rest:3000' },
|
|
39
|
+
AUTH_JWT_SECRET: {
|
|
40
|
+
kind: 'credential',
|
|
41
|
+
reference: SUPABASE_BOOTSTRAP_CREDENTIAL,
|
|
42
|
+
key: 'jwtSecret',
|
|
43
|
+
},
|
|
44
|
+
DATABASE_URL: {
|
|
45
|
+
kind: 'template',
|
|
46
|
+
segments: [
|
|
47
|
+
{ kind: 'literal', value: 'postgres://supabase_storage_admin:' },
|
|
48
|
+
{
|
|
49
|
+
kind: 'credential',
|
|
50
|
+
reference: SUPABASE_BOOTSTRAP_CREDENTIAL,
|
|
51
|
+
key: 'postgresPassword',
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
kind: 'literal',
|
|
55
|
+
value: '@supabase-db:5432/postgres?search_path=storage&sslmode=disable',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
STORAGE_PUBLIC_URL: { kind: 'literal', value: baseUrl },
|
|
60
|
+
REQUEST_ALLOW_X_FORWARDED_PATH: { kind: 'literal', value: 'true' },
|
|
61
|
+
FILE_SIZE_LIMIT: { kind: 'literal', value: '52428800' },
|
|
62
|
+
TENANT_ID: { kind: 'literal', value: context.projectId },
|
|
63
|
+
REGION: { kind: 'literal', value: context.environment },
|
|
64
|
+
ENABLE_IMAGE_TRANSFORMATION: { kind: 'literal', value: 'true' },
|
|
65
|
+
IMGPROXY_URL: { kind: 'literal', value: 'http://supabase-imgproxy:5001' },
|
|
66
|
+
...createStorageBackendEnvironment(backend),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/*** Project file-backed or S3-backed Storage environment without leaking resolved credentials. */
|
|
70
|
+
function createStorageBackendEnvironment(target) {
|
|
71
|
+
if (target === undefined) {
|
|
72
|
+
return {
|
|
73
|
+
STORAGE_BACKEND: { kind: 'literal', value: 'file' },
|
|
74
|
+
GLOBAL_S3_BUCKET: { kind: 'literal', value: 'stub' },
|
|
75
|
+
FILE_STORAGE_BACKEND_PATH: { kind: 'literal', value: '/var/lib/storage' },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const s3 = createSupabaseS3Values(target);
|
|
79
|
+
return {
|
|
80
|
+
STORAGE_BACKEND: { kind: 'literal', value: 's3' },
|
|
81
|
+
STORAGE_S3_BUCKET: s3.bucket,
|
|
82
|
+
STORAGE_S3_ENDPOINT: s3.endpoint,
|
|
83
|
+
STORAGE_S3_FORCE_PATH_STYLE: s3.forcePathStyle,
|
|
84
|
+
STORAGE_S3_REGION: s3.region,
|
|
85
|
+
AWS_ACCESS_KEY_ID: s3.accessKeyId,
|
|
86
|
+
AWS_SECRET_ACCESS_KEY: s3.secretAccessKey,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/*** Create retained production or destroyable development file-storage persistence. */
|
|
90
|
+
function createFileStoragePersistence(prod) {
|
|
91
|
+
return {
|
|
92
|
+
data: {
|
|
93
|
+
id: 'data',
|
|
94
|
+
mountPath: '/var/lib/storage',
|
|
95
|
+
sizeGiB: prod ? 20 : 5,
|
|
96
|
+
retention: prod ? 'retain' : 'delete-on-destroy',
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=createSupabaseStorageWorkload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseStorageWorkload.js","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseStorageWorkload.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,8FAA8F;AAC9F,MAAM,UAAU,6BAA6B,CAC3C,OAA8B,EAC9B,OAAe;IAEf,MAAM,IAAI,GACR,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,KAAK,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC;IAChG,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO;QACL,EAAE,EAAE,kBAAkB;QACtB,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,OAAO,EAAE;QAC3D,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAC/B,WAAW,EAAE,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;QAChE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;QACrD,GAAG,CAAC,OA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9C,iBAAiB,EAAE,EAAE,CAAC,MAAM;QAC5B,iBAAiB,EAAE,EAAE,CAAC,WAAW;QACjC,qBAAqB,EAAE,EAAE,CAAC,eAAe;KAC1C,CAAC;AACJ,CAAC;AAED,uFAAuF;AACvF,SAAS,4BAA4B,CACnC,IAAa;IAEb,OAAO;QACL,IAAI,EAAE;YACJ,EAAE,EAAE,MAAM;YACV,SAAS,EAAE,kBAAkB;YAC7B,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACtB,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,mBAAmB;SACjD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n InfraExecutionContext,\n InfraS3PersistenceTarget,\n InfraWorkloadSpec,\n InfraWorkloadValue,\n} from '@ankhorage/contracts/infra';\n\nimport { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';\nimport { createSupabaseS3Values } from './createSupabaseS3Values';\n\n/*** Create Supabase Storage using either retained file storage or the selected S3 backend. */\nexport function createSupabaseStorageWorkload(\n context: InfraExecutionContext,\n baseUrl: string,\n): InfraWorkloadSpec {\n const prod =\n context.desired.database?.provider === 'supabase' && context.desired.database.tier === 'prod';\n const backend = resolveStorageBackend(context);\n return {\n id: 'supabase-storage',\n artifact: { kind: 'image', image: SUPABASE_IMAGES.storage },\n ports: { http: { port: 5000 } },\n environment: createStorageEnvironment(context, baseUrl, backend),\n health: { kind: 'http', port: 5000, path: '/status' },\n ...(backend === undefined ? { persistence: createFileStoragePersistence(prod) } : {}),\n exposure: 'internal',\n replicas: 1,\n dependsOn: { 'supabase-db': true, 'supabase-rest': true, 'supabase-imgproxy': true },\n };\n}\n\n/*** Resolve an optional external Storage backend only when Supabase owns object storage. */\nfunction resolveStorageBackend(\n context: InfraExecutionContext,\n): InfraS3PersistenceTarget | undefined {\n return context.desired.objectStorage?.provider === 'supabase'\n ? context.desired.objectStorage.backend\n : undefined;\n}\n\n/*** Project the stable Storage environment plus the selected persistence backend. */\nfunction createStorageEnvironment(\n context: InfraExecutionContext,\n baseUrl: string,\n backend: InfraS3PersistenceTarget | undefined,\n): Readonly<Record<string, InfraWorkloadValue>> {\n return {\n ANON_KEY: {\n kind: 'credential',\n reference: SUPABASE_BOOTSTRAP_CREDENTIAL,\n key: 'anonKey',\n },\n SERVICE_KEY: {\n kind: 'credential',\n reference: SUPABASE_BOOTSTRAP_CREDENTIAL,\n key: 'serviceRoleKey',\n },\n POSTGREST_URL: { kind: 'literal', value: 'http://supabase-rest:3000' },\n AUTH_JWT_SECRET: {\n kind: 'credential',\n reference: SUPABASE_BOOTSTRAP_CREDENTIAL,\n key: 'jwtSecret',\n },\n DATABASE_URL: {\n kind: 'template',\n segments: [\n { kind: 'literal', value: 'postgres://supabase_storage_admin:' },\n {\n kind: 'credential',\n reference: SUPABASE_BOOTSTRAP_CREDENTIAL,\n key: 'postgresPassword',\n },\n {\n kind: 'literal',\n value: '@supabase-db:5432/postgres?search_path=storage&sslmode=disable',\n },\n ],\n },\n STORAGE_PUBLIC_URL: { kind: 'literal', value: baseUrl },\n REQUEST_ALLOW_X_FORWARDED_PATH: { kind: 'literal', value: 'true' },\n FILE_SIZE_LIMIT: { kind: 'literal', value: '52428800' },\n TENANT_ID: { kind: 'literal', value: context.projectId },\n REGION: { kind: 'literal', value: context.environment },\n ENABLE_IMAGE_TRANSFORMATION: { kind: 'literal', value: 'true' },\n IMGPROXY_URL: { kind: 'literal', value: 'http://supabase-imgproxy:5001' },\n ...createStorageBackendEnvironment(backend),\n };\n}\n\n/*** Project file-backed or S3-backed Storage environment without leaking resolved credentials. */\nfunction createStorageBackendEnvironment(\n target: InfraS3PersistenceTarget | undefined,\n): Readonly<Record<string, InfraWorkloadValue>> {\n if (target === undefined) {\n return {\n STORAGE_BACKEND: { kind: 'literal', value: 'file' },\n GLOBAL_S3_BUCKET: { kind: 'literal', value: 'stub' },\n FILE_STORAGE_BACKEND_PATH: { kind: 'literal', value: '/var/lib/storage' },\n };\n }\n const s3 = createSupabaseS3Values(target);\n return {\n STORAGE_BACKEND: { kind: 'literal', value: 's3' },\n STORAGE_S3_BUCKET: s3.bucket,\n STORAGE_S3_ENDPOINT: s3.endpoint,\n STORAGE_S3_FORCE_PATH_STYLE: s3.forcePathStyle,\n STORAGE_S3_REGION: s3.region,\n AWS_ACCESS_KEY_ID: s3.accessKeyId,\n AWS_SECRET_ACCESS_KEY: s3.secretAccessKey,\n };\n}\n\n/*** Create retained production or destroyable development file-storage persistence. */\nfunction createFileStoragePersistence(\n prod: boolean,\n): NonNullable<InfraWorkloadSpec['persistence']> {\n return {\n data: {\n id: 'data',\n mountPath: '/var/lib/storage',\n sizeGiB: prod ? 20 : 5,\n retention: prod ? 'retain' : 'delete-on-destroy',\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InfraExecutionContext, InfraWorkloadSpec } from '@ankhorage/contracts/infra';
|
|
2
|
+
/*** Project the selected Supabase platform into one ordered runtime-neutral workload graph. */
|
|
3
|
+
export declare function createSupabaseWorkloads(context: InfraExecutionContext): readonly InfraWorkloadSpec[];
|
|
4
|
+
//# sourceMappingURL=createSupabaseWorkloads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseWorkloads.d.ts","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseWorkloads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,iBAAiB,EAElB,MAAM,4BAA4B,CAAC;AAwBpC,+FAA+F;AAC/F,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,qBAAqB,GAC7B,SAAS,iBAAiB,EAAE,CAkB9B"}
|