Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To solve the npm package size issue #252

Merged
merged 35 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1974727
I am a bad js programer
TingDaoK Sep 9, 2021
f371350
Merge branch 'main' into npm-package
TingDaoK Sep 9, 2021
e477526
add one more todo
TingDaoK Sep 9, 2021
83fb37d
Merge branch 'npm-package' of github.com:awslabs/aws-crt-nodejs into …
TingDaoK Sep 9, 2021
4b001af
TODO checksum
TingDaoK Sep 10, 2021
a46bbaf
Checksum
TingDaoK Sep 11, 2021
6b58845
remove test line
TingDaoK Sep 11, 2021
bdcb541
check the path is correct
TingDaoK Sep 11, 2021
d86f783
just for testing
TingDaoK Sep 13, 2021
7a84ef3
Revert "just for testing"
TingDaoK Sep 13, 2021
fd26fb1
pro test
TingDaoK Sep 13, 2021
d37cc1e
you don't need typedoc
TingDaoK Sep 13, 2021
8630a0c
use `^` to include any newer version
TingDaoK Sep 13, 2021
0a294d3
sha 256 instead
TingDaoK Sep 14, 2021
465e5ed
Still have the checksum at S3
TingDaoK Sep 14, 2021
7e17e3e
introduce the env variable and README
TingDaoK Sep 14, 2021
e7acc86
markdown
TingDaoK Sep 14, 2021
8f865de
get rid of the newline for the checksums
TingDaoK Sep 14, 2021
338950e
Coments addressed, first round
TingDaoK Sep 15, 2021
30f62db
our own copy folder and firendly change work directory
TingDaoK Sep 15, 2021
ebf6066
remove test code and be more like a JS developer
TingDaoK Sep 15, 2021
2a4a334
more styling fix
TingDaoK Sep 15, 2021
429486a
remove uuid as well
TingDaoK Sep 15, 2021
0683a23
node build-in modules first
TingDaoK Sep 15, 2021
3bca139
remove source code after build
TingDaoK Sep 15, 2021
410ca2f
again, forgot to remove the test
TingDaoK Sep 15, 2021
28bed15
also another one for test
TingDaoK Sep 15, 2021
967aa2f
don't need to copy around
TingDaoK Sep 15, 2021
5ed6f0c
remove the unused variable
TingDaoK Sep 15, 2021
f8240a2
tweak, return 0 at end
TingDaoK Sep 15, 2021
58ba0b1
better error handling
TingDaoK Sep 16, 2021
95714c8
check if it's a release
TingDaoK Sep 16, 2021
b63392c
comments addressed
TingDaoK Sep 16, 2021
9391224
to fix npm warning?
TingDaoK Sep 16, 2021
32a4c82
npm update
TingDaoK Sep 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ deps_build/
/test/
/samples/
/tsconfig*.json
/typedoc*.json
/jest.config.js
/make-docs.sh

Expand All @@ -167,20 +168,10 @@ deps_build/
**/.github/
**/continuous-delivery/
**/docs/
**/codebuild/

# Skip large submodule files
crt/aws-c-*/tests
crt/**/AWSCRTAndroidTestRunner
crt/s2n/tests/fuzz/corpus
crt/s2n/tests/ctverif
crt/s2n/tests/pems
crt/s2n/tests/saw
crt/s2n/tests/sidetrail
crt/s2n/tests/integration/trust-store
crt/s2n/tests/integration/data
crt/s2n/tests/unit/kats
crt/*/.cbmc-batch/
crt/*/codebuild/
# Skip Native Code
**/crt/

# Skip unwanted binaries
dist/bin/**/sha256_profile
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ You can either add it to package.json (if using a tool like webpack), or just im
npm install aws-crt
```

To reduce the size of package, we put the C source code in the S3 bucket. If the platform you are using doesn't have the prebuilt binary, the install script will pull the source from S3 bucket. In case of no public internet access, you can specify the "CRT_BINARY_HOST" environment variable for the host of the source code. The build script will fetch source code from that host instead. To fetch the source from S3, you can reach to the cloudfront distribution (Only works for version after v1.9.2) `https://d332vdhbectycy.cloudfront.net/aws-crt-<version>-source.tgz`, the sha256 checksum `https://d332vdhbectycy.cloudfront.net/aws-crt-<version>-source.sha256`

### Debug C part of code

After building the package locally, use ```node ./scripts/build.js --debug``` to enable debug. Then, attach any C debugger to use node to run `jest`
Expand Down
55 changes: 55 additions & 0 deletions continuous-delivery/pack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -ex

# force a failure if there's no tag
git describe --tags
# now get the tag
CURRENT_TAG=$(git describe --tags | cut -f2 -dv)
# convert v0.2.12-2-g50254a9 to 0.2.12
CURRENT_TAG_VERSION=$(git describe --tags | cut -f1 -d'-' | cut -f2 -dv)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be check if the tagged commit at current head? This can prevent updating binaries without bumping versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed a check that was there for testing. Added it back to check if the tag is release. So, in that case, we can prevent updating binaries without proper release, which will also prevent the version is not updated, I think.

# if there's a hash on the tag, then this is not a release tagged commit
if [ "$CURRENT_TAG" != "$CURRENT_TAG_VERSION" ]; then
echo "Current tag version is not a release tag, cut a new release if you want to publish."
exit 1
fi

# go to previous directory
cd ..

# native source code
tar -cvzf aws-crt-$CURRENT_TAG_VERSION-source.tgz aws-crt-nodejs/crt
# sha256 checksum
SOURCE_SHA256=$(sha256sum aws-crt-$CURRENT_TAG_VERSION-source.tgz | awk '{print $1}')
echo -n $SOURCE_SHA256 > aws-crt-$CURRENT_TAG_VERSION-source.sha256

# omnibus package
tar -cvzf aws-crt-$CURRENT_TAG_VERSION-all.tgz aws-crt-nodejs/
# sha256 checksum
SOURCE_SHA256=$(sha256sum aws-crt-$CURRENT_TAG_VERSION-all.tgz | awk '{print $1}')
echo -n $SOURCE_SHA256 > aws-crt-$CURRENT_TAG_VERSION-all.sha256

# binaries
tar -cvzf aws-crt-$CURRENT_TAG_VERSION-binary.tgz aws-crt-nodejs/dist/bin
# sha256 checksum
SOURCE_SHA256=$(sha256sum aws-crt-$CURRENT_TAG_VERSION-binary.tgz | awk '{print $1}')
echo -n $SOURCE_SHA256 > aws-crt-$CURRENT_TAG_VERSION-binary.sha256


# npm pack
cd aws-crt-nodejs
npm install --unsafe-perm
npm pack --unsafe-perm
cp aws-crt-*.tgz ..

# Check unzip npm package size
cd ..
UNZIP="unzip_pack"
mkdir $UNZIP
tar -xf aws-crt-$CURRENT_TAG_VERSION.tgz -C $UNZIP
PACK_FILE_SIZE_KB=$(du -sk $UNZIP | awk '{print $1}')
if expr $PACK_FILE_SIZE_KB \> 12000 ; then
# the package size is larger than 12 MB, return -1
echo "Package size is too large"
exit -1
fi
exit 0
9 changes: 5 additions & 4 deletions continuous-delivery/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ phases:
- cp -r $CODEBUILD_SRC_DIR_aws_crt_nodejs_win_x64/* $DIST_BIN
- cp -r $CODEBUILD_SRC_DIR_aws_crt_nodejs_linux_aarch64/* $DIST_BIN
- ls $DIST_BIN
- npm install --unsafe-perm
- npm pack --unsafe-perm
- cp aws-crt-*.tgz ..
post_build:
commands:
- bash ./continuous-delivery/pack.sh

artifacts:
files:
- 'aws-crt-*.tgz'
- "aws-crt-*.tgz"
- "aws-crt-*.sha256"
Loading