Skip to content

Commit 84a7ea6

Browse files
committed
Fix build scripts
1 parent f6a7ccd commit 84a7ea6

File tree

8 files changed

+33
-23
lines changed

8 files changed

+33
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
**/dist
33
**/global-s3-assets
44
**/regional-s3-assets
5+
**/staging
56
**/open-source
67
**/.zip
78
**/tmp

buildspec.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ phases:
66
nodejs: 16
77
pre_build:
88
commands:
9+
- npm install -g npm@9.4.2
910
- echo "Installing dependencies and executing unit tests - `pwd`"
1011
- cd deployment && chmod +x ./run-unit-tests.sh && ./run-unit-tests.sh
1112
- echo "Installing dependencies and executing unit tests completed `date`"

deployment/build-s3-dist.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ headline "[Init] Setting up paths and variables"
3434
solution_name="$1"
3535
asset_bucket="$2"
3636
solution_version="$3"
37-
template_dir="$PWD"
38-
staging_dist_dir="$template_dir/staging"
39-
template_dist_dir="$template_dir/global-s3-assets"
40-
build_dist_dir="$template_dir/regional-s3-assets"
41-
source_dir="$template_dir/../source"
37+
deployment_dir="$PWD"
38+
staging_dist_dir="$deployment_dir/staging"
39+
template_dist_dir="$deployment_dir/global-s3-assets"
40+
build_dist_dir="$deployment_dir/regional-s3-assets"
41+
source_dir="$deployment_dir/../source"
4242
cdk_source_dir="$source_dir/constructs"
4343

4444
headline "[Init] Clean old folders"
@@ -52,17 +52,16 @@ mkdir -p "$build_dist_dir"
5252
headline "[Build] Synthesize cdk template and assets"
5353
cd "$cdk_source_dir"
5454
npm run clean:install
55-
overrideWarningsEnabled=false npx cdk synth --asset-metadata false --path-metadata --output="$staging_dist_dir"
55+
overrideWarningsEnabled=false npx cdk synth --quiet --asset-metadata false --path-metadata --output="$staging_dist_dir"
5656
cd "$staging_dist_dir"
5757
rm tree.json manifest.json cdk.out ./*.assets.json
5858
cp "$staging_dist_dir"/*.template.json "$template_dist_dir"/
5959
rm ./*.template.json
6060

6161
headline "[Package] Generate public template"
62-
# Run the helper to clean-up the templates and remove unnecessary CDK elements
63-
cd "$template_dir"
64-
npx ts-node "$template_dir"/cdk-solution-helper/template-builder/index "$template_dist_dir" "$solution_name" "$asset_bucket" "$solution_version"
62+
cd "$deployment_dir"
63+
npx ts-node "$deployment_dir"/cdk-solution-helper/template-builder/index "$template_dist_dir" "$solution_name" "$asset_bucket" "$solution_version"
6564
mv "$template_dist_dir"/*.template.json "$template_dist_dir"/"$solution_name".template
6665

6766
headline "[Package] Generate public assets for lambda and ui"
68-
npx ts-node "$template_dir"/cdk-solution-helper/asset-package/index "$staging_dist_dir" "$build_dist_dir"
67+
npx ts-node "$deployment_dir"/cdk-solution-helper/asset-packager/index "$staging_dist_dir" "$build_dist_dir"

deployment/cdk-solution-helper/asset-packager/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
import { CDKAssetPackager } from "./asset-packager";
77
import path from "path";
88

9-
export async function handler(cdkAssetFolderPath: string | undefined, outputPath: string | undefined) {
10-
if (!cdkAssetFolderPath || !outputPath) throw new Error("undefined input path");
9+
export async function handler(
10+
cdkAssetFolderPath: string | undefined,
11+
outputPath: string | undefined
12+
) {
13+
if (!cdkAssetFolderPath || !outputPath)
14+
throw new Error("undefined input path");
1115
const assetPackager = new CDKAssetPackager(cdkAssetFolderPath);
1216
const assetPaths = await assetPackager.getAssetPaths();
1317
for (const path of assetPaths) {
@@ -19,8 +23,8 @@ export async function handler(cdkAssetFolderPath: string | undefined, outputPath
1923
if (require.main === module) {
2024
// this module was run directly from the command line, getting command line arguments
2125
// e.g. npx ts-node index.ts cdkAssetPath outputPath
22-
const cdkAssetPath = process.argv[3];
23-
const outputPath = process.argv[4];
26+
const cdkAssetPath = process.argv[2];
27+
const outputPath = process.argv[3];
2428
handler(cdkAssetPath, outputPath)
2529
.then(() => console.log("all assets packaged"))
2630
.catch((err) => {

deployment/cdk-solution-helper/template-builder/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ export async function handler(
3535
if (require.main === module) {
3636
// this module was run directly from the command line, getting command line arguments
3737
// e.g. npx ts-node index.ts templatePath mySolution lambdaAssetBucketName myVersion
38-
const templatePath = process.argv[3];
39-
const solutionName = process.argv[4];
40-
const lambdaBucketName = process.argv[5];
41-
const version = process.argv[6];
38+
const templatePath = process.argv[2];
39+
const solutionName = process.argv[3];
40+
const lambdaBucketName = process.argv[4];
41+
const version = process.argv[5];
42+
console.log(
43+
`********here: ${templatePath} ${solutionName} ${lambdaBucketName} ${version}`
44+
);
4245
handler(templatePath, solutionName, lambdaBucketName, version)
4346
.then(() => console.log("written all cfn templates"))
4447
.catch((err) => {

deployment/cdk-solution-helper/template-builder/template-builder.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ export class TemplateBuilder {
3535
template.Resources[key].Type === "AWS::Lambda::LayerVersion"
3636
);
3737
lambdaResourceKeys.forEach((resourceKey) => {
38-
const lambdaFunction = template.Resources[resourceKey];
39-
const assetProperty = lambdaFunction.Properties.Code;
38+
const lambdaResource = template.Resources[resourceKey];
39+
const assetProperty =
40+
lambdaResource.Type == "AWS::Lambda::Function"
41+
? lambdaResource.Properties.Code
42+
: lambdaResource.Properties.Content;
4043
const artifactHash = assetProperty.S3Key;
4144
assetProperty.S3Key = `${this.solutionName}/${this.solutionVersion}/${artifactHash}`;
4245
assetProperty.S3Bucket = {
4346
"Fn::Sub": `${this.lambdaAssetBucketName}-\${AWS::Region}`,
4447
};
45-
template.Resources[resourceKey] = lambdaFunction;
48+
template.Resources[resourceKey] = lambdaResource;
4649
});
4750
return template;
4851
}

source/image-handler/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"main": "index.js",
99
"scripts": {
1010
"clean": "rm -rf node_modules/ dist/ coverage/",
11-
"install:SharpForLambda": "rm -rf node_modules/sharp && npm install --arch=x64 --platform=linux sharp",
1211
"pretest": "npm run clean && npm ci",
1312
"test": "jest --coverage --silent"
1413
},

source/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "npx eslint . --ext .ts",
1010
"prettier-format": "npx prettier --config .prettierrc.yml '**/*.ts' --write",
1111
"install:custom-resource": "cd ./custom-resource && npm run clean && npm ci",
12-
"install:image-handler": "cd ./image-handler && npm run clean && npm ci && npm run install:SharpForLambda",
12+
"install:image-handler": "cd ./image-handler && npm run clean && npm ci",
1313
"install:dependencies": "npm run install:custom-resource && npm run install:image-handler"
1414
},
1515
"devDependencies": {

0 commit comments

Comments
 (0)