@ericminassian/platform-engine 0.4.1 → 0.5.0
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/dist/clients.d.ts +0 -4
- package/dist/clients.js +1 -14
- package/dist/clients.js.map +1 -1
- package/dist/compat.d.ts +9 -21
- package/dist/compat.js +6 -26
- package/dist/compat.js.map +1 -1
- package/dist/drivers/cognito.d.ts +18 -0
- package/dist/drivers/cognito.js +58 -17
- package/dist/drivers/cognito.js.map +1 -1
- package/dist/drivers/index.d.ts +0 -2
- package/dist/drivers/index.js +0 -2
- package/dist/drivers/index.js.map +1 -1
- package/dist/drivers/logs.d.ts +11 -0
- package/dist/drivers/logs.js +15 -1
- package/dist/drivers/logs.js.map +1 -1
- package/dist/drivers/scheduler.d.ts +0 -21
- package/dist/drivers/scheduler.js +0 -43
- package/dist/drivers/scheduler.js.map +1 -1
- package/dist/index.d.ts +2 -81
- package/dist/index.js +0 -5
- package/dist/index.js.map +1 -1
- package/dist/local.js +2 -140
- package/dist/local.js.map +1 -1
- package/dist/login-branding.d.ts +27 -0
- package/dist/login-branding.js +329 -0
- package/dist/login-branding.js.map +1 -0
- package/dist/login-glyphs.d.ts +12 -0
- package/dist/login-glyphs.js +903 -0
- package/dist/login-glyphs.js.map +1 -0
- package/dist/policy.d.ts +2 -26
- package/dist/policy.js +2 -107
- package/dist/policy.js.map +1 -1
- package/dist/stage.d.ts +1 -2
- package/dist/stage.js +16 -86
- package/dist/stage.js.map +1 -1
- package/dist/util.d.ts +0 -22
- package/dist/util.js +0 -16
- package/dist/util.js.map +1 -1
- package/package.json +10 -7
- package/src/clients.ts +1 -15
- package/src/compat.ts +9 -32
- package/src/drivers/cognito.ts +79 -14
- package/src/drivers/index.ts +0 -2
- package/src/drivers/logs.ts +21 -0
- package/src/drivers/scheduler.ts +0 -69
- package/src/index.ts +3 -78
- package/src/local.ts +2 -152
- package/src/login-branding.ts +407 -0
- package/src/login-glyphs.ts +911 -0
- package/src/policy.ts +2 -132
- package/src/stage.ts +16 -101
- package/src/util.ts +0 -34
- package/dist/drivers/ecr.d.ts +0 -109
- package/dist/drivers/ecr.js +0 -303
- package/dist/drivers/ecr.js.map +0 -1
- package/dist/drivers/ecs.d.ts +0 -163
- package/dist/drivers/ecs.js +0 -447
- package/dist/drivers/ecs.js.map +0 -1
- package/dist/images.d.ts +0 -104
- package/dist/images.js +0 -182
- package/dist/images.js.map +0 -1
- package/dist/services.d.ts +0 -155
- package/dist/services.js +0 -464
- package/dist/services.js.map +0 -1
- package/src/drivers/ecr.ts +0 -457
- package/src/drivers/ecs.ts +0 -661
- package/src/images.ts +0 -254
- package/src/services.ts +0 -663
package/src/policy.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type EmailRuntimeConfig,
|
|
3
3
|
emailFromAddress,
|
|
4
|
-
type ContainersRuntimeConfig,
|
|
5
4
|
IAM_APP_PATH,
|
|
6
5
|
names,
|
|
7
6
|
ownFunctionHandlers,
|
|
@@ -42,14 +41,11 @@ export function emailIdentityArn(region: string, accountId: string, identity: st
|
|
|
42
41
|
return `arn:aws:ses:${region}:${accountId}:identity/${identity}`;
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
/**
|
|
46
|
-
* Trust for per-stage roles: the worker and Web Function (Lambda), schedules
|
|
47
|
-
* (Scheduler) and long-running services (ECS tasks).
|
|
48
|
-
*/
|
|
44
|
+
/** Trust for per-stage roles: the worker and Web Function (Lambda) and schedules (Scheduler). */
|
|
49
45
|
export function stageTrustPolicy(): PolicyDocument {
|
|
50
46
|
return policy({
|
|
51
47
|
Effect: 'Allow',
|
|
52
|
-
Principal: { Service: ['lambda.amazonaws.com', 'scheduler.amazonaws.com'
|
|
48
|
+
Principal: { Service: ['lambda.amazonaws.com', 'scheduler.amazonaws.com'] },
|
|
53
49
|
Action: 'sts:AssumeRole',
|
|
54
50
|
});
|
|
55
51
|
}
|
|
@@ -396,10 +392,6 @@ export function controlPlanePolicy(input: {
|
|
|
396
392
|
> & {
|
|
397
393
|
realtime?: Pick<NonNullable<PlatformRuntimeConfig['realtime']>, 'apiId'>;
|
|
398
394
|
email?: Pick<EmailRuntimeConfig, 'identityArn'>;
|
|
399
|
-
containers?: Pick<
|
|
400
|
-
ContainersRuntimeConfig,
|
|
401
|
-
'cluster' | 'repository' | 'executionRoleArn' | 'schedulerRoleArn'
|
|
402
|
-
>;
|
|
403
395
|
};
|
|
404
396
|
}): PolicyDocument {
|
|
405
397
|
const { region, accountId: acct, runtime } = input;
|
|
@@ -661,79 +653,6 @@ export function controlPlanePolicy(input: {
|
|
|
661
653
|
},
|
|
662
654
|
);
|
|
663
655
|
}
|
|
664
|
-
if (runtime.containers) {
|
|
665
|
-
const { cluster, repository, executionRoleArn, schedulerRoleArn } = runtime.containers;
|
|
666
|
-
statements.push(
|
|
667
|
-
{
|
|
668
|
-
// Stage services (deploy, destroy, start/stop/restart).
|
|
669
|
-
Sid: 'ContainerServices',
|
|
670
|
-
Effect: 'Allow',
|
|
671
|
-
Action: [
|
|
672
|
-
'ecs:CreateService',
|
|
673
|
-
'ecs:UpdateService',
|
|
674
|
-
'ecs:DeleteService',
|
|
675
|
-
'ecs:DescribeServices',
|
|
676
|
-
'ecs:TagResource',
|
|
677
|
-
'ecs:UntagResource',
|
|
678
|
-
'ecs:ListTagsForResource',
|
|
679
|
-
],
|
|
680
|
-
Resource: `arn:aws:ecs:${region}:${acct}:service/${cluster}/*`,
|
|
681
|
-
},
|
|
682
|
-
{
|
|
683
|
-
// Task definitions, and the cluster's tasks and service listing, take no narrower resource.
|
|
684
|
-
Sid: 'ContainerTasks',
|
|
685
|
-
Effect: 'Allow',
|
|
686
|
-
Action: [
|
|
687
|
-
'ecs:RegisterTaskDefinition',
|
|
688
|
-
'ecs:DeregisterTaskDefinition',
|
|
689
|
-
'ecs:DeleteTaskDefinitions',
|
|
690
|
-
'ecs:DescribeTaskDefinition',
|
|
691
|
-
'ecs:ListTaskDefinitions',
|
|
692
|
-
'ecs:ListTaskDefinitionFamilies',
|
|
693
|
-
'ecs:TagResource',
|
|
694
|
-
'ecs:ListTagsForResource',
|
|
695
|
-
'ecs:ListServices',
|
|
696
|
-
'ecs:ListTasks',
|
|
697
|
-
'ecs:DescribeTasks',
|
|
698
|
-
'ecs:StopTask',
|
|
699
|
-
],
|
|
700
|
-
Resource: '*',
|
|
701
|
-
},
|
|
702
|
-
{
|
|
703
|
-
// Images are built through the registry API (no Docker), so pushes are IAM calls.
|
|
704
|
-
Sid: 'ContainerImages',
|
|
705
|
-
Effect: 'Allow',
|
|
706
|
-
Action: [
|
|
707
|
-
'ecr:BatchCheckLayerAvailability',
|
|
708
|
-
'ecr:InitiateLayerUpload',
|
|
709
|
-
'ecr:UploadLayerPart',
|
|
710
|
-
'ecr:CompleteLayerUpload',
|
|
711
|
-
'ecr:PutImage',
|
|
712
|
-
'ecr:BatchGetImage',
|
|
713
|
-
'ecr:GetDownloadUrlForLayer',
|
|
714
|
-
'ecr:DescribeImages',
|
|
715
|
-
'ecr:ListImages',
|
|
716
|
-
'ecr:BatchDeleteImage',
|
|
717
|
-
],
|
|
718
|
-
Resource: `arn:aws:ecr:${region}:${acct}:repository/${repository}`,
|
|
719
|
-
},
|
|
720
|
-
{
|
|
721
|
-
Sid: 'ContainerRoles',
|
|
722
|
-
Effect: 'Allow',
|
|
723
|
-
Action: 'iam:PassRole',
|
|
724
|
-
Resource: [executionRoleArn, schedulerRoleArn],
|
|
725
|
-
},
|
|
726
|
-
{
|
|
727
|
-
// ECS manages task network interfaces through its service-linked role, which it creates on
|
|
728
|
-
// first use. A young account doesn't have it yet, so the first CreateService makes it.
|
|
729
|
-
Sid: 'ContainerServiceLinkedRole',
|
|
730
|
-
Effect: 'Allow',
|
|
731
|
-
Action: 'iam:CreateServiceLinkedRole',
|
|
732
|
-
Resource: `arn:aws:iam::${acct}:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS`,
|
|
733
|
-
Condition: { StringEquals: { 'iam:AWSServiceName': 'ecs.amazonaws.com' } },
|
|
734
|
-
},
|
|
735
|
-
);
|
|
736
|
-
}
|
|
737
656
|
if (runtime.alertsTopicArn) {
|
|
738
657
|
statements.push({
|
|
739
658
|
Sid: 'Alerts',
|
|
@@ -745,55 +664,6 @@ export function controlPlanePolicy(input: {
|
|
|
745
664
|
return policy(...statements);
|
|
746
665
|
}
|
|
747
666
|
|
|
748
|
-
/**
|
|
749
|
-
* What ECS needs to start a platform container: pull its image and ship its
|
|
750
|
-
* logs to the stage's service log groups (created by the engine). The app's
|
|
751
|
-
* own code runs as the stage role, never as this one.
|
|
752
|
-
*/
|
|
753
|
-
export function containerExecutionPolicy(input: {
|
|
754
|
-
region: string;
|
|
755
|
-
accountId: string;
|
|
756
|
-
repository: string;
|
|
757
|
-
}): PolicyDocument {
|
|
758
|
-
const { region, accountId: acct } = input;
|
|
759
|
-
return policy(
|
|
760
|
-
{
|
|
761
|
-
Sid: 'PullImages',
|
|
762
|
-
Effect: 'Allow',
|
|
763
|
-
Action: ['ecr:BatchGetImage', 'ecr:GetDownloadUrlForLayer', 'ecr:BatchCheckLayerAvailability'],
|
|
764
|
-
Resource: `arn:aws:ecr:${region}:${acct}:repository/${input.repository}`,
|
|
765
|
-
},
|
|
766
|
-
{ Sid: 'RegistryAuth', Effect: 'Allow', Action: 'ecr:GetAuthorizationToken', Resource: '*' },
|
|
767
|
-
{
|
|
768
|
-
Sid: 'ContainerLogs',
|
|
769
|
-
Effect: 'Allow',
|
|
770
|
-
Action: ['logs:CreateLogStream', 'logs:PutLogEvents'],
|
|
771
|
-
Resource: [
|
|
772
|
-
`arn:aws:logs:${region}:${acct}:log-group:/platform/apps/*/*/services/*`,
|
|
773
|
-
`arn:aws:logs:${region}:${acct}:log-group:/platform/apps/*/*/services/*:log-stream:*`,
|
|
774
|
-
],
|
|
775
|
-
},
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
/**
|
|
780
|
-
* Assumed by EventBridge Scheduler for the one-shot schedules that stop a
|
|
781
|
-
* preview's services. It can only change a stage service's desired count
|
|
782
|
-
* (the schedule's input is fixed by the engine); app code never holds it.
|
|
783
|
-
*/
|
|
784
|
-
export function containerSchedulerPolicy(input: {
|
|
785
|
-
region: string;
|
|
786
|
-
accountId: string;
|
|
787
|
-
cluster: string;
|
|
788
|
-
}): PolicyDocument {
|
|
789
|
-
return policy({
|
|
790
|
-
Sid: 'ScaleStageServices',
|
|
791
|
-
Effect: 'Allow',
|
|
792
|
-
Action: 'ecs:UpdateService',
|
|
793
|
-
Resource: `arn:aws:ecs:${input.region}:${input.accountId}:service/${input.cluster}/*--*`,
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
|
|
797
667
|
export function serviceTrustPolicy(...services: string[]): PolicyDocument {
|
|
798
668
|
return policy({ Effect: 'Allow', Principal: { Service: services }, Action: 'sts:AssumeRole' });
|
|
799
669
|
}
|
package/src/stage.ts
CHANGED
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
findEventApi,
|
|
50
50
|
getChannelNamespace,
|
|
51
51
|
} from './drivers/appsync.ts';
|
|
52
|
-
import { deleteUserPoolClient, ensureUserPoolClient } from './drivers/cognito.ts';
|
|
52
|
+
import { deleteUserPoolClient, ensureLoginBranding, ensureUserPoolClient } from './drivers/cognito.ts';
|
|
53
53
|
import { deleteTable, describeTable, ensureTable, stageTableSpec } from './drivers/dynamodb.ts';
|
|
54
54
|
import { deleteEventBus, deleteRule, ensureEventBus, ensureRule, listRules } from './drivers/events.ts';
|
|
55
55
|
import { deleteRole, ensureRole } from './drivers/iam.ts';
|
|
@@ -85,7 +85,6 @@ import {
|
|
|
85
85
|
import {
|
|
86
86
|
deleteSchedule,
|
|
87
87
|
deleteScheduleGroup,
|
|
88
|
-
deleteScheduleGroupIfEmpty,
|
|
89
88
|
ensureSchedule,
|
|
90
89
|
ensureScheduleGroup,
|
|
91
90
|
listSchedules,
|
|
@@ -124,18 +123,8 @@ import type {
|
|
|
124
123
|
ResourceRef,
|
|
125
124
|
RollbackStageInput,
|
|
126
125
|
} from './index.ts';
|
|
126
|
+
import { loginBranding } from './login-branding.ts';
|
|
127
127
|
import { configurationSetArn, stageRolePolicy, stageTrustPolicy } from './policy.ts';
|
|
128
|
-
import {
|
|
129
|
-
applyServicesRollback,
|
|
130
|
-
awaitServiceRollouts,
|
|
131
|
-
destroyServices,
|
|
132
|
-
listServiceResources,
|
|
133
|
-
planServicesRollback,
|
|
134
|
-
pruneServices,
|
|
135
|
-
type ServiceRollout,
|
|
136
|
-
type ServicesRollback,
|
|
137
|
-
startServices,
|
|
138
|
-
} from './services.ts';
|
|
139
128
|
import { type EngineContext, ignoreNotFound, stageTags } from './util.ts';
|
|
140
129
|
|
|
141
130
|
/**
|
|
@@ -144,14 +133,6 @@ import { type EngineContext, ignoreNotFound, stageTags } from './util.ts';
|
|
|
144
133
|
*/
|
|
145
134
|
const DEPLOYMENTS_KEPT = 3;
|
|
146
135
|
|
|
147
|
-
/**
|
|
148
|
-
* Crons, jobs' retries and delayed sends, and preview stop schedules share the
|
|
149
|
-
* stage's schedule group. Cron keys start with a letter and can't contain
|
|
150
|
-
* `--`; a job's schedule starts with `_` and a service's stop schedule is
|
|
151
|
-
* `<key>--stop`.
|
|
152
|
-
*/
|
|
153
|
-
const isCronSchedule = (name: string) => !name.includes('--') && !isJobSchedule(name);
|
|
154
|
-
|
|
155
136
|
/**
|
|
156
137
|
* Public host of a stage. Under `plat dev` the `local` stage is simply
|
|
157
138
|
* `<app>.localhost`; everything else follows `stageHost`.
|
|
@@ -168,8 +149,7 @@ function statementId(prefix: string, name: string): string {
|
|
|
168
149
|
/**
|
|
169
150
|
* Reconcile one stage with its manifest, then flip the route. Ordering keeps
|
|
170
151
|
* the old deployment serving until everything for the new one is ready:
|
|
171
|
-
* data/messaging → role → worker →
|
|
172
|
-
* build → services (running) → route (last) → GC.
|
|
152
|
+
* data/messaging → role → worker → static → server build → route (last) → GC.
|
|
173
153
|
*/
|
|
174
154
|
export async function deployStage(ctx: EngineContext, input: DeployStageInput): Promise<DeployStageResult> {
|
|
175
155
|
const { manifest: m, stage, platform, deploymentId } = input;
|
|
@@ -187,8 +167,6 @@ export async function deployStage(ctx: EngineContext, input: DeployStageInput):
|
|
|
187
167
|
const retention = input.logRetentionDays ?? (prod ? 30 : 7);
|
|
188
168
|
const hasWeb = Boolean(m.web?.server) && webMode === 'function';
|
|
189
169
|
const hasWorker = Boolean(m.worker);
|
|
190
|
-
const serviceKeys = Object.keys(m.services);
|
|
191
|
-
const servicesOnEcs = (input.servicesMode ?? 'ecs') === 'ecs';
|
|
192
170
|
const resources: ResourceRef[] = [];
|
|
193
171
|
const workerName = names.workerFunction(app, stage);
|
|
194
172
|
const servedStores = publicStores(m);
|
|
@@ -205,14 +183,6 @@ export async function deployStage(ctx: EngineContext, input: DeployStageInput):
|
|
|
205
183
|
throw new Error(
|
|
206
184
|
"plat.config.ts declares email, but this platform has no mail domain yet (its foundation predates it): deploy the platform's foundation first",
|
|
207
185
|
);
|
|
208
|
-
if (serviceKeys.length && servicesOnEcs) {
|
|
209
|
-
if (!platform.containers)
|
|
210
|
-
throw new Error(
|
|
211
|
-
"plat.config.ts declares services, but this platform has no container compute yet (its foundation predates it): deploy the platform's foundation first",
|
|
212
|
-
);
|
|
213
|
-
if (!input.artifacts.services)
|
|
214
|
-
throw new Error('manifest declares services but no services artifact was provided');
|
|
215
|
-
}
|
|
216
186
|
|
|
217
187
|
ctx.log('info', `deploying ${app}/${stage} (${deploymentId})`);
|
|
218
188
|
|
|
@@ -238,12 +208,6 @@ export async function deployStage(ctx: EngineContext, input: DeployStageInput):
|
|
|
238
208
|
});
|
|
239
209
|
}
|
|
240
210
|
if (hasWorker) await ensureLogGroup(ctx, { name: workerLogGroup, retentionDays: retention, tags });
|
|
241
|
-
for (const key of serviceKeys)
|
|
242
|
-
await ensureLogGroup(ctx, {
|
|
243
|
-
name: names.serviceLogGroup(app, stage, key),
|
|
244
|
-
retentionDays: retention,
|
|
245
|
-
tags,
|
|
246
|
-
});
|
|
247
211
|
|
|
248
212
|
// 2. Data.
|
|
249
213
|
let table: string | undefined;
|
|
@@ -301,6 +265,13 @@ export async function deployStage(ctx: EngineContext, input: DeployStageInput):
|
|
|
301
265
|
callbackUrls: [`${url}${AUTH_ROUTES.callback}`],
|
|
302
266
|
logoutUrls: [`${url}/`],
|
|
303
267
|
});
|
|
268
|
+
if (ctx.target === 'aws')
|
|
269
|
+
await ensureLoginBranding(ctx, {
|
|
270
|
+
userPoolId: platform.userPoolId,
|
|
271
|
+
clientId,
|
|
272
|
+
name: names.userPoolClient(app, stage),
|
|
273
|
+
branding: loginBranding({ app, domain: platform.domain }),
|
|
274
|
+
});
|
|
304
275
|
auth = {
|
|
305
276
|
mode: platform.target === 'emulator' ? 'local' : 'cognito',
|
|
306
277
|
userPoolId: platform.userPoolId,
|
|
@@ -480,27 +451,6 @@ export async function deployStage(ctx: EngineContext, input: DeployStageInput):
|
|
|
480
451
|
}
|
|
481
452
|
await retireLegacyQueues(ctx, { app, stage, legacy, deadLetters });
|
|
482
453
|
|
|
483
|
-
// 9b. Services: images, task definitions and ECS services. Their rollouts run while the static
|
|
484
|
-
// files and the web revision go up, and must finish before the route flips.
|
|
485
|
-
let services: DeployStageResult['services'];
|
|
486
|
-
let rollouts: ServiceRollout[] = [];
|
|
487
|
-
if (servicesOnEcs && serviceKeys.length && platform.containers && input.artifacts.services) {
|
|
488
|
-
const started = await startServices(ctx, {
|
|
489
|
-
app,
|
|
490
|
-
stage,
|
|
491
|
-
deploymentId,
|
|
492
|
-
services: m.services,
|
|
493
|
-
containers: platform.containers,
|
|
494
|
-
region,
|
|
495
|
-
roleArn,
|
|
496
|
-
env,
|
|
497
|
-
tags,
|
|
498
|
-
artifact: input.artifacts.services,
|
|
499
|
-
resources,
|
|
500
|
-
});
|
|
501
|
-
services = started.deployed;
|
|
502
|
-
rollouts = started.rollouts;
|
|
503
|
-
}
|
|
504
454
|
// 10. Static files (new prefix per deployment; the old one keeps serving until the route flips).
|
|
505
455
|
let staticPrefix: string | undefined;
|
|
506
456
|
if (input.artifacts.static) {
|
|
@@ -585,10 +535,6 @@ export async function deployStage(ctx: EngineContext, input: DeployStageInput):
|
|
|
585
535
|
? { o: requestFunction.urlDomain, c: 'r' as const, k: await originSecret(stageKey) }
|
|
586
536
|
: undefined;
|
|
587
537
|
|
|
588
|
-
// 11b. Every service that should run is running (a failed rollout fails the deploy here).
|
|
589
|
-
if (platform.containers && rollouts.length)
|
|
590
|
-
await awaitServiceRollouts(ctx, { cluster: platform.containers.cluster, rollouts });
|
|
591
|
-
|
|
592
538
|
// 12. Route flip — the only step that changes what users see. A stage with public stores is
|
|
593
539
|
// routed even without web, so its files have a host.
|
|
594
540
|
let route: RouteRecord | undefined;
|
|
@@ -632,23 +578,6 @@ export async function deployStage(ctx: EngineContext, input: DeployStageInput):
|
|
|
632
578
|
}
|
|
633
579
|
}
|
|
634
580
|
|
|
635
|
-
// 13b. Services removed from the manifest, and old builds of the rest. Kept: the newest few
|
|
636
|
-
// deployments' builds, the one each service ran before this deploy and the previously live one
|
|
637
|
-
// (rollback targets).
|
|
638
|
-
if (servicesOnEcs && platform.containers) {
|
|
639
|
-
await pruneServices(ctx, {
|
|
640
|
-
app,
|
|
641
|
-
stage,
|
|
642
|
-
services: m.services,
|
|
643
|
-
containers: platform.containers,
|
|
644
|
-
keep: [deploymentId, liveRoute?.d],
|
|
645
|
-
keepTaskDefinitions: rollouts.flatMap((r) => r.previousTaskDefinition ?? []),
|
|
646
|
-
kept: DEPLOYMENTS_KEPT,
|
|
647
|
-
});
|
|
648
|
-
// The group holds crons and jobs' retries and delayed sends while there's a worker.
|
|
649
|
-
if (!hasWorker) await deleteScheduleGroupIfEmpty(ctx, names.scheduleGroup(app, stage));
|
|
650
|
-
}
|
|
651
|
-
|
|
652
581
|
// 14. Realtime removed from the manifest: the route no longer advertises it, so the namespace
|
|
653
582
|
// can go (open connections to it are dropped by AppSync).
|
|
654
583
|
if (!m.realtime && platform.realtime) {
|
|
@@ -665,7 +594,6 @@ export async function deployStage(ctx: EngineContext, input: DeployStageInput):
|
|
|
665
594
|
...(webFunction ? { webFunction } : {}),
|
|
666
595
|
...(requestFunction ? { requestFunction } : {}),
|
|
667
596
|
...(workerFunction ? { workerFunction } : {}),
|
|
668
|
-
...(services ? { services } : {}),
|
|
669
597
|
resources,
|
|
670
598
|
};
|
|
671
599
|
}
|
|
@@ -904,7 +832,7 @@ async function reconcileWorkerTriggers(
|
|
|
904
832
|
p.resources.push({ type: 'schedule', name: `${group}/${key}` });
|
|
905
833
|
}
|
|
906
834
|
for (const s of await listSchedules(ctx, group))
|
|
907
|
-
if (
|
|
835
|
+
if (!isJobSchedule(s) && !cronKeys.includes(s)) await deleteSchedule(ctx, group, s);
|
|
908
836
|
|
|
909
837
|
// Nothing triggers these any more.
|
|
910
838
|
for (const fn of stale) await deleteWorkerFunction(ctx, fn.name);
|
|
@@ -912,14 +840,10 @@ async function reconcileWorkerTriggers(
|
|
|
912
840
|
|
|
913
841
|
/**
|
|
914
842
|
* The manifest no longer has a worker: remove its functions, everything that
|
|
915
|
-
* targets them, and jobs waiting for them.
|
|
916
|
-
* with them the group).
|
|
843
|
+
* targets them, and jobs waiting for them.
|
|
917
844
|
*/
|
|
918
845
|
async function removeWorker(ctx: EngineContext, app: string, stage: string): Promise<void> {
|
|
919
|
-
|
|
920
|
-
const schedules = await listSchedules(ctx, group);
|
|
921
|
-
for (const s of schedules) if (isCronSchedule(s) || isJobSchedule(s)) await deleteSchedule(ctx, group, s);
|
|
922
|
-
await deleteScheduleGroupIfEmpty(ctx, group);
|
|
846
|
+
await deleteScheduleGroup(ctx, names.scheduleGroup(app, stage));
|
|
923
847
|
const bus = names.eventBus(app, stage);
|
|
924
848
|
for (const rule of await listRules(ctx, bus, `${names.base(app, stage)}--`))
|
|
925
849
|
await deleteRule(ctx, bus, rule);
|
|
@@ -1094,13 +1018,9 @@ export function staleStaticPrefixes(prefixes: string[], keep: Array<string | und
|
|
|
1094
1018
|
/**
|
|
1095
1019
|
* Rollback targets lose their files and builds to garbage collection after
|
|
1096
1020
|
* enough deploys. Check before changing anything, so a stage is never
|
|
1097
|
-
* pointed at a deployment that can no longer serve.
|
|
1098
|
-
* services go back to.
|
|
1021
|
+
* pointed at a deployment that can no longer serve.
|
|
1099
1022
|
*/
|
|
1100
|
-
async function assertCanRollBack(
|
|
1101
|
-
ctx: EngineContext,
|
|
1102
|
-
input: RollbackStageInput,
|
|
1103
|
-
): Promise<ServicesRollback | undefined> {
|
|
1023
|
+
async function assertCanRollBack(ctx: EngineContext, input: RollbackStageInput): Promise<void> {
|
|
1104
1024
|
const { app, stage, platform, route } = input;
|
|
1105
1025
|
const gone = (what: string) => new Error(`deployment ${route.d} can't be rolled back to: ${what}`);
|
|
1106
1026
|
if (route.s && !(await hasObjects(ctx, platform.sitesBucket, `${route.s}/`))) {
|
|
@@ -1116,7 +1036,6 @@ async function assertCanRollBack(
|
|
|
1116
1036
|
if (!state) throw gone('its server revision has been cleaned up');
|
|
1117
1037
|
if (state !== 'Active') throw gone(`its server revision is ${state}`);
|
|
1118
1038
|
}
|
|
1119
|
-
return planServicesRollback(ctx, input, gone);
|
|
1120
1039
|
}
|
|
1121
1040
|
|
|
1122
1041
|
/**
|
|
@@ -1129,8 +1048,7 @@ async function assertCanRollBack(
|
|
|
1129
1048
|
*/
|
|
1130
1049
|
export async function rollbackStage(ctx: EngineContext, input: RollbackStageInput): Promise<RouteRecord> {
|
|
1131
1050
|
const { app, stage, platform } = input;
|
|
1132
|
-
|
|
1133
|
-
await applyServicesRollback(ctx, services);
|
|
1051
|
+
await assertCanRollBack(ctx, input);
|
|
1134
1052
|
const host = hostFor(platform, app, stage);
|
|
1135
1053
|
let route = input.route;
|
|
1136
1054
|
const live = route.o && platform.kvsArn ? await getRoute(ctx, platform.kvsArn, host) : undefined;
|
|
@@ -1171,8 +1089,6 @@ export async function destroyStage(ctx: EngineContext, input: DestroyStageInput)
|
|
|
1171
1089
|
await deleteWebFunction(ctx, names.webFunction(app, stage));
|
|
1172
1090
|
// Its versions, aliases and function URLs go with it.
|
|
1173
1091
|
await deleteFunction(ctx, names.requestFunction(app, stage));
|
|
1174
|
-
if (platform.containers) await destroyServices(ctx, { app, stage, containers: platform.containers });
|
|
1175
|
-
await deleteScheduleGroup(ctx, names.scheduleGroup(app, stage));
|
|
1176
1092
|
for (const q of await listQueues(ctx, `${names.base(app, stage)}--`)) await deleteQueue(ctx, q.name);
|
|
1177
1093
|
await deleteEventBus(ctx, names.eventBus(app, stage));
|
|
1178
1094
|
if (platform.realtime)
|
|
@@ -1248,6 +1164,5 @@ export async function listStageResources(
|
|
|
1248
1164
|
name: tenantName,
|
|
1249
1165
|
arn: configurationSetArn(ctx.region, await ctx.accountId(), tenantName),
|
|
1250
1166
|
});
|
|
1251
|
-
out.push(...(await listServiceResources(ctx, app, stage)));
|
|
1252
1167
|
return out;
|
|
1253
1168
|
}
|
package/src/util.ts
CHANGED
|
@@ -41,10 +41,6 @@ const NOT_FOUND = new Set([
|
|
|
41
41
|
'NoSuchCachePolicy',
|
|
42
42
|
'NoSuchDistribution',
|
|
43
43
|
'EntityNotFound',
|
|
44
|
-
'ServiceNotFoundException',
|
|
45
|
-
'ClusterNotFoundException',
|
|
46
|
-
'RepositoryNotFoundException',
|
|
47
|
-
'ImageNotFoundException',
|
|
48
44
|
]);
|
|
49
45
|
|
|
50
46
|
export function isNotFound(e: unknown): boolean {
|
|
@@ -121,36 +117,6 @@ export async function mapLimit<T, R>(
|
|
|
121
117
|
return out;
|
|
122
118
|
}
|
|
123
119
|
|
|
124
|
-
export interface RawRequest {
|
|
125
|
-
method: string;
|
|
126
|
-
protocol: string;
|
|
127
|
-
hostname: string;
|
|
128
|
-
port?: number;
|
|
129
|
-
path: string;
|
|
130
|
-
query?: Record<string, string>;
|
|
131
|
-
headers: Record<string, string>;
|
|
132
|
-
body?: string;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Send a request outside the SDK's operations through a client's own HTTP
|
|
137
|
-
* handler, so it gets the same TLS setup (the emulator's CA) as the client.
|
|
138
|
-
*/
|
|
139
|
-
export async function sendRaw(
|
|
140
|
-
client: { config: { requestHandler: unknown } },
|
|
141
|
-
request: RawRequest,
|
|
142
|
-
): Promise<{ statusCode: number; body: Uint8Array }> {
|
|
143
|
-
const handler = client.config.requestHandler as {
|
|
144
|
-
handle(
|
|
145
|
-
request: RawRequest,
|
|
146
|
-
): Promise<{ response: { statusCode: number; body: AsyncIterable<Uint8Array> } }>;
|
|
147
|
-
};
|
|
148
|
-
const { response } = await handler.handle(request);
|
|
149
|
-
const chunks: Uint8Array[] = [];
|
|
150
|
-
for await (const c of response.body) chunks.push(c);
|
|
151
|
-
return { statusCode: response.statusCode, body: new Uint8Array(Buffer.concat(chunks)) };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
120
|
// ------------------------------------------------------------------ tags
|
|
155
121
|
|
|
156
122
|
export function stageTags(app: string, stage: string): Record<string, string> {
|
package/dist/drivers/ecr.d.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { type ImageConfig, type ImageFile, type ImageManifest } from '../images.ts';
|
|
2
|
-
import { type EngineContext } from '../util.ts';
|
|
3
|
-
/**
|
|
4
|
-
* Container images through the ECR API alone (no Docker daemon, no registry
|
|
5
|
-
* login): blobs go up with the layer-upload calls and images are manifests
|
|
6
|
-
* written with PutImage. Every call is IAM-authorized on the repository.
|
|
7
|
-
*/
|
|
8
|
-
export interface RepositoryState {
|
|
9
|
-
name: string;
|
|
10
|
-
arn: string;
|
|
11
|
-
registryId: string;
|
|
12
|
-
}
|
|
13
|
-
export declare function ensureRepository(ctx: EngineContext, spec: {
|
|
14
|
-
name: string;
|
|
15
|
-
tags?: Record<string, string>;
|
|
16
|
-
}): Promise<RepositoryState>;
|
|
17
|
-
/** An image in a registry other than the platform's, pinned by manifest digest. */
|
|
18
|
-
export interface ImageRef {
|
|
19
|
-
/** `public.ecr.aws`. */
|
|
20
|
-
registry: string;
|
|
21
|
-
/** `docker/library/node`. */
|
|
22
|
-
repository: string;
|
|
23
|
-
digest: string;
|
|
24
|
-
tag?: string;
|
|
25
|
-
}
|
|
26
|
-
/** Where a base image comes from the first time a repository needs it. */
|
|
27
|
-
export interface ImageSource {
|
|
28
|
-
/** The manifest's raw bytes (its digest is checked against the ref). */
|
|
29
|
-
manifest(ref: ImageRef): Promise<{
|
|
30
|
-
bytes: Uint8Array;
|
|
31
|
-
mediaType?: string;
|
|
32
|
-
}>;
|
|
33
|
-
blob(ref: ImageRef, digest: string): Promise<Uint8Array>;
|
|
34
|
-
}
|
|
35
|
-
/** Anonymous pulls from a public registry that speaks the distribution API with token auth (ECR Public). */
|
|
36
|
-
export declare function publicRegistrySource(fetchImpl?: typeof fetch): ImageSource;
|
|
37
|
-
/** A base image as held in the platform's repository. */
|
|
38
|
-
export interface BaseImage {
|
|
39
|
-
/** Manifest digest (the ref's). */
|
|
40
|
-
digest: string;
|
|
41
|
-
tag: string;
|
|
42
|
-
manifest: ImageManifest;
|
|
43
|
-
config: ImageConfig;
|
|
44
|
-
}
|
|
45
|
-
/** Tag a base image is kept under: `base--<first 12 hex of its digest>`. */
|
|
46
|
-
export declare function baseImageTag(digest: string): string;
|
|
47
|
-
/**
|
|
48
|
-
* Make `repository` hold `base` (copying it from its registry the first
|
|
49
|
-
* time) and return its manifest and config. The copy is tagged: ECR
|
|
50
|
-
* reclaims layers no image references, so the base's layers stay only
|
|
51
|
-
* while an image of their own points at them.
|
|
52
|
-
*/
|
|
53
|
-
export declare function ensureBaseImage(ctx: EngineContext, spec: {
|
|
54
|
-
repository: string;
|
|
55
|
-
base: ImageRef;
|
|
56
|
-
source?: ImageSource;
|
|
57
|
-
}): Promise<BaseImage>;
|
|
58
|
-
export interface PushImageSpec {
|
|
59
|
-
repository: string;
|
|
60
|
-
/** `<registry>/<repository>`: the pushed image is referenced as `<repositoryUri>@<digest>`. */
|
|
61
|
-
repositoryUri: string;
|
|
62
|
-
/** From {@link ensureBaseImage}, in the same repository. */
|
|
63
|
-
base: BaseImage;
|
|
64
|
-
/** Files of the one layer added on top of the base. */
|
|
65
|
-
files: readonly ImageFile[];
|
|
66
|
-
entrypoint: string[];
|
|
67
|
-
cmd?: string[];
|
|
68
|
-
env?: Record<string, string>;
|
|
69
|
-
workingDir?: string;
|
|
70
|
-
user?: string;
|
|
71
|
-
tag: string;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Build an image (the base plus one layer of `files`) and push it under
|
|
75
|
-
* `tag`. Idempotent: blobs the repository has are skipped and pushing the
|
|
76
|
-
* same image under the same tag again is a no-op.
|
|
77
|
-
*/
|
|
78
|
-
export declare function pushImage(ctx: EngineContext, spec: PushImageSpec): Promise<{
|
|
79
|
-
digest: string;
|
|
80
|
-
image: string;
|
|
81
|
-
}>;
|
|
82
|
-
export interface ImageListing {
|
|
83
|
-
tag: string;
|
|
84
|
-
digest: string;
|
|
85
|
-
pushedAt?: Date;
|
|
86
|
-
}
|
|
87
|
-
/** Tagged images whose tag starts with `tagPrefix`, one entry per tag. */
|
|
88
|
-
export declare function listImages(ctx: EngineContext, repository: string, tagPrefix?: string): Promise<ImageListing[]>;
|
|
89
|
-
/**
|
|
90
|
-
* Delete images by tag or digest. A tag removes only that tag (the image
|
|
91
|
-
* goes with its last tag); a digest removes the image under every tag.
|
|
92
|
-
*/
|
|
93
|
-
export declare function deleteImages(ctx: EngineContext, repository: string, ids: ReadonlyArray<{
|
|
94
|
-
tag: string;
|
|
95
|
-
} | {
|
|
96
|
-
digest: string;
|
|
97
|
-
}>): Promise<void>;
|
|
98
|
-
/** An image's manifest by tag or digest, or undefined when the repository doesn't hold it. */
|
|
99
|
-
export declare function getImage(ctx: EngineContext, repository: string, id: {
|
|
100
|
-
tag: string;
|
|
101
|
-
} | {
|
|
102
|
-
digest: string;
|
|
103
|
-
}): Promise<{
|
|
104
|
-
digest: string;
|
|
105
|
-
manifest: string;
|
|
106
|
-
mediaType?: string;
|
|
107
|
-
} | undefined>;
|
|
108
|
-
/** Upload one blob in the part size ECR asks for. ECR checks the digest on completion. */
|
|
109
|
-
export declare function uploadBlob(ctx: EngineContext, repository: string, bytes: Uint8Array, digest: string): Promise<void>;
|