Skip to content

Commit b441615

Browse files
author
Florian Chazal
committed
Add lerna command for uber zip
1 parent 1b3bb38 commit b441615

File tree

9 files changed

+35
-56
lines changed

9 files changed

+35
-56
lines changed

.github/workflows/pr_lint_and_test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
- name: Packages size report
6060
uses: flochaz/[email protected]
6161
with:
62-
build-command: mkdir dist && npm run lerna-package && bash -c "mv ./packages/*/dist/* dist/" && ls dist
62+
build-command: mkdir dist && npm run lerna-package && npm run lerna-package-uber-zip && bash -c "mv ./packages/*/dist/* dist/" && ls dist
6363
dist-directory: /dist
6464
env:
6565
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

examples/cdk/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"watch": "tsc -w",
1616
"test": "npm run test:unit",
1717
"package": "echo 'Not applicable'",
18+
"package-uber-zip": "echo 'Not applicable'",
1819
"test:unit": "npm run build && jest",
1920
"test:e2e": "echo 'To be implemented ...'",
2021
"version": "npm install @aws-lambda-powertools/[email protected] @aws-lambda-powertools/[email protected] @aws-lambda-powertools/[email protected] && git add package.json",

examples/sam/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "sam build --beta-features",
1212
"test": "npm run test:unit",
1313
"package": "echo 'Not applicable'",
14+
"package-uber-zip": "echo 'Not applicable'",
1415
"test:unit": "npm run build && jest",
1516
"test:e2e": "echo 'To be implemented ...'",
1617
"version": "npm install @aws-lambda-powertools/[email protected] @aws-lambda-powertools/[email protected] @aws-lambda-powertools/[email protected] && git add package.json"

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"lerna-test:unit": "lerna exec -- npm run test:unit",
2020
"lerna-test:e2e": "lerna exec -- npm run test:e2e",
2121
"lerna-package": "lerna exec -- npm run package",
22+
"lerna-package-uber-zip": "lerna exec -- npm run package-uber-zip",
2223
"lerna-build": "lerna exec -- tsc",
2324
"lerna-lint": "lerna exec -- eslint \"./{src,tests}/**/*.ts ./src/*.ts\"",
2425
"lerna-format": "lerna exec -- eslint --fix \"./{src,tests}/**/*.ts ./src/*.ts\"",

packages/commons/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2020
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2121
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
22+
"package-uber-zip": "../../uber-package-builder.sh ${LERNA_PACKAGE_NAME}-uber ./dist/",
2223
"prepare": "npm run build",
2324
"prepublishOnly": "npm test && npm run lint",
2425
"preversion": "npm run lint",

packages/logger/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2222
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2323
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
24+
"package-uber-zip": "../../uber-package-builder.sh ${LERNA_PACKAGE_NAME}-uber ./dist/",
2425
"prepare": "npm run build",
2526
"prepublishOnly": "npm test && npm run lint",
2627
"preversion": "npm run lint",

packages/metrics/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2222
"format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests",
2323
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
24+
"package-uber-zip": "../../uber-package-builder.sh ${LERNA_PACKAGE_NAME}-uber ./dist/",
2425
"prepare": "npm run build",
2526
"prepublishOnly": "npm test && npm run lint",
2627
"preversion": "npm run lint",

packages/tracer/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"preversion": "npm run lint",
2626
"version": "npm run format && git add -A src",
2727
"postversion": "git push && git push --tags",
28-
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/"
28+
"package": "mkdir -p dist/ && npm pack && mv *.tgz dist/",
29+
"package-uber-zip": "../../uber-package-builder.sh ${LERNA_PACKAGE_NAME}-uber ./dist/"
2930
},
3031
"homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/tracer#readme",
3132
"license": "MIT-0",

uber-package-builder.sh

+26-54
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,45 @@
22
set -e
33

44

5-
usage() {
6-
echo "Uber package Builder"
7-
echo "------------------------"
8-
echo "./uber-pacakge-builder.sh NAME LOCAL_NPM_PACKAGE_LOCATION"
9-
echo ""}
5+
# usage() {
6+
# echo "Uber package Builder"
7+
# echo "------------------------"
8+
# echo "./uber-pacakge-builder.sh NAME LOCAL_NPM_PACKAGE_LOCATION"
9+
# echo ""}
1010

1111

12-
if [[ "$#" -lt 3 ]]; then
13-
usage
14-
exit 1
15-
fi
12+
# if [[ "$#" -lt 2 ]]; then
13+
# usage
14+
# exit 1
15+
# fi
1616

17-
name="${1}"
18-
runtime="${2}"
19-
dist_folder="${3}"
20-
21-
if test -d "$dist_folder"; then
22-
packages="${@:4}"
23-
else
24-
dist_folder=""
25-
packages="${@:3}"
26-
fi
17+
name=$(basename ${1})
18+
dist_folder="${2}"
2719

20+
echo "Will bundle $(ls ${dist_folder}) into ${dist_folder}/${name}.tgz from ${PWD}"
2821

2922
output_folder="$(mktemp -d)"
3023

3124
echo "$output_folder is the output folder"
3225

33-
docker_image="public.ecr.aws/sam/build-$runtime:latest"
34-
volume_params="-v $output_folder:/layer"
35-
36-
if [[ $runtime == node* ]]; then
37-
38-
package_folder="nodejs/"
39-
mkdir -p "$output_folder/$package_folder"
40-
if [[ -n "$dist_folder" ]]; then
41-
cp -r "$dist_folder" "$output_folder/$package_folder/"
42-
fi
43-
install_command="pushd $package_folder; npm install; npm install --save $packages; popd"
44-
volume_params="$volume_params -v $HOME/.npmrc:/root/.npmrc"
45-
46-
elif [[ $runtime == python* ]]; then
47-
48-
package_folder="python/lib/$runtime/site-packages/"
49-
if [[ -n "$dist_folder" ]]; then
50-
cp "$dist_folder" "$output_folder/requirements.txt"
51-
else
52-
touch "$output_folder/requirements.txt"
53-
fi
54-
55-
install_command="pip install -r requirements.txt -t $package_folder $packages"
56-
volume_params="$volume_params -v $HOME/.config/pip:/root/.config/pip"
57-
58-
else
59-
60-
usage
61-
exit 1
26+
docker_image="public.ecr.aws/sam/build-nodejs14.x:latest"
27+
volume_params="-v $output_folder:/bundle"
6228

63-
fi
29+
package_folder="nodejs/"
30+
mkdir -p "$output_folder/$package_folder"
6431

32+
cp -r "${2}" "$output_folder/$package_folder/"
33+
34+
install_command="pushd $package_folder; npm install --save ./*.tgz; popd"
35+
volume_params="$volume_params -v $HOME/.npmrc:/root/.npmrc"
6536

66-
echo "Building layer"
67-
zip_command="zip -r layer.zip * && rm -rf $package_folder"
37+
# echo "Building bundle: docker run --rm $volume_params -w "/bundle" "$docker_image" /bin/bash -c "$install_command && $zip_command""
38+
zip_command="zip -r bundle.zip * && rm -rf $package_folder"
6839

69-
docker run --rm $volume_params -w "/layer" "$docker_image" /bin/bash -c "$install_command && $zip_command"
40+
docker run --rm $volume_params -w "/bundle" "$docker_image" /bin/bash -c "$install_command && $zip_command"
7041

42+
mv "$output_folder/bundle.zip" "$dist_folder/$name.zip"
7143

72-
mv "$output_folder/layer.zip" "$dist_folder/$name.zip"
44+
rm -rf $output_folder
7345

74-
echo "All done. Enjoy your shiny new Lambda layer in $output_folder !"
46+
echo "All done"

0 commit comments

Comments
 (0)