Add container customizer (#280)

This commit is contained in:
Thomas Hobson 2021-06-19 21:24:28 +12:00
parent 7d40abfb3f
commit 2c5ec5f7ec
No known key found for this signature in database
GPG Key ID: 9F1FD9D87950DB6F
3 changed files with 64 additions and 0 deletions

1
builder/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build

2
builder/Dockerfile Normal file
View File

@ -0,0 +1,2 @@
FROM ghcr.io/engineer-man/piston:latest
ADD . /piston/packages/

61
builder/build.sh Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Build a container using the spec file provided
help_msg(){
echo "Usage: $0 [specfile] [tag]"
echo
echo "$1"
exit 1
}
cleanup(){
echo "Exiting..."
docker stop builder_piston_instance && docker rm builder_piston_instance
}
fetch_packages(){
local port=$((5535 + $RANDOM % 60000))
mkdir build
# Start a piston container
docker run \
-v "$PWD/build":'/piston/packages' \
--tmpfs /piston/jobs \
-dit \
-p $port:2000 \
--name builder_piston_instance \
ghcr.io/engineer-man/piston
# Ensure the CLI is installed
cd ../cli
npm i
cd -
# Evalulate the specfile
../cli/index.js -u "http://127.0.0.1:$port" ppman spec $1
}
build_container(){
docker build -t $1 -f "$(dirname $0)/Dockerfile" "$PWD/build"
}
SPEC_FILE=$1
TAG=$2
[ -z "$SPEC_FILE" ] && help_msg "specfile is required"
[ -z "$TAG" ] && help_msg "tag is required"
[ -f "$SPEC_FILE" ] || help_msg "specfile does not exist"
which node || help_msg "nodejs is required"
which npm || help_msg "npm is required"
trap cleanup EXIT
fetch_packages $SPEC_FILE
build_container $TAG
echo "Start your custom piston container with"
echo "$ docker run --tmpfs /piston/jobs -dit -p 2000:2000 $TAG"