forked from casper-network/casper-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_wasm_package.sh
executable file
·52 lines (48 loc) · 1.54 KB
/
build_wasm_package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
abspath() {
# generate absolute path from relative path
# $1 : relative filename
# return : absolute path
if [ -d "$1" ]; then
# dir
(cd "$1"; pwd)
elif [ -f "$1" ]; then
# file
if [[ $1 == */* ]]; then
echo "$(cd "${1%/*}"; pwd)/${1##*/}"
else
echo "$(pwd)/$1"
fi
fi
}
export RUN_DIR=$(dirname $(abspath $0))
NODE_CONFIG_FILE="$RUN_DIR/node/Cargo.toml"
# have to be sed instead of grep -oP to work in alpine docker image
export WASM_PACKAGE_VERSION="$(grep ^version $NODE_CONFIG_FILE | sed -e s'/.*= "//' | sed -e s'/".*//')"
export CL_WASM_DIR="$RUN_DIR/target/wasm32-unknown-unknown/release"
export CL_OUTPUT_S3_DIR="$RUN_DIR/s3_artifacts/${WASM_PACKAGE_VERSION}"
export CL_WASM_PACKAGE="$CL_OUTPUT_S3_DIR/casper-contracts.tar.gz"
export CL_S3_BUCKET='casperlabs-cicd-artifacts'
export CL_S3_LOCATION="wasm_contracts/${WASM_PACKAGE_VERSION}"
if [ ! -d $CL_OUTPUT_S3_DIR ]; then
mkdir -p "${CL_OUTPUT_S3_DIR}"
fi
# package all wasm files
echo "[INFO] Checking if wasm files are ready under the path $CL_WASM_DIR"
if [ -d "$CL_WASM_DIR" ]; then
ls -al $CL_WASM_DIR/*wasm
echo "[INFO] Creating a tar.gz package: $CL_WASM_PACKAGE"
pushd $CL_WASM_DIR
tar zvcf $CL_WASM_PACKAGE *wasm
popd
else
echo "[ERROR] No wasm dir: $CL_WASM_DIR"
exit 1
fi
# upload to s3
if [ -z "$AWS_SECRET_ACCESS_KEY" ] || [ -z "$AWS_ACCESS_KEY_ID" ]; then
log "ERROR: AWS KEYS needed to run. Contact SRE."
exit 1
else
s3cmd put ${CL_WASM_PACKAGE} s3://${CL_S3_BUCKET}/${CL_S3_LOCATION}/casper-contracts.tar.gz
fi