I hereby claim:
- I am stevenuray on github.
- I am surayest (https://keybase.io/surayest) on keybase.
- I have a public key ASDk-AprMUppT3s8KSjWTXW3hlkN3aOK2pRcMxx9AXXpBwo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
#!/usr/bin/env bash | |
#This is called so that container startup is interrupted if npm install fails with a nonzero status code. | |
set -euo pipefail |
#Script variables here | |
readonly NPM_DIR=/app/src/node_modules | |
readonly LOCK_FILE=$NPM_DIR/.npm_lock | |
readonly LOCK_FD=200 | |
readonly MD5_FILE=$NPM_DIR/.package_md5 |
lock() { | |
# Create lock file. | |
eval "exec $2>$1" | |
# Get exclusive, waiting lock on the file descriptor of the lock file. | |
flock --exclusive $2 | |
} |
unlock() { | |
flock --unlock $1 | |
} |
check_npm_libraries() { | |
if [ ! -f $MD5_FILE ] || ! md5sum -c --status <<<"$(cat $MD5_FILE)"; then | |
echo "INVALID" | |
else | |
echo "VALID" | |
fi | |
} |
prepare_npm_volume() { | |
#Try to get node_modules lock. | |
lock $LOCK_FILE $LOCK_FD | |
#Check status of npm libraries now that this container has the lock. | |
echo "This container has the lock on the npm libraries." | |
npm_library_status=$(check_npm_libraries) | |
if [ "$npm_library_status" == "INVALID" ]; then | |
install_npm_libraries |
install_npm_libraries() { | |
npm install grunt | |
echo "Installing npm Libraries..." | |
npm install --loglevel info | |
write_md5_sum_to_md5_file | |
} |
#!/usr/bin/env bash | |
# Application containers should not continue starting | |
# if their dependencies are unverified, | |
# so if any command in this script fails the container | |
# will stop it’s initialization process and | |
# an error message will be presented to the user. | |
set -euo pipefail | |
# Set variables here | |
# The resource to have synchronized write access is the node_modules directory. |