@ankhorage/infra-supabase 0.0.0-stage → 0.5.16
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,103 @@
|
|
|
1
|
+
export const SUPABASE_BOOTSTRAP_CREDENTIAL = {
|
|
2
|
+
source: 'control-plane',
|
|
3
|
+
name: 'SUPABASE_BOOTSTRAP',
|
|
4
|
+
};
|
|
5
|
+
export const SUPABASE_IMAGES = {
|
|
6
|
+
database: 'supabase/postgres:17.6.1.136',
|
|
7
|
+
auth: 'supabase/gotrue:v2.196.0',
|
|
8
|
+
rest: 'postgrest/postgrest:v14.17',
|
|
9
|
+
realtime: 'supabase/realtime:v2.134.10',
|
|
10
|
+
storage: 'supabase/storage-api:v1.74.0',
|
|
11
|
+
imgproxy: 'darthsim/imgproxy:v3.31.4',
|
|
12
|
+
meta: 'supabase/postgres-meta:v0.99.0',
|
|
13
|
+
gateway: 'envoyproxy/envoy:v1.39.1',
|
|
14
|
+
studio: 'supabase/studio:2026.09.07-sha-7996410',
|
|
15
|
+
};
|
|
16
|
+
const SUPABASE_ENVOY_CONFIG_BEFORE_STORAGE_ROUTE = `static_resources:
|
|
17
|
+
listeners:
|
|
18
|
+
- name: supabase
|
|
19
|
+
address:
|
|
20
|
+
socket_address:
|
|
21
|
+
address: 0.0.0.0
|
|
22
|
+
port_value: 8000
|
|
23
|
+
filter_chains:
|
|
24
|
+
- filters:
|
|
25
|
+
- name: envoy.filters.network.http_connection_manager
|
|
26
|
+
typed_config:
|
|
27
|
+
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
|
|
28
|
+
stat_prefix: supabase
|
|
29
|
+
normalize_path: true
|
|
30
|
+
merge_slashes: true
|
|
31
|
+
upgrade_configs:
|
|
32
|
+
- upgrade_type: websocket
|
|
33
|
+
route_config:
|
|
34
|
+
name: supabase
|
|
35
|
+
virtual_hosts:
|
|
36
|
+
- name: supabase
|
|
37
|
+
domains: ["*"]
|
|
38
|
+
cors:
|
|
39
|
+
allow_origin_string_match:
|
|
40
|
+
- safe_regex:
|
|
41
|
+
regex: ".*"
|
|
42
|
+
allow_methods: "GET,POST,PUT,PATCH,DELETE,OPTIONS,HEAD"
|
|
43
|
+
allow_headers: "*"
|
|
44
|
+
routes:
|
|
45
|
+
- match: { prefix: "/auth/v1/" }
|
|
46
|
+
route: { cluster: auth, prefix_rewrite: "/", timeout: 30s }
|
|
47
|
+
- match: { prefix: "/rest/v1/" }
|
|
48
|
+
route: { cluster: rest, prefix_rewrite: "/", timeout: 30s }
|
|
49
|
+
- match: { prefix: "/realtime/v1/" }
|
|
50
|
+
route: { cluster: realtime, prefix_rewrite: "/", timeout: 30s }
|
|
51
|
+
`;
|
|
52
|
+
const SUPABASE_ENVOY_STORAGE_ROUTE = ` - match: { prefix: "/storage/v1/" }
|
|
53
|
+
route: { cluster: storage, prefix_rewrite: "/", timeout: 30s }
|
|
54
|
+
`;
|
|
55
|
+
const SUPABASE_ENVOY_CONFIG_AFTER_STORAGE_ROUTE = ` http_filters:
|
|
56
|
+
- name: envoy.filters.http.cors
|
|
57
|
+
typed_config:
|
|
58
|
+
"@type": type.googleapis.com/envoy.extensions.filters.http.cors.v3.Cors
|
|
59
|
+
- name: envoy.filters.http.router
|
|
60
|
+
typed_config:
|
|
61
|
+
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
|
|
62
|
+
clusters:
|
|
63
|
+
- name: auth
|
|
64
|
+
connect_timeout: 5s
|
|
65
|
+
type: STRICT_DNS
|
|
66
|
+
load_assignment:
|
|
67
|
+
cluster_name: auth
|
|
68
|
+
endpoints:
|
|
69
|
+
- lb_endpoints:
|
|
70
|
+
- endpoint:
|
|
71
|
+
address: { socket_address: { address: supabase-auth, port_value: 9999 } }
|
|
72
|
+
- name: rest
|
|
73
|
+
connect_timeout: 5s
|
|
74
|
+
type: STRICT_DNS
|
|
75
|
+
load_assignment:
|
|
76
|
+
cluster_name: rest
|
|
77
|
+
endpoints:
|
|
78
|
+
- lb_endpoints:
|
|
79
|
+
- endpoint:
|
|
80
|
+
address: { socket_address: { address: supabase-rest, port_value: 3000 } }
|
|
81
|
+
- name: realtime
|
|
82
|
+
connect_timeout: 5s
|
|
83
|
+
type: STRICT_DNS
|
|
84
|
+
load_assignment:
|
|
85
|
+
cluster_name: realtime
|
|
86
|
+
endpoints:
|
|
87
|
+
- lb_endpoints:
|
|
88
|
+
- endpoint:
|
|
89
|
+
address: { socket_address: { address: supabase-realtime, port_value: 4000 } }
|
|
90
|
+
`;
|
|
91
|
+
const SUPABASE_ENVOY_STORAGE_CLUSTER = ` - name: storage
|
|
92
|
+
connect_timeout: 5s
|
|
93
|
+
type: STRICT_DNS
|
|
94
|
+
load_assignment:
|
|
95
|
+
cluster_name: storage
|
|
96
|
+
endpoints:
|
|
97
|
+
- lb_endpoints:
|
|
98
|
+
- endpoint:
|
|
99
|
+
address: { socket_address: { address: supabase-storage, port_value: 5000 } }
|
|
100
|
+
`;
|
|
101
|
+
export const SUPABASE_ENVOY_CONFIG = `${SUPABASE_ENVOY_CONFIG_BEFORE_STORAGE_ROUTE}${SUPABASE_ENVOY_STORAGE_ROUTE}${SUPABASE_ENVOY_CONFIG_AFTER_STORAGE_ROUTE}${SUPABASE_ENVOY_STORAGE_CLUSTER}`;
|
|
102
|
+
export const SUPABASE_ENVOY_CONFIG_WITHOUT_STORAGE = `${SUPABASE_ENVOY_CONFIG_BEFORE_STORAGE_ROUTE}${SUPABASE_ENVOY_CONFIG_AFTER_STORAGE_ROUTE}`;
|
|
103
|
+
//# sourceMappingURL=supabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.js","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/constants/supabase.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,6BAA6B,GAAG;IAC3C,MAAM,EAAE,eAAe;IACvB,IAAI,EAAE,oBAAoB;CAClB,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,QAAQ,EAAE,8BAA8B;IACxC,IAAI,EAAE,0BAA0B;IAChC,IAAI,EAAE,4BAA4B;IAClC,QAAQ,EAAE,6BAA6B;IACvC,OAAO,EAAE,8BAA8B;IACvC,QAAQ,EAAE,2BAA2B;IACrC,IAAI,EAAE,gCAAgC;IACtC,OAAO,EAAE,0BAA0B;IACnC,MAAM,EAAE,wCAAwC;CACxC,CAAC;AAEX,MAAM,0CAA0C,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmClD,CAAC;AAEF,MAAM,4BAA4B,GAAG;;CAEpC,CAAC;AAEF,MAAM,yCAAyC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCjD,CAAC;AAEF,MAAM,8BAA8B,GAAG;;;;;;;;;CAStC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,0CAA0C,GAAG,4BAA4B,GAAG,yCAAyC,GAAG,8BAA8B,EAAE,CAAC;AAEjM,MAAM,CAAC,MAAM,qCAAqC,GAAG,GAAG,0CAA0C,GAAG,yCAAyC,EAAE,CAAC","sourcesContent":["export const SUPABASE_BOOTSTRAP_CREDENTIAL = {\n source: 'control-plane',\n name: 'SUPABASE_BOOTSTRAP',\n} as const;\n\nexport const SUPABASE_IMAGES = {\n database: 'supabase/postgres:17.6.1.136',\n auth: 'supabase/gotrue:v2.196.0',\n rest: 'postgrest/postgrest:v14.17',\n realtime: 'supabase/realtime:v2.134.10',\n storage: 'supabase/storage-api:v1.74.0',\n imgproxy: 'darthsim/imgproxy:v3.31.4',\n meta: 'supabase/postgres-meta:v0.99.0',\n gateway: 'envoyproxy/envoy:v1.39.1',\n studio: 'supabase/studio:2026.09.07-sha-7996410',\n} as const;\n\nconst SUPABASE_ENVOY_CONFIG_BEFORE_STORAGE_ROUTE = `static_resources:\n listeners:\n - name: supabase\n address:\n socket_address:\n address: 0.0.0.0\n port_value: 8000\n filter_chains:\n - filters:\n - name: envoy.filters.network.http_connection_manager\n typed_config:\n \"@type\": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager\n stat_prefix: supabase\n normalize_path: true\n merge_slashes: true\n upgrade_configs:\n - upgrade_type: websocket\n route_config:\n name: supabase\n virtual_hosts:\n - name: supabase\n domains: [\"*\"]\n cors:\n allow_origin_string_match:\n - safe_regex:\n regex: \".*\"\n allow_methods: \"GET,POST,PUT,PATCH,DELETE,OPTIONS,HEAD\"\n allow_headers: \"*\"\n routes:\n - match: { prefix: \"/auth/v1/\" }\n route: { cluster: auth, prefix_rewrite: \"/\", timeout: 30s }\n - match: { prefix: \"/rest/v1/\" }\n route: { cluster: rest, prefix_rewrite: \"/\", timeout: 30s }\n - match: { prefix: \"/realtime/v1/\" }\n route: { cluster: realtime, prefix_rewrite: \"/\", timeout: 30s }\n`;\n\nconst SUPABASE_ENVOY_STORAGE_ROUTE = ` - match: { prefix: \"/storage/v1/\" }\n route: { cluster: storage, prefix_rewrite: \"/\", timeout: 30s }\n`;\n\nconst SUPABASE_ENVOY_CONFIG_AFTER_STORAGE_ROUTE = ` http_filters:\n - name: envoy.filters.http.cors\n typed_config:\n \"@type\": type.googleapis.com/envoy.extensions.filters.http.cors.v3.Cors\n - name: envoy.filters.http.router\n typed_config:\n \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n clusters:\n - name: auth\n connect_timeout: 5s\n type: STRICT_DNS\n load_assignment:\n cluster_name: auth\n endpoints:\n - lb_endpoints:\n - endpoint:\n address: { socket_address: { address: supabase-auth, port_value: 9999 } }\n - name: rest\n connect_timeout: 5s\n type: STRICT_DNS\n load_assignment:\n cluster_name: rest\n endpoints:\n - lb_endpoints:\n - endpoint:\n address: { socket_address: { address: supabase-rest, port_value: 3000 } }\n - name: realtime\n connect_timeout: 5s\n type: STRICT_DNS\n load_assignment:\n cluster_name: realtime\n endpoints:\n - lb_endpoints:\n - endpoint:\n address: { socket_address: { address: supabase-realtime, port_value: 4000 } }\n`;\n\nconst SUPABASE_ENVOY_STORAGE_CLUSTER = ` - name: storage\n connect_timeout: 5s\n type: STRICT_DNS\n load_assignment:\n cluster_name: storage\n endpoints:\n - lb_endpoints:\n - endpoint:\n address: { socket_address: { address: supabase-storage, port_value: 5000 } }\n`;\n\nexport const SUPABASE_ENVOY_CONFIG = `${SUPABASE_ENVOY_CONFIG_BEFORE_STORAGE_ROUTE}${SUPABASE_ENVOY_STORAGE_ROUTE}${SUPABASE_ENVOY_CONFIG_AFTER_STORAGE_ROUTE}${SUPABASE_ENVOY_STORAGE_CLUSTER}`;\n\nexport const SUPABASE_ENVOY_CONFIG_WITHOUT_STORAGE = `${SUPABASE_ENVOY_CONFIG_BEFORE_STORAGE_ROUTE}${SUPABASE_ENVOY_CONFIG_AFTER_STORAGE_ROUTE}`;\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InfraExecutionContext, InfraWorkloadSpec } from '@ankhorage/contracts/infra';
|
|
2
|
+
/*** Create the GoTrue authentication workload from the external Auth URL and authored sign-up policy. */
|
|
3
|
+
export declare function createSupabaseAuthWorkload(context: InfraExecutionContext, baseUrl: string): InfraWorkloadSpec;
|
|
4
|
+
//# sourceMappingURL=createSupabaseAuthWorkload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseAuthWorkload.d.ts","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseAuthWorkload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,iBAAiB,EAElB,MAAM,4BAA4B,CAAC;AAIpC,yGAAyG;AACzG,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,MAAM,GACd,iBAAiB,CAgCnB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';
|
|
2
|
+
/*** Create the GoTrue authentication workload from the external Auth URL and authored sign-up policy. */
|
|
3
|
+
export function createSupabaseAuthWorkload(context, baseUrl) {
|
|
4
|
+
return {
|
|
5
|
+
id: 'supabase-auth',
|
|
6
|
+
artifact: { kind: 'image', image: SUPABASE_IMAGES.auth },
|
|
7
|
+
ports: { http: { port: 9999 } },
|
|
8
|
+
environment: {
|
|
9
|
+
GOTRUE_API_HOST: literal('0.0.0.0'),
|
|
10
|
+
GOTRUE_API_PORT: literal('9999'),
|
|
11
|
+
API_EXTERNAL_URL: literal(`${baseUrl}/auth/v1`),
|
|
12
|
+
GOTRUE_SITE_URL: literal(baseUrl),
|
|
13
|
+
GOTRUE_URI_ALLOW_LIST: literal(''),
|
|
14
|
+
GOTRUE_DB_DRIVER: literal('postgres'),
|
|
15
|
+
GOTRUE_DB_DATABASE_URL: databaseUrl('supabase_auth_admin'),
|
|
16
|
+
DB_NAMESPACE: literal('auth'),
|
|
17
|
+
GOTRUE_JWT_ADMIN_ROLES: literal('service_role'),
|
|
18
|
+
GOTRUE_JWT_AUD: literal('authenticated'),
|
|
19
|
+
GOTRUE_JWT_DEFAULT_GROUP_NAME: literal('authenticated'),
|
|
20
|
+
GOTRUE_JWT_EXP: literal('3600'),
|
|
21
|
+
GOTRUE_JWT_SECRET: credential('jwtSecret'),
|
|
22
|
+
GOTRUE_JWT_ISSUER: literal(`${baseUrl}/auth/v1`),
|
|
23
|
+
GOTRUE_EXTERNAL_EMAIL_ENABLED: literal('true'),
|
|
24
|
+
GOTRUE_EXTERNAL_ANONYMOUS_USERS_ENABLED: literal('false'),
|
|
25
|
+
GOTRUE_MAILER_AUTOCONFIRM: literal(context.desired.auth?.signUp?.signUpPolicy === 'requireVerification' ? 'false' : 'true'),
|
|
26
|
+
GOTRUE_EXTERNAL_PHONE_ENABLED: literal('false'),
|
|
27
|
+
},
|
|
28
|
+
health: { kind: 'http', port: 9999, path: '/health' },
|
|
29
|
+
exposure: 'internal',
|
|
30
|
+
replicas: 1,
|
|
31
|
+
dependsOn: { 'supabase-db': true },
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/*** Create one literal authentication workload value. */
|
|
35
|
+
function literal(value) {
|
|
36
|
+
return { kind: 'literal', value };
|
|
37
|
+
}
|
|
38
|
+
/*** Create one execution-only Supabase bootstrap credential reference. */
|
|
39
|
+
function credential(key) {
|
|
40
|
+
return { kind: 'credential', reference: SUPABASE_BOOTSTRAP_CREDENTIAL, key };
|
|
41
|
+
}
|
|
42
|
+
/*** Create one password-bearing Postgres URL materialized only by the selected runtime. */
|
|
43
|
+
function databaseUrl(user) {
|
|
44
|
+
return {
|
|
45
|
+
kind: 'template',
|
|
46
|
+
segments: [
|
|
47
|
+
literal(`postgres://${user}:`),
|
|
48
|
+
credential('postgresPassword'),
|
|
49
|
+
literal('@supabase-db:5432/postgres'),
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=createSupabaseAuthWorkload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseAuthWorkload.js","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseAuthWorkload.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEvF,yGAAyG;AACzG,MAAM,UAAU,0BAA0B,CACxC,OAA8B,EAC9B,OAAe;IAEf,OAAO;QACL,EAAE,EAAE,eAAe;QACnB,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,IAAI,EAAE;QACxD,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAC/B,WAAW,EAAE;YACX,eAAe,EAAE,OAAO,CAAC,SAAS,CAAC;YACnC,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC;YAChC,gBAAgB,EAAE,OAAO,CAAC,GAAG,OAAO,UAAU,CAAC;YAC/C,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC;YACjC,qBAAqB,EAAE,OAAO,CAAC,EAAE,CAAC;YAClC,gBAAgB,EAAE,OAAO,CAAC,UAAU,CAAC;YACrC,sBAAsB,EAAE,WAAW,CAAC,qBAAqB,CAAC;YAC1D,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC;YAC7B,sBAAsB,EAAE,OAAO,CAAC,cAAc,CAAC;YAC/C,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC;YACxC,6BAA6B,EAAE,OAAO,CAAC,eAAe,CAAC;YACvD,cAAc,EAAE,OAAO,CAAC,MAAM,CAAC;YAC/B,iBAAiB,EAAE,UAAU,CAAC,WAAW,CAAC;YAC1C,iBAAiB,EAAE,OAAO,CAAC,GAAG,OAAO,UAAU,CAAC;YAChD,6BAA6B,EAAE,OAAO,CAAC,MAAM,CAAC;YAC9C,uCAAuC,EAAE,OAAO,CAAC,OAAO,CAAC;YACzD,yBAAyB,EAAE,OAAO,CAChC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,KAAK,qBAAqB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CACxF;YACD,6BAA6B,EAAE,OAAO,CAAC,OAAO,CAAC;SAChD;QACD,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE;QACrD,QAAQ,EAAE,UAAU;QACpB,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE;KACnC,CAAC;AACJ,CAAC;AAED,yDAAyD;AACzD,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACpC,CAAC;AAED,0EAA0E;AAC1E,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B,EAAE,GAAG,EAAE,CAAC;AAC/E,CAAC;AAED,2FAA2F;AAC3F,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,OAAO,CAAC,cAAc,IAAI,GAAG,CAAC;YAC9B,UAAU,CAAC,kBAAkB,CAAC;YAC9B,OAAO,CAAC,4BAA4B,CAAC;SACtC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n InfraExecutionContext,\n InfraWorkloadScalarValue,\n InfraWorkloadSpec,\n InfraWorkloadValue,\n} from '@ankhorage/contracts/infra';\n\nimport { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';\n\n/*** Create the GoTrue authentication workload from the external Auth URL and authored sign-up policy. */\nexport function createSupabaseAuthWorkload(\n context: InfraExecutionContext,\n baseUrl: string,\n): InfraWorkloadSpec {\n return {\n id: 'supabase-auth',\n artifact: { kind: 'image', image: SUPABASE_IMAGES.auth },\n ports: { http: { port: 9999 } },\n environment: {\n GOTRUE_API_HOST: literal('0.0.0.0'),\n GOTRUE_API_PORT: literal('9999'),\n API_EXTERNAL_URL: literal(`${baseUrl}/auth/v1`),\n GOTRUE_SITE_URL: literal(baseUrl),\n GOTRUE_URI_ALLOW_LIST: literal(''),\n GOTRUE_DB_DRIVER: literal('postgres'),\n GOTRUE_DB_DATABASE_URL: databaseUrl('supabase_auth_admin'),\n DB_NAMESPACE: literal('auth'),\n GOTRUE_JWT_ADMIN_ROLES: literal('service_role'),\n GOTRUE_JWT_AUD: literal('authenticated'),\n GOTRUE_JWT_DEFAULT_GROUP_NAME: literal('authenticated'),\n GOTRUE_JWT_EXP: literal('3600'),\n GOTRUE_JWT_SECRET: credential('jwtSecret'),\n GOTRUE_JWT_ISSUER: literal(`${baseUrl}/auth/v1`),\n GOTRUE_EXTERNAL_EMAIL_ENABLED: literal('true'),\n GOTRUE_EXTERNAL_ANONYMOUS_USERS_ENABLED: literal('false'),\n GOTRUE_MAILER_AUTOCONFIRM: literal(\n context.desired.auth?.signUp?.signUpPolicy === 'requireVerification' ? 'false' : 'true',\n ),\n GOTRUE_EXTERNAL_PHONE_ENABLED: literal('false'),\n },\n health: { kind: 'http', port: 9999, path: '/health' },\n exposure: 'internal',\n replicas: 1,\n dependsOn: { 'supabase-db': true },\n };\n}\n\n/*** Create one literal authentication workload value. */\nfunction literal(value: string): InfraWorkloadScalarValue {\n return { kind: 'literal', value };\n}\n\n/*** Create one execution-only Supabase bootstrap credential reference. */\nfunction credential(key: string): InfraWorkloadScalarValue {\n return { kind: 'credential', reference: SUPABASE_BOOTSTRAP_CREDENTIAL, key };\n}\n\n/*** Create one password-bearing Postgres URL materialized only by the selected runtime. */\nfunction databaseUrl(user: string): InfraWorkloadValue {\n return {\n kind: 'template',\n segments: [\n literal(`postgres://${user}:`),\n credential('postgresPassword'),\n literal('@supabase-db:5432/postgres'),\n ],\n };\n}\n"]}
|
package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseBackupWorkload.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InfraExecutionContext, InfraWorkloadSpec } from '@ankhorage/contracts/infra';
|
|
2
|
+
/*** Create the scheduled logical Postgres backup workload when backup intent is configured. */
|
|
3
|
+
export declare function createSupabaseDatabaseBackupWorkload(context: InfraExecutionContext): InfraWorkloadSpec | undefined;
|
|
4
|
+
//# sourceMappingURL=createSupabaseDatabaseBackupWorkload.d.ts.map
|
package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseBackupWorkload.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseDatabaseBackupWorkload.d.ts","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseDatabaseBackupWorkload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AA2KpC,+FAA+F;AAC/F,wBAAgB,oCAAoC,CAClD,OAAO,EAAE,qBAAqB,GAC7B,iBAAiB,GAAG,SAAS,CAkC/B"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { SUPABASE_DATA_RESTORE_WORKLOAD_ID, SUPABASE_RECOVERY_SCHEMA } from '../constants/recovery';
|
|
2
|
+
import { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';
|
|
3
|
+
import { createSupabaseS3Values } from './createSupabaseS3Values';
|
|
4
|
+
const DEFAULT_BACKUP_INTERVAL_HOURS = 24;
|
|
5
|
+
const INTERNAL_SCHEMA_PATTERN = [
|
|
6
|
+
'information_schema',
|
|
7
|
+
'pg_*',
|
|
8
|
+
SUPABASE_RECOVERY_SCHEMA,
|
|
9
|
+
'_analytics',
|
|
10
|
+
'_realtime',
|
|
11
|
+
'_supavisor',
|
|
12
|
+
'auth',
|
|
13
|
+
'etl',
|
|
14
|
+
'extensions',
|
|
15
|
+
'pgbouncer',
|
|
16
|
+
'realtime',
|
|
17
|
+
'storage',
|
|
18
|
+
'supabase_functions',
|
|
19
|
+
'supabase_migrations',
|
|
20
|
+
'cron',
|
|
21
|
+
'dbdev',
|
|
22
|
+
'graphql',
|
|
23
|
+
'graphql_public',
|
|
24
|
+
'net',
|
|
25
|
+
'pgmq',
|
|
26
|
+
'pgsodium',
|
|
27
|
+
'pgsodium_masks',
|
|
28
|
+
'pgtle',
|
|
29
|
+
'repack',
|
|
30
|
+
'tiger',
|
|
31
|
+
'tiger_data',
|
|
32
|
+
'timescaledb_*',
|
|
33
|
+
'_timescaledb_*',
|
|
34
|
+
'topology',
|
|
35
|
+
'vault',
|
|
36
|
+
].join('|');
|
|
37
|
+
const DATA_EXCLUDED_SCHEMA_PATTERN = [
|
|
38
|
+
'information_schema',
|
|
39
|
+
'pg_*',
|
|
40
|
+
SUPABASE_RECOVERY_SCHEMA,
|
|
41
|
+
'graphql',
|
|
42
|
+
'graphql_public',
|
|
43
|
+
'pgsodium',
|
|
44
|
+
'pgsodium_masks',
|
|
45
|
+
'pgtle',
|
|
46
|
+
'repack',
|
|
47
|
+
'tiger',
|
|
48
|
+
'tiger_data',
|
|
49
|
+
'timescaledb_*',
|
|
50
|
+
'_timescaledb_*',
|
|
51
|
+
'topology',
|
|
52
|
+
'vault',
|
|
53
|
+
'etl',
|
|
54
|
+
'extensions',
|
|
55
|
+
'pgbouncer',
|
|
56
|
+
'realtime',
|
|
57
|
+
'supabase_migrations',
|
|
58
|
+
'_analytics',
|
|
59
|
+
'_realtime',
|
|
60
|
+
'_supavisor',
|
|
61
|
+
].join('|');
|
|
62
|
+
const RESERVED_ROLE_PATTERN = [
|
|
63
|
+
'anon',
|
|
64
|
+
'authenticated',
|
|
65
|
+
'authenticator',
|
|
66
|
+
'cli_login_.*',
|
|
67
|
+
'dashboard_user',
|
|
68
|
+
'pgbouncer',
|
|
69
|
+
'postgres',
|
|
70
|
+
'service_role',
|
|
71
|
+
'supabase_.*',
|
|
72
|
+
'pgsodium_keyholder',
|
|
73
|
+
'pgsodium_keyiduser',
|
|
74
|
+
'pgsodium_keymaker',
|
|
75
|
+
'pgtle_admin',
|
|
76
|
+
].join('|');
|
|
77
|
+
const ALLOWED_CONFIG_PATTERN = [
|
|
78
|
+
'pgaudit.*',
|
|
79
|
+
'pgrst.*',
|
|
80
|
+
'session_replication_role',
|
|
81
|
+
'statement_timeout',
|
|
82
|
+
'track_io_timing',
|
|
83
|
+
].join('|');
|
|
84
|
+
const BACKUP_SCRIPT = `
|
|
85
|
+
set -eu
|
|
86
|
+
umask 077
|
|
87
|
+
cleanup() {
|
|
88
|
+
rm -f /tmp/ankhorage-s3-curl.conf /tmp/ankhorage-roles.sql /tmp/ankhorage-schema.sql \
|
|
89
|
+
/tmp/ankhorage-data.sql /tmp/ankhorage-latest
|
|
90
|
+
}
|
|
91
|
+
trap cleanup EXIT INT TERM
|
|
92
|
+
upload_file() {
|
|
93
|
+
file="$1"
|
|
94
|
+
key="$2"
|
|
95
|
+
curl --fail --silent --show-error --config /tmp/ankhorage-s3-curl.conf \
|
|
96
|
+
--aws-sigv4 "aws:amz:\${S3_REGION}:s3" --upload-file "$file" "\${S3_URL_PREFIX}/$key"
|
|
97
|
+
}
|
|
98
|
+
backup_once() {
|
|
99
|
+
timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
|
|
100
|
+
prefix="database/\${timestamp}"
|
|
101
|
+
printf 'user = "%s:%s"\n' "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" > /tmp/ankhorage-s3-curl.conf
|
|
102
|
+
|
|
103
|
+
pg_dumpall --roles-only --role postgres --quote-all-identifiers --no-role-passwords --no-comments \
|
|
104
|
+
| sed -E 's/^\\(un)?restrict .*$/-- &/' \
|
|
105
|
+
| sed -E 's/^CREATE ROLE "(${RESERVED_ROLE_PATTERN})"/-- &/' \
|
|
106
|
+
| sed -E 's/ (NOSUPERUSER|NOREPLICATION)//g' \
|
|
107
|
+
| sed -E 's/^-- (.* SET "(${ALLOWED_CONFIG_PATTERN})" .*)/\\1/' \
|
|
108
|
+
| sed -E 's/^ALTER ROLE "(${RESERVED_ROLE_PATTERN})"/-- &/' \
|
|
109
|
+
| sed -E 's/^GRANT "(${RESERVED_ROLE_PATTERN})" TO /-- &/' \
|
|
110
|
+
| sed -E 's/^GRANT ".*" TO "(${RESERVED_ROLE_PATTERN})"/-- &/' \
|
|
111
|
+
| sed -E 's/^GRANT .* GRANTED BY "(${RESERVED_ROLE_PATTERN})";$/-- &/' \
|
|
112
|
+
| sed -E 's/^GRANT (SET|ALTER SYSTEM) ON PARAMETER .* TO "(${RESERVED_ROLE_PATTERN})"( WITH GRANT OPTION)?;$/-- &/' \
|
|
113
|
+
| uniq > /tmp/ankhorage-roles.sql
|
|
114
|
+
printf '\nRESET ALL;\n' >> /tmp/ankhorage-roles.sql
|
|
115
|
+
|
|
116
|
+
pg_dump --schema-only --quote-all-identifiers --role postgres \
|
|
117
|
+
--exclude-schema '${INTERNAL_SCHEMA_PATTERN}' \
|
|
118
|
+
| sed -E 's/^\\(un)?restrict .*$/-- &/' \
|
|
119
|
+
| sed -E 's/^CREATE SCHEMA "/CREATE SCHEMA IF NOT EXISTS "/' \
|
|
120
|
+
| sed -E 's/^CREATE TABLE "/CREATE TABLE IF NOT EXISTS "/' \
|
|
121
|
+
| sed -E 's/^CREATE SEQUENCE "/CREATE SEQUENCE IF NOT EXISTS "/' \
|
|
122
|
+
| sed -E 's/^CREATE VIEW "/CREATE OR REPLACE VIEW "/' \
|
|
123
|
+
| sed -E 's/^CREATE FUNCTION "/CREATE OR REPLACE FUNCTION "/' \
|
|
124
|
+
| sed -E 's/^CREATE TRIGGER "/CREATE OR REPLACE TRIGGER "/' \
|
|
125
|
+
| sed -E 's/^CREATE PUBLICATION "supabase_realtime/-- &/' \
|
|
126
|
+
| sed -E 's/^CREATE EVENT TRIGGER /-- &/' \
|
|
127
|
+
| sed -E 's/^ WHEN TAG IN /-- &/' \
|
|
128
|
+
| sed -E 's/^ EXECUTE FUNCTION /-- &/' \
|
|
129
|
+
| sed -E 's/^ALTER EVENT TRIGGER /-- &/' \
|
|
130
|
+
| sed -E 's/^ALTER PUBLICATION "supabase_realtime_/-- &/' \
|
|
131
|
+
| sed -E 's/^ALTER FOREIGN DATA WRAPPER (.+) OWNER TO /-- &/' \
|
|
132
|
+
| sed -E 's/^ALTER DEFAULT PRIVILEGES FOR ROLE "supabase_admin"/-- &/' \
|
|
133
|
+
| sed -E 's/^GRANT ALL ON FOREIGN DATA WRAPPER (.+) TO "postgres" WITH GRANT OPTION/-- &/' \
|
|
134
|
+
| sed -E 's/^GRANT (.+) ON (.+) "(${INTERNAL_SCHEMA_PATTERN})"/-- &/' \
|
|
135
|
+
| sed -E 's/^REVOKE (.+) ON (.+) "(${INTERNAL_SCHEMA_PATTERN})"/-- &/' \
|
|
136
|
+
| sed -E 's/^(CREATE EXTENSION IF NOT EXISTS "pg_tle").+/\\1;/' \
|
|
137
|
+
| sed -E 's/^(CREATE EXTENSION IF NOT EXISTS "pgsodium").+/\\1;/' \
|
|
138
|
+
| sed -E 's/^(CREATE EXTENSION IF NOT EXISTS "pgmq").+/\\1;/' \
|
|
139
|
+
| sed -E 's/^COMMENT ON EXTENSION (.+)/-- &/' \
|
|
140
|
+
| sed -E 's/^CREATE POLICY "cron_job_/-- &/' \
|
|
141
|
+
| sed -E 's/^ALTER TABLE "cron"/-- &/' \
|
|
142
|
+
| sed -E 's/^SET transaction_timeout = 0;/-- &/' \
|
|
143
|
+
> /tmp/ankhorage-schema.sql
|
|
144
|
+
|
|
145
|
+
printf 'SET session_replication_role = replica;\n\n' > /tmp/ankhorage-data.sql
|
|
146
|
+
pg_dump --data-only --quote-all-identifiers --role postgres \
|
|
147
|
+
--exclude-schema '${DATA_EXCLUDED_SCHEMA_PATTERN}' \
|
|
148
|
+
--exclude-table 'auth.schema_migrations' \
|
|
149
|
+
--exclude-table 'storage.migrations' \
|
|
150
|
+
--exclude-table 'storage.buckets_vectors' \
|
|
151
|
+
--exclude-table 'storage.vector_indexes' \
|
|
152
|
+
--exclude-table 'supabase_functions.migrations' \
|
|
153
|
+
--schema '*' \
|
|
154
|
+
| sed -E 's/^\\(un)?restrict .*$/-- &/' >> /tmp/ankhorage-data.sql
|
|
155
|
+
printf '\nRESET ALL;\n' >> /tmp/ankhorage-data.sql
|
|
156
|
+
|
|
157
|
+
upload_file /tmp/ankhorage-roles.sql "\${prefix}/roles.sql"
|
|
158
|
+
upload_file /tmp/ankhorage-schema.sql "\${prefix}/schema.sql"
|
|
159
|
+
upload_file /tmp/ankhorage-data.sql "\${prefix}/data.sql"
|
|
160
|
+
printf '%s' "$prefix" > /tmp/ankhorage-latest
|
|
161
|
+
upload_file /tmp/ankhorage-latest 'database/latest'
|
|
162
|
+
cleanup
|
|
163
|
+
touch /tmp/ankhorage-backup-ready
|
|
164
|
+
}
|
|
165
|
+
backup_once
|
|
166
|
+
while sleep "$BACKUP_INTERVAL_SECONDS"; do backup_once; done
|
|
167
|
+
`;
|
|
168
|
+
/*** Create the scheduled logical Postgres backup workload when backup intent is configured. */
|
|
169
|
+
export function createSupabaseDatabaseBackupWorkload(context) {
|
|
170
|
+
const backup = context.desired.database?.provider === 'supabase' ? context.desired.database.backup : undefined;
|
|
171
|
+
if (backup === undefined)
|
|
172
|
+
return undefined;
|
|
173
|
+
const s3 = createSupabaseS3Values(backup.target);
|
|
174
|
+
const intervalHours = backup.intervalHours ?? DEFAULT_BACKUP_INTERVAL_HOURS;
|
|
175
|
+
return {
|
|
176
|
+
id: 'supabase-db-backup',
|
|
177
|
+
artifact: { kind: 'image', image: SUPABASE_IMAGES.database },
|
|
178
|
+
command: ['sh'],
|
|
179
|
+
args: ['-ec', BACKUP_SCRIPT],
|
|
180
|
+
environment: {
|
|
181
|
+
PGHOST: literal('supabase-db'),
|
|
182
|
+
PGPORT: literal('5432'),
|
|
183
|
+
PGDATABASE: literal('postgres'),
|
|
184
|
+
PGUSER: literal('postgres'),
|
|
185
|
+
PGPASSWORD: bootstrapCredential('postgresPassword'),
|
|
186
|
+
S3_REGION: s3.region,
|
|
187
|
+
S3_URL_PREFIX: s3.urlPrefix,
|
|
188
|
+
AWS_ACCESS_KEY_ID: s3.accessKeyId,
|
|
189
|
+
AWS_SECRET_ACCESS_KEY: s3.secretAccessKey,
|
|
190
|
+
BACKUP_INTERVAL_SECONDS: literal(String(intervalHours * 3600)),
|
|
191
|
+
},
|
|
192
|
+
health: {
|
|
193
|
+
kind: 'command',
|
|
194
|
+
command: ['test', '-f', '/tmp/ankhorage-backup-ready'],
|
|
195
|
+
intervalSeconds: 30,
|
|
196
|
+
timeoutSeconds: 5,
|
|
197
|
+
failureThreshold: 10,
|
|
198
|
+
},
|
|
199
|
+
exposure: 'internal',
|
|
200
|
+
replicas: 1,
|
|
201
|
+
dependsOn: { [SUPABASE_DATA_RESTORE_WORKLOAD_ID]: true },
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/*** Create one literal workload value. */
|
|
205
|
+
function literal(value) {
|
|
206
|
+
return { kind: 'literal', value };
|
|
207
|
+
}
|
|
208
|
+
/*** Create one execution-only Supabase bootstrap credential reference. */
|
|
209
|
+
function bootstrapCredential(key) {
|
|
210
|
+
return { kind: 'credential', reference: SUPABASE_BOOTSTRAP_CREDENTIAL, key };
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=createSupabaseDatabaseBackupWorkload.js.map
|
package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseBackupWorkload.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseDatabaseBackupWorkload.js","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseDatabaseBackupWorkload.ts"],"names":[],"mappings":"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","sourcesContent":["import type {\n InfraExecutionContext,\n InfraWorkloadScalarValue,\n InfraWorkloadSpec,\n} from '@ankhorage/contracts/infra';\n\nimport { SUPABASE_DATA_RESTORE_WORKLOAD_ID, SUPABASE_RECOVERY_SCHEMA } from '../constants/recovery';\nimport { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';\nimport { createSupabaseS3Values } from './createSupabaseS3Values';\n\nconst DEFAULT_BACKUP_INTERVAL_HOURS = 24;\nconst INTERNAL_SCHEMA_PATTERN = [\n 'information_schema',\n 'pg_*',\n SUPABASE_RECOVERY_SCHEMA,\n '_analytics',\n '_realtime',\n '_supavisor',\n 'auth',\n 'etl',\n 'extensions',\n 'pgbouncer',\n 'realtime',\n 'storage',\n 'supabase_functions',\n 'supabase_migrations',\n 'cron',\n 'dbdev',\n 'graphql',\n 'graphql_public',\n 'net',\n 'pgmq',\n 'pgsodium',\n 'pgsodium_masks',\n 'pgtle',\n 'repack',\n 'tiger',\n 'tiger_data',\n 'timescaledb_*',\n '_timescaledb_*',\n 'topology',\n 'vault',\n].join('|');\nconst DATA_EXCLUDED_SCHEMA_PATTERN = [\n 'information_schema',\n 'pg_*',\n SUPABASE_RECOVERY_SCHEMA,\n 'graphql',\n 'graphql_public',\n 'pgsodium',\n 'pgsodium_masks',\n 'pgtle',\n 'repack',\n 'tiger',\n 'tiger_data',\n 'timescaledb_*',\n '_timescaledb_*',\n 'topology',\n 'vault',\n 'etl',\n 'extensions',\n 'pgbouncer',\n 'realtime',\n 'supabase_migrations',\n '_analytics',\n '_realtime',\n '_supavisor',\n].join('|');\nconst RESERVED_ROLE_PATTERN = [\n 'anon',\n 'authenticated',\n 'authenticator',\n 'cli_login_.*',\n 'dashboard_user',\n 'pgbouncer',\n 'postgres',\n 'service_role',\n 'supabase_.*',\n 'pgsodium_keyholder',\n 'pgsodium_keyiduser',\n 'pgsodium_keymaker',\n 'pgtle_admin',\n].join('|');\nconst ALLOWED_CONFIG_PATTERN = [\n 'pgaudit.*',\n 'pgrst.*',\n 'session_replication_role',\n 'statement_timeout',\n 'track_io_timing',\n].join('|');\nconst BACKUP_SCRIPT = `\nset -eu\numask 077\ncleanup() {\n rm -f /tmp/ankhorage-s3-curl.conf /tmp/ankhorage-roles.sql /tmp/ankhorage-schema.sql \\\n /tmp/ankhorage-data.sql /tmp/ankhorage-latest\n}\ntrap cleanup EXIT INT TERM\nupload_file() {\n file=\"$1\"\n key=\"$2\"\n curl --fail --silent --show-error --config /tmp/ankhorage-s3-curl.conf \\\n --aws-sigv4 \"aws:amz:\\${S3_REGION}:s3\" --upload-file \"$file\" \"\\${S3_URL_PREFIX}/$key\"\n}\nbackup_once() {\n timestamp=\"$(date -u +%Y%m%dT%H%M%SZ)\"\n prefix=\"database/\\${timestamp}\"\n printf 'user = \"%s:%s\"\\n' \"$AWS_ACCESS_KEY_ID\" \"$AWS_SECRET_ACCESS_KEY\" > /tmp/ankhorage-s3-curl.conf\n\n pg_dumpall --roles-only --role postgres --quote-all-identifiers --no-role-passwords --no-comments \\\n | sed -E 's/^\\\\(un)?restrict .*$/-- &/' \\\n | sed -E 's/^CREATE ROLE \"(${RESERVED_ROLE_PATTERN})\"/-- &/' \\\n | sed -E 's/ (NOSUPERUSER|NOREPLICATION)//g' \\\n | sed -E 's/^-- (.* SET \"(${ALLOWED_CONFIG_PATTERN})\" .*)/\\\\1/' \\\n | sed -E 's/^ALTER ROLE \"(${RESERVED_ROLE_PATTERN})\"/-- &/' \\\n | sed -E 's/^GRANT \"(${RESERVED_ROLE_PATTERN})\" TO /-- &/' \\\n | sed -E 's/^GRANT \".*\" TO \"(${RESERVED_ROLE_PATTERN})\"/-- &/' \\\n | sed -E 's/^GRANT .* GRANTED BY \"(${RESERVED_ROLE_PATTERN})\";$/-- &/' \\\n | sed -E 's/^GRANT (SET|ALTER SYSTEM) ON PARAMETER .* TO \"(${RESERVED_ROLE_PATTERN})\"( WITH GRANT OPTION)?;$/-- &/' \\\n | uniq > /tmp/ankhorage-roles.sql\n printf '\\nRESET ALL;\\n' >> /tmp/ankhorage-roles.sql\n\n pg_dump --schema-only --quote-all-identifiers --role postgres \\\n --exclude-schema '${INTERNAL_SCHEMA_PATTERN}' \\\n | sed -E 's/^\\\\(un)?restrict .*$/-- &/' \\\n | sed -E 's/^CREATE SCHEMA \"/CREATE SCHEMA IF NOT EXISTS \"/' \\\n | sed -E 's/^CREATE TABLE \"/CREATE TABLE IF NOT EXISTS \"/' \\\n | sed -E 's/^CREATE SEQUENCE \"/CREATE SEQUENCE IF NOT EXISTS \"/' \\\n | sed -E 's/^CREATE VIEW \"/CREATE OR REPLACE VIEW \"/' \\\n | sed -E 's/^CREATE FUNCTION \"/CREATE OR REPLACE FUNCTION \"/' \\\n | sed -E 's/^CREATE TRIGGER \"/CREATE OR REPLACE TRIGGER \"/' \\\n | sed -E 's/^CREATE PUBLICATION \"supabase_realtime/-- &/' \\\n | sed -E 's/^CREATE EVENT TRIGGER /-- &/' \\\n | sed -E 's/^ WHEN TAG IN /-- &/' \\\n | sed -E 's/^ EXECUTE FUNCTION /-- &/' \\\n | sed -E 's/^ALTER EVENT TRIGGER /-- &/' \\\n | sed -E 's/^ALTER PUBLICATION \"supabase_realtime_/-- &/' \\\n | sed -E 's/^ALTER FOREIGN DATA WRAPPER (.+) OWNER TO /-- &/' \\\n | sed -E 's/^ALTER DEFAULT PRIVILEGES FOR ROLE \"supabase_admin\"/-- &/' \\\n | sed -E 's/^GRANT ALL ON FOREIGN DATA WRAPPER (.+) TO \"postgres\" WITH GRANT OPTION/-- &/' \\\n | sed -E 's/^GRANT (.+) ON (.+) \"(${INTERNAL_SCHEMA_PATTERN})\"/-- &/' \\\n | sed -E 's/^REVOKE (.+) ON (.+) \"(${INTERNAL_SCHEMA_PATTERN})\"/-- &/' \\\n | sed -E 's/^(CREATE EXTENSION IF NOT EXISTS \"pg_tle\").+/\\\\1;/' \\\n | sed -E 's/^(CREATE EXTENSION IF NOT EXISTS \"pgsodium\").+/\\\\1;/' \\\n | sed -E 's/^(CREATE EXTENSION IF NOT EXISTS \"pgmq\").+/\\\\1;/' \\\n | sed -E 's/^COMMENT ON EXTENSION (.+)/-- &/' \\\n | sed -E 's/^CREATE POLICY \"cron_job_/-- &/' \\\n | sed -E 's/^ALTER TABLE \"cron\"/-- &/' \\\n | sed -E 's/^SET transaction_timeout = 0;/-- &/' \\\n > /tmp/ankhorage-schema.sql\n\n printf 'SET session_replication_role = replica;\\n\\n' > /tmp/ankhorage-data.sql\n pg_dump --data-only --quote-all-identifiers --role postgres \\\n --exclude-schema '${DATA_EXCLUDED_SCHEMA_PATTERN}' \\\n --exclude-table 'auth.schema_migrations' \\\n --exclude-table 'storage.migrations' \\\n --exclude-table 'storage.buckets_vectors' \\\n --exclude-table 'storage.vector_indexes' \\\n --exclude-table 'supabase_functions.migrations' \\\n --schema '*' \\\n | sed -E 's/^\\\\(un)?restrict .*$/-- &/' >> /tmp/ankhorage-data.sql\n printf '\\nRESET ALL;\\n' >> /tmp/ankhorage-data.sql\n\n upload_file /tmp/ankhorage-roles.sql \"\\${prefix}/roles.sql\"\n upload_file /tmp/ankhorage-schema.sql \"\\${prefix}/schema.sql\"\n upload_file /tmp/ankhorage-data.sql \"\\${prefix}/data.sql\"\n printf '%s' \"$prefix\" > /tmp/ankhorage-latest\n upload_file /tmp/ankhorage-latest 'database/latest'\n cleanup\n touch /tmp/ankhorage-backup-ready\n}\nbackup_once\nwhile sleep \"$BACKUP_INTERVAL_SECONDS\"; do backup_once; done\n`;\n\n/*** Create the scheduled logical Postgres backup workload when backup intent is configured. */\nexport function createSupabaseDatabaseBackupWorkload(\n context: InfraExecutionContext,\n): InfraWorkloadSpec | undefined {\n const backup =\n context.desired.database?.provider === 'supabase' ? context.desired.database.backup : undefined;\n if (backup === undefined) return undefined;\n const s3 = createSupabaseS3Values(backup.target);\n const intervalHours = backup.intervalHours ?? DEFAULT_BACKUP_INTERVAL_HOURS;\n return {\n id: 'supabase-db-backup',\n artifact: { kind: 'image', image: SUPABASE_IMAGES.database },\n command: ['sh'],\n args: ['-ec', BACKUP_SCRIPT],\n environment: {\n PGHOST: literal('supabase-db'),\n PGPORT: literal('5432'),\n PGDATABASE: literal('postgres'),\n PGUSER: literal('postgres'),\n PGPASSWORD: bootstrapCredential('postgresPassword'),\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 BACKUP_INTERVAL_SECONDS: literal(String(intervalHours * 3600)),\n },\n health: {\n kind: 'command',\n command: ['test', '-f', '/tmp/ankhorage-backup-ready'],\n intervalSeconds: 30,\n timeoutSeconds: 5,\n failureThreshold: 10,\n },\n exposure: 'internal',\n replicas: 1,\n dependsOn: { [SUPABASE_DATA_RESTORE_WORKLOAD_ID]: 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 Supabase bootstrap credential reference. */\nfunction bootstrapCredential(key: string): InfraWorkloadScalarValue {\n return { kind: 'credential', reference: SUPABASE_BOOTSTRAP_CREDENTIAL, key };\n}\n"]}
|
package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseDataRestoreWorkload.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InfraExecutionContext, InfraWorkloadSpec } from '@ankhorage/contracts/infra';
|
|
2
|
+
/*** Create the post-migration data recovery workload for a database protected by S3 backups. */
|
|
3
|
+
export declare function createSupabaseDatabaseDataRestoreWorkload(context: InfraExecutionContext, ownsObjectStorage: boolean): InfraWorkloadSpec | undefined;
|
|
4
|
+
//# sourceMappingURL=createSupabaseDatabaseDataRestoreWorkload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseDatabaseDataRestoreWorkload.d.ts","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseDatabaseDataRestoreWorkload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EAErB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAyEpC,gGAAgG;AAChG,wBAAgB,yCAAyC,CACvD,OAAO,EAAE,qBAAqB,EAC9B,iBAAiB,EAAE,OAAO,GACzB,iBAAiB,GAAG,SAAS,CAmC/B"}
|
package/dist/features/platform-infrastructure/domain/createSupabaseDatabaseDataRestoreWorkload.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { SUPABASE_DATA_RESTORE_WORKLOAD_ID, SUPABASE_RECOVERY_SCHEMA, SUPABASE_RECOVERY_STATE_TABLE, } from '../constants/recovery';
|
|
2
|
+
import { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';
|
|
3
|
+
import { createSupabaseS3Values } from './createSupabaseS3Values';
|
|
4
|
+
const DATA_RESTORE_READY_FILE = '/tmp/ankhorage-data-restore-ready';
|
|
5
|
+
const RECOVERY_STATE_RELATION = `"${SUPABASE_RECOVERY_SCHEMA}"."${SUPABASE_RECOVERY_STATE_TABLE}"`;
|
|
6
|
+
const DATA_RESTORE_SCRIPT = `
|
|
7
|
+
set -eu
|
|
8
|
+
umask 077
|
|
9
|
+
ready='${DATA_RESTORE_READY_FILE}'
|
|
10
|
+
cleanup() {
|
|
11
|
+
rm -f /tmp/ankhorage-s3-curl.conf /tmp/ankhorage-data.sql /tmp/ankhorage-data-restore.sql
|
|
12
|
+
}
|
|
13
|
+
download_file() {
|
|
14
|
+
key="$1"
|
|
15
|
+
file="$2"
|
|
16
|
+
status="$(curl --silent --show-error --connect-timeout 2 --max-time 30 \
|
|
17
|
+
--retry 10 --retry-all-errors --retry-delay 2 \
|
|
18
|
+
--config /tmp/ankhorage-s3-curl.conf \
|
|
19
|
+
--aws-sigv4 "aws:amz:\${S3_REGION}:s3" --output "$file" --write-out '%{http_code}' \
|
|
20
|
+
"\${S3_URL_PREFIX}/$key" || true)"
|
|
21
|
+
if [ "$status" != '200' ]; then
|
|
22
|
+
echo "Database backup file $key failed to download with HTTP $status." >&2
|
|
23
|
+
return 1
|
|
24
|
+
fi
|
|
25
|
+
}
|
|
26
|
+
trap cleanup EXIT INT TERM
|
|
27
|
+
rm -f "$ready"
|
|
28
|
+
printf 'user = "%s:%s"\n' "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" > /tmp/ankhorage-s3-curl.conf
|
|
29
|
+
prefix="$(psql --set ON_ERROR_STOP=1 --dbname "$PGDATABASE" --tuples-only --no-align \
|
|
30
|
+
--command "SELECT backup_prefix FROM ${RECOVERY_STATE_RELATION} WHERE id = 'latest' AND NOT data_restored;")"
|
|
31
|
+
|
|
32
|
+
if [ -n "$prefix" ]; then
|
|
33
|
+
suffix="\${prefix#database/}"
|
|
34
|
+
case "$prefix:$suffix" in
|
|
35
|
+
database/*:*/*|database/*:*..*|database/:*)
|
|
36
|
+
echo 'Database recovery state contains an invalid backup pointer.' >&2
|
|
37
|
+
exit 1
|
|
38
|
+
;;
|
|
39
|
+
database/*:*) ;;
|
|
40
|
+
*)
|
|
41
|
+
echo 'Database recovery state contains an invalid backup pointer.' >&2
|
|
42
|
+
exit 1
|
|
43
|
+
;;
|
|
44
|
+
esac
|
|
45
|
+
|
|
46
|
+
echo "Restoring database data from backup set $prefix after managed schema migrations."
|
|
47
|
+
download_file "$prefix/data.sql" /tmp/ankhorage-data.sql
|
|
48
|
+
cat /tmp/ankhorage-data.sql > /tmp/ankhorage-data-restore.sql
|
|
49
|
+
cat >> /tmp/ankhorage-data-restore.sql <<'SQL'
|
|
50
|
+
UPDATE ${RECOVERY_STATE_RELATION}
|
|
51
|
+
SET data_restored = TRUE
|
|
52
|
+
WHERE id = 'latest';
|
|
53
|
+
SQL
|
|
54
|
+
psql --single-transaction --set ON_ERROR_STOP=1 --dbname "$PGDATABASE" \
|
|
55
|
+
--file /tmp/ankhorage-data-restore.sql
|
|
56
|
+
echo 'Database data restore completed.'
|
|
57
|
+
else
|
|
58
|
+
echo 'No pending database data restore exists.'
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
touch "$ready"
|
|
62
|
+
cleanup
|
|
63
|
+
trap - EXIT INT TERM
|
|
64
|
+
while :; do sleep 3600; done
|
|
65
|
+
`;
|
|
66
|
+
/*** Create the post-migration data recovery workload for a database protected by S3 backups. */
|
|
67
|
+
export function createSupabaseDatabaseDataRestoreWorkload(context, ownsObjectStorage) {
|
|
68
|
+
const backup = context.desired.database?.provider === 'supabase' ? context.desired.database.backup : undefined;
|
|
69
|
+
if (backup === undefined)
|
|
70
|
+
return undefined;
|
|
71
|
+
const s3 = createSupabaseS3Values(backup.target);
|
|
72
|
+
return {
|
|
73
|
+
id: SUPABASE_DATA_RESTORE_WORKLOAD_ID,
|
|
74
|
+
artifact: { kind: 'image', image: SUPABASE_IMAGES.database },
|
|
75
|
+
command: ['sh'],
|
|
76
|
+
args: ['-ec', DATA_RESTORE_SCRIPT],
|
|
77
|
+
environment: {
|
|
78
|
+
PGHOST: literal('supabase-db'),
|
|
79
|
+
PGPORT: literal('5432'),
|
|
80
|
+
PGDATABASE: literal('postgres'),
|
|
81
|
+
PGUSER: literal('postgres'),
|
|
82
|
+
PGPASSWORD: bootstrapCredential('postgresPassword'),
|
|
83
|
+
S3_REGION: s3.region,
|
|
84
|
+
S3_URL_PREFIX: s3.urlPrefix,
|
|
85
|
+
AWS_ACCESS_KEY_ID: s3.accessKeyId,
|
|
86
|
+
AWS_SECRET_ACCESS_KEY: s3.secretAccessKey,
|
|
87
|
+
},
|
|
88
|
+
health: {
|
|
89
|
+
kind: 'command',
|
|
90
|
+
command: ['test', '-f', DATA_RESTORE_READY_FILE],
|
|
91
|
+
intervalSeconds: 10,
|
|
92
|
+
timeoutSeconds: 5,
|
|
93
|
+
failureThreshold: 120,
|
|
94
|
+
},
|
|
95
|
+
exposure: 'internal',
|
|
96
|
+
replicas: 1,
|
|
97
|
+
dependsOn: {
|
|
98
|
+
'supabase-auth': true,
|
|
99
|
+
...(ownsObjectStorage ? { 'supabase-storage': true } : {}),
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/*** Create one literal workload value. */
|
|
104
|
+
function literal(value) {
|
|
105
|
+
return { kind: 'literal', value };
|
|
106
|
+
}
|
|
107
|
+
/*** Create one execution-only Supabase bootstrap credential reference. */
|
|
108
|
+
function bootstrapCredential(key) {
|
|
109
|
+
return { kind: 'credential', reference: SUPABASE_BOOTSTRAP_CREDENTIAL, key };
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=createSupabaseDatabaseDataRestoreWorkload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseDatabaseDataRestoreWorkload.js","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseDatabaseDataRestoreWorkload.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,iCAAiC,EACjC,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,uBAAuB,GAAG,mCAAmC,CAAC;AACpE,MAAM,uBAAuB,GAAG,IAAI,wBAAwB,MAAM,6BAA6B,GAAG,CAAC;AACnG,MAAM,mBAAmB,GAAG;;;SAGnB,uBAAuB;;;;;;;;;;;;;;;;;;;;;yCAqBS,uBAAuB;;;;;;;;;;;;;;;;;;;;SAoBvD,uBAAuB;;;;;;;;;;;;;;;CAe/B,CAAC;AAEF,gGAAgG;AAChG,MAAM,UAAU,yCAAyC,CACvD,OAA8B,EAC9B,iBAA0B;IAE1B,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,SAAS,CAAC;IAC3C,MAAM,EAAE,GAAG,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO;QACL,EAAE,EAAE,iCAAiC;QACrC,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,QAAQ,EAAE;QAC5D,OAAO,EAAE,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC;QAClC,WAAW,EAAE;YACX,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC;YAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC;YACvB,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC;YAC/B,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC;YAC3B,UAAU,EAAE,mBAAmB,CAAC,kBAAkB,CAAC;YACnD,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,MAAM,EAAE;YACN,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,uBAAuB,CAAC;YAChD,eAAe,EAAE,EAAE;YACnB,cAAc,EAAE,CAAC;YACjB,gBAAgB,EAAE,GAAG;SACtB;QACD,QAAQ,EAAE,UAAU;QACpB,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE;YACT,eAAe,EAAE,IAAI;YACrB,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC3D;KACF,CAAC;AACJ,CAAC;AAED,0CAA0C;AAC1C,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACpC,CAAC;AAED,0EAA0E;AAC1E,SAAS,mBAAmB,CAAC,GAAW;IACtC,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 {\n SUPABASE_DATA_RESTORE_WORKLOAD_ID,\n SUPABASE_RECOVERY_SCHEMA,\n SUPABASE_RECOVERY_STATE_TABLE,\n} from '../constants/recovery';\nimport { SUPABASE_BOOTSTRAP_CREDENTIAL, SUPABASE_IMAGES } from '../constants/supabase';\nimport { createSupabaseS3Values } from './createSupabaseS3Values';\n\nconst DATA_RESTORE_READY_FILE = '/tmp/ankhorage-data-restore-ready';\nconst RECOVERY_STATE_RELATION = `\"${SUPABASE_RECOVERY_SCHEMA}\".\"${SUPABASE_RECOVERY_STATE_TABLE}\"`;\nconst DATA_RESTORE_SCRIPT = `\nset -eu\numask 077\nready='${DATA_RESTORE_READY_FILE}'\ncleanup() {\n rm -f /tmp/ankhorage-s3-curl.conf /tmp/ankhorage-data.sql /tmp/ankhorage-data-restore.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}\ntrap cleanup EXIT INT TERM\nrm -f \"$ready\"\nprintf 'user = \"%s:%s\"\\n' \"$AWS_ACCESS_KEY_ID\" \"$AWS_SECRET_ACCESS_KEY\" > /tmp/ankhorage-s3-curl.conf\nprefix=\"$(psql --set ON_ERROR_STOP=1 --dbname \"$PGDATABASE\" --tuples-only --no-align \\\n --command \"SELECT backup_prefix FROM ${RECOVERY_STATE_RELATION} WHERE id = 'latest' AND NOT data_restored;\")\"\n\nif [ -n \"$prefix\" ]; then\n suffix=\"\\${prefix#database/}\"\n case \"$prefix:$suffix\" in\n database/*:*/*|database/*:*..*|database/:*)\n echo 'Database recovery state contains an invalid backup pointer.' >&2\n exit 1\n ;;\n database/*:*) ;;\n *)\n echo 'Database recovery state contains an invalid backup pointer.' >&2\n exit 1\n ;;\n esac\n\n echo \"Restoring database data from backup set $prefix after managed schema migrations.\"\n download_file \"$prefix/data.sql\" /tmp/ankhorage-data.sql\n cat /tmp/ankhorage-data.sql > /tmp/ankhorage-data-restore.sql\n cat >> /tmp/ankhorage-data-restore.sql <<'SQL'\nUPDATE ${RECOVERY_STATE_RELATION}\nSET data_restored = TRUE\nWHERE id = 'latest';\nSQL\n psql --single-transaction --set ON_ERROR_STOP=1 --dbname \"$PGDATABASE\" \\\n --file /tmp/ankhorage-data-restore.sql\n echo 'Database data restore completed.'\nelse\n echo 'No pending database data restore exists.'\nfi\n\ntouch \"$ready\"\ncleanup\ntrap - EXIT INT TERM\nwhile :; do sleep 3600; done\n`;\n\n/*** Create the post-migration data recovery workload for a database protected by S3 backups. */\nexport function createSupabaseDatabaseDataRestoreWorkload(\n context: InfraExecutionContext,\n ownsObjectStorage: boolean,\n): InfraWorkloadSpec | undefined {\n const backup =\n context.desired.database?.provider === 'supabase' ? context.desired.database.backup : undefined;\n if (backup === undefined) return undefined;\n const s3 = createSupabaseS3Values(backup.target);\n return {\n id: SUPABASE_DATA_RESTORE_WORKLOAD_ID,\n artifact: { kind: 'image', image: SUPABASE_IMAGES.database },\n command: ['sh'],\n args: ['-ec', DATA_RESTORE_SCRIPT],\n environment: {\n PGHOST: literal('supabase-db'),\n PGPORT: literal('5432'),\n PGDATABASE: literal('postgres'),\n PGUSER: literal('postgres'),\n PGPASSWORD: bootstrapCredential('postgresPassword'),\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 health: {\n kind: 'command',\n command: ['test', '-f', DATA_RESTORE_READY_FILE],\n intervalSeconds: 10,\n timeoutSeconds: 5,\n failureThreshold: 120,\n },\n exposure: 'internal',\n replicas: 1,\n dependsOn: {\n 'supabase-auth': true,\n ...(ownsObjectStorage ? { 'supabase-storage': true } : {}),\n },\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 Supabase bootstrap credential reference. */\nfunction bootstrapCredential(key: string): InfraWorkloadScalarValue {\n return { kind: 'credential', reference: SUPABASE_BOOTSTRAP_CREDENTIAL, key };\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InfraWorkloadSpec } from '@ankhorage/contracts/infra';
|
|
2
|
+
/*** Keep Postgres data and pgsodium configuration on independently retained runtime volumes. */
|
|
3
|
+
export declare function createSupabaseDatabasePersistence(prod: boolean): NonNullable<InfraWorkloadSpec['persistence']>;
|
|
4
|
+
//# sourceMappingURL=createSupabaseDatabasePersistence.d.ts.map
|
package/dist/features/platform-infrastructure/domain/createSupabaseDatabasePersistence.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseDatabasePersistence.d.ts","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseDatabasePersistence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,gGAAgG;AAChG,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,OAAO,GACZ,WAAW,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAgB/C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*** Keep Postgres data and pgsodium configuration on independently retained runtime volumes. */
|
|
2
|
+
export function createSupabaseDatabasePersistence(prod) {
|
|
3
|
+
return {
|
|
4
|
+
data: {
|
|
5
|
+
id: 'data',
|
|
6
|
+
mountPath: '/var/lib/postgresql/data',
|
|
7
|
+
sizeGiB: prod ? 20 : 5,
|
|
8
|
+
retention: prod ? 'retain' : 'delete-on-destroy',
|
|
9
|
+
},
|
|
10
|
+
config: {
|
|
11
|
+
id: 'config',
|
|
12
|
+
mountPath: '/etc/postgresql-custom',
|
|
13
|
+
sizeGiB: 1,
|
|
14
|
+
seed: 'image',
|
|
15
|
+
retention: prod ? 'retain' : 'delete-on-destroy',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=createSupabaseDatabasePersistence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSupabaseDatabasePersistence.js","sourceRoot":"","sources":["../../../../src/features/platform-infrastructure/domain/createSupabaseDatabasePersistence.ts"],"names":[],"mappings":"AAEA,gGAAgG;AAChG,MAAM,UAAU,iCAAiC,CAC/C,IAAa;IAEb,OAAO;QACL,IAAI,EAAE;YACJ,EAAE,EAAE,MAAM;YACV,SAAS,EAAE,0BAA0B;YACrC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACtB,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,mBAAmB;SACjD;QACD,MAAM,EAAE;YACN,EAAE,EAAE,QAAQ;YACZ,SAAS,EAAE,wBAAwB;YACnC,OAAO,EAAE,CAAC;YACV,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,mBAAmB;SACjD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { InfraWorkloadSpec } from '@ankhorage/contracts/infra';\n\n/*** Keep Postgres data and pgsodium configuration on independently retained runtime volumes. */\nexport function createSupabaseDatabasePersistence(\n prod: boolean,\n): NonNullable<InfraWorkloadSpec['persistence']> {\n return {\n data: {\n id: 'data',\n mountPath: '/var/lib/postgresql/data',\n sizeGiB: prod ? 20 : 5,\n retention: prod ? 'retain' : 'delete-on-destroy',\n },\n config: {\n id: 'config',\n mountPath: '/etc/postgresql-custom',\n sizeGiB: 1,\n seed: 'image',\n retention: prod ? 'retain' : 'delete-on-destroy',\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { InfraExecutionContext, InfraWorkloadSpec, InfraWorkloadValue } from '@ankhorage/contracts/infra';
|
|
2
|
+
/*** Project first-boot restore state for a database protected by scheduled S3 backups. */
|
|
3
|
+
export declare function createSupabaseDatabaseRestore(context: InfraExecutionContext): SupabaseDatabaseRestoreProjection;
|
|
4
|
+
interface SupabaseDatabaseRestoreProjection {
|
|
5
|
+
readonly environment: Readonly<Record<string, InfraWorkloadValue>>;
|
|
6
|
+
readonly files: NonNullable<InfraWorkloadSpec['files']>;
|
|
7
|
+
readonly entrypoint?: {
|
|
8
|
+
readonly command: readonly string[];
|
|
9
|
+
readonly args: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=createSupabaseDatabaseRestore.d.ts.map
|