Skip to content

Instantly share code, notes, and snippets.

@stevenuray
stevenuray / monolith_development_container_entrypoint
Last active Jul 11, 2018
Dockerlith Application Container Entrypoint Script for Synchronizing Access to Shared NPM Dependencies
View monolith_development_container_entrypoint
#!/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.
@stevenuray
stevenuray / lock-script.sh
Created Jul 5, 2018
Dockerlith Lock Script Prepare NPM Volume Function
View lock-script.sh
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
@stevenuray
stevenuray / lock-script.sh
Last active Jul 5, 2018
Dockerlith Lock Script MD5 Sum Persistence Function
View lock-script.sh
install_npm_libraries() {
npm install grunt
echo "Installing npm Libraries..."
npm install --loglevel info
write_md5_sum_to_md5_file
}
@stevenuray
stevenuray / lock-script.sh
Created Jul 5, 2018
Dockerlith Lock Script Dependency Update Check
View lock-script.sh
check_npm_libraries() {
if [ ! -f $MD5_FILE ] || ! md5sum -c --status <<<"$(cat $MD5_FILE)"; then
echo "INVALID"
else
echo "VALID"
fi
}
@stevenuray
stevenuray / lock-script.sh
Created Jul 5, 2018
Dockerlith Lock Script Unlock Function
View lock-script.sh
unlock() {
flock --unlock $1
}
@stevenuray
stevenuray / lock-script.sh
Created Jul 5, 2018
Dockerlith Lock Script Lock Function
View lock-script.sh
lock() {
# Create lock file.
eval "exec $2>$1"
# Get exclusive, waiting lock on the file descriptor of the lock file.
flock --exclusive $2
}
@stevenuray
stevenuray / lock-script.sh
Created Jul 5, 2018
Dockerlith Lock Script Variables
View lock-script.sh
#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
@stevenuray
stevenuray / gist:5b6c4bb382f6ad9cff64785548d4f5c1
Last active Jul 5, 2018
File Descriptor Lock Bash Scipt Header
View gist:5b6c4bb382f6ad9cff64785548d4f5c1
#!/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
@stevenuray
stevenuray / keybase.md
Created Sep 14, 2017
Steven Uray's Keybase Gist
View keybase.md

Keybase proof

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: