|
1 | 1 | import * as path from 'path';
|
| 2 | +import '@aws-cdk/assert-internal/jest'; |
2 | 3 | import { Template } from '@aws-cdk/assertions';
|
3 | 4 | import * as ecr from '@aws-cdk/aws-ecr';
|
4 | 5 | import * as ecr_assets from '@aws-cdk/aws-ecr-assets';
|
@@ -32,6 +33,92 @@ test('create a service with ECR Public(image repository type: ECR_PUBLIC)', () =
|
32 | 33 | });
|
33 | 34 | });
|
34 | 35 |
|
| 36 | +test('custom environment variables and start commands are allowed for imageConfiguration with defined port', () => { |
| 37 | + // GIVEN |
| 38 | + const app = new cdk.App(); |
| 39 | + const stack = new cdk.Stack(app, 'demo-stack'); |
| 40 | + // WHEN |
| 41 | + new Service(stack, 'DemoService', { |
| 42 | + source: Source.fromEcrPublic({ |
| 43 | + imageConfiguration: { |
| 44 | + port: 8000, |
| 45 | + environment: { |
| 46 | + foo: 'fooval', |
| 47 | + bar: 'barval', |
| 48 | + }, |
| 49 | + startCommand: '/root/start-command.sh', |
| 50 | + }, |
| 51 | + imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest', |
| 52 | + }), |
| 53 | + }); |
| 54 | + // we should have the service |
| 55 | + Template.fromStack(stack).hasResourceProperties('AWS::AppRunner::Service', { |
| 56 | + SourceConfiguration: { |
| 57 | + AuthenticationConfiguration: {}, |
| 58 | + ImageRepository: { |
| 59 | + ImageConfiguration: { |
| 60 | + Port: '8000', |
| 61 | + RuntimeEnvironmentVariables: [ |
| 62 | + { |
| 63 | + Name: 'foo', |
| 64 | + Value: 'fooval', |
| 65 | + }, |
| 66 | + { |
| 67 | + Name: 'bar', |
| 68 | + Value: 'barval', |
| 69 | + }, |
| 70 | + ], |
| 71 | + StartCommand: '/root/start-command.sh', |
| 72 | + }, |
| 73 | + ImageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest', |
| 74 | + ImageRepositoryType: 'ECR_PUBLIC', |
| 75 | + }, |
| 76 | + }, |
| 77 | + }); |
| 78 | +}); |
| 79 | + |
| 80 | +test('custom environment variables and start commands are allowed for imageConfiguration with port undefined', () => { |
| 81 | + // GIVEN |
| 82 | + const app = new cdk.App(); |
| 83 | + const stack = new cdk.Stack(app, 'demo-stack'); |
| 84 | + // WHEN |
| 85 | + new Service(stack, 'DemoService', { |
| 86 | + source: Source.fromEcrPublic({ |
| 87 | + imageConfiguration: { |
| 88 | + environment: { |
| 89 | + foo: 'fooval', |
| 90 | + bar: 'barval', |
| 91 | + }, |
| 92 | + startCommand: '/root/start-command.sh', |
| 93 | + }, |
| 94 | + imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest', |
| 95 | + }), |
| 96 | + }); |
| 97 | + // we should have the service |
| 98 | + Template.fromStack(stack).hasResourceProperties('AWS::AppRunner::Service', { |
| 99 | + SourceConfiguration: { |
| 100 | + AuthenticationConfiguration: {}, |
| 101 | + ImageRepository: { |
| 102 | + ImageConfiguration: { |
| 103 | + RuntimeEnvironmentVariables: [ |
| 104 | + { |
| 105 | + Name: 'foo', |
| 106 | + Value: 'fooval', |
| 107 | + }, |
| 108 | + { |
| 109 | + Name: 'bar', |
| 110 | + Value: 'barval', |
| 111 | + }, |
| 112 | + ], |
| 113 | + StartCommand: '/root/start-command.sh', |
| 114 | + }, |
| 115 | + ImageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest', |
| 116 | + ImageRepositoryType: 'ECR_PUBLIC', |
| 117 | + }, |
| 118 | + }, |
| 119 | + }); |
| 120 | +}); |
| 121 | + |
35 | 122 | test('create a service from existing ECR repository(image repository type: ECR)', () => {
|
36 | 123 | // GIVEN
|
37 | 124 | const app = new cdk.App();
|
@@ -249,6 +336,66 @@ test('create a service with github repository - undefined branch name is allowed
|
249 | 336 | });
|
250 | 337 | });
|
251 | 338 |
|
| 339 | +test('create a service with github repository - buildCommand, environment and startCommand are allowed', () => { |
| 340 | + // GIVEN |
| 341 | + const app = new cdk.App(); |
| 342 | + const stack = new cdk.Stack(app, 'demo-stack'); |
| 343 | + // WHEN |
| 344 | + new Service(stack, 'DemoService', { |
| 345 | + source: Source.fromGitHub({ |
| 346 | + repositoryUrl: 'https://github.com/aws-containers/hello-app-runner', |
| 347 | + configurationSource: ConfigurationSourceType.API, |
| 348 | + codeConfigurationValues: { |
| 349 | + runtime: Runtime.PYTHON_3, |
| 350 | + port: '8000', |
| 351 | + buildCommand: '/root/build.sh', |
| 352 | + environment: { |
| 353 | + foo: 'fooval', |
| 354 | + bar: 'barval', |
| 355 | + }, |
| 356 | + startCommand: '/root/start.sh', |
| 357 | + }, |
| 358 | + connection: GitHubConnection.fromConnectionArn('MOCK'), |
| 359 | + }), |
| 360 | + }); |
| 361 | + |
| 362 | + // THEN |
| 363 | + // we should have the service with the branch value as 'main' |
| 364 | + Template.fromStack(stack).hasResourceProperties('AWS::AppRunner::Service', { |
| 365 | + SourceConfiguration: { |
| 366 | + AuthenticationConfiguration: { |
| 367 | + ConnectionArn: 'MOCK', |
| 368 | + }, |
| 369 | + CodeRepository: { |
| 370 | + CodeConfiguration: { |
| 371 | + CodeConfigurationValues: { |
| 372 | + Port: '8000', |
| 373 | + Runtime: 'PYTHON_3', |
| 374 | + BuildCommand: '/root/build.sh', |
| 375 | + RuntimeEnvironmentVariables: [ |
| 376 | + { |
| 377 | + Name: 'foo', |
| 378 | + Value: 'fooval', |
| 379 | + }, |
| 380 | + { |
| 381 | + Name: 'bar', |
| 382 | + Value: 'barval', |
| 383 | + }, |
| 384 | + ], |
| 385 | + StartCommand: '/root/start.sh', |
| 386 | + }, |
| 387 | + ConfigurationSource: 'API', |
| 388 | + }, |
| 389 | + RepositoryUrl: 'https://github.com/aws-containers/hello-app-runner', |
| 390 | + SourceCodeVersion: { |
| 391 | + Type: 'BRANCH', |
| 392 | + Value: 'main', |
| 393 | + }, |
| 394 | + }, |
| 395 | + }, |
| 396 | + }); |
| 397 | +}); |
| 398 | + |
252 | 399 |
|
253 | 400 | test('import from service name', () => {
|
254 | 401 | // GIVEN
|
@@ -417,3 +564,23 @@ test('custom cpu and memory units are allowed', () => {
|
417 | 564 | },
|
418 | 565 | });
|
419 | 566 | });
|
| 567 | + |
| 568 | +test('environment variable with a prefix of AWSAPPRUNNER should throw an error', () => { |
| 569 | + // GIVEN |
| 570 | + const app = new cdk.App(); |
| 571 | + const stack = new cdk.Stack(app, 'demo-stack'); |
| 572 | + // WHEN |
| 573 | + // we should have the service |
| 574 | + expect(() => { |
| 575 | + new Service(stack, 'DemoService', { |
| 576 | + source: Source.fromEcrPublic({ |
| 577 | + imageConfiguration: { |
| 578 | + environment: { |
| 579 | + AWSAPPRUNNER_FOO: 'bar', |
| 580 | + }, |
| 581 | + }, |
| 582 | + imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest', |
| 583 | + }), |
| 584 | + }); |
| 585 | + }).toThrow('Environment variable key AWSAPPRUNNER_FOO with a prefix of AWSAPPRUNNER is not allowed'); |
| 586 | +}); |
0 commit comments