Skip to content

Commit

Permalink
buildEnvVars
Browse files Browse the repository at this point in the history
  • Loading branch information
saddam-azad committed Dec 21, 2024
1 parent a7cd0c3 commit aa0852b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
14 changes: 6 additions & 8 deletions lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export interface PipelineProps {
buildcmd: string;
outputdir: string;
};
buildEnvironmentVariables?: Record<string, { value: string; type: BuildEnvironmentVariableType.PARAMETER_STORE }>;
// buildEnvironmentVariables?: Record<string, { value: string; type: BuildEnvironmentVariableType.PARAMETER_STORE }>;
buildEnvironmentVariables: { key: string; resource: string; }[],

// events
eventTarget: string;
Expand Down Expand Up @@ -281,14 +282,11 @@ export class PipelineConstruct extends Construct {
}

// environment variables
const buildEnvironmentVariables = Object.entries(props.buildEnvironmentVariables || {}).reduce(
(acc, [name, { value }]) => {
if (typeof value === 'string') {
acc[name] = { value, type: BuildEnvironmentVariableType.PARAMETER_STORE };
}
const buildEnvironmentVariables: Record<string, BuildEnvironmentVariable> = (props.buildEnvironmentVariables || []).reduce(
(acc: Record<string, BuildEnvironmentVariable>, { key, resource }) => {
acc[key] = { value: resource, type: BuildEnvironmentVariableType.PARAMETER_STORE };
return acc;
},
{} as Record<string, { value: string; type: BuildEnvironmentVariableType.PARAMETER_STORE }>
}, {}
);

// create the cloudbuild project
Expand Down
7 changes: 4 additions & 3 deletions stack/SPAProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ export interface SPAProps extends StackProps {
* If you have custom environments for build step, create Parameter Store variables as plaintext and use this format:
* Must be in the same region as your stack.
*
* MY_VARIABLE: { value: "/path-to/your-parameter" }
*
* buildEnvironmentVariables: [
* { key: 'PUBLIC_EXAMPLE', resource: '/path-to/your-parameter' }
* ]
*/
readonly buildEnvironmentVariables?: Record<string, { value: string; }>;
readonly buildEnvironmentVariables?: { key: string; resource: string; }[];

/**
* Optional. If you have a custom CloudFront Functions file for your app, provide the relative path to the file.
Expand Down
2 changes: 1 addition & 1 deletion stack/SPAStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class SPAStack extends Stack {
buildcmd: props.buildProps?.buildcmd as string,
outputdir: props.buildProps?.outputdir as string,
},
buildEnvironmentVariables: props.buildEnvironmentVariables as Record<string, { value: string; type: BuildEnvironmentVariableType.PARAMETER_STORE }>,
buildEnvironmentVariables: props.buildEnvironmentVariables as { key: string; resource: string }[],
eventTarget: props.eventTarget as string
});

Expand Down
5 changes: 5 additions & 0 deletions templates/spa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const appStackProps: SPAProps = {
hostedZoneId: 'Z1D633PJRANDOM',
globalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abcd1234-abcd-1234-abcd-1234abcd1234',

// Custom buildtime environment variables
// buildEnvironmentVariables: [
// { key: 'PUBLIC_EXAMPLE', resource: '/path-to/your-parameter' }
// ]

// Custom Cloudfront Functions
// edgeFunctionFilePath: 'custom.js',

Expand Down

0 comments on commit aa0852b

Please sign in to comment.