2021-06-19 11:24:28 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Build a container using the spec file provided
|
|
|
|
|
2022-01-02 10:39:24 +01:00
|
|
|
START_DIR=$PWD
|
|
|
|
cd "$(dirname "$BASH_SOURCE[0]}")"
|
|
|
|
|
2021-06-19 11:24:28 +02:00
|
|
|
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 \
|
2024-09-06 17:43:07 +02:00
|
|
|
--privileged \
|
2021-06-19 11:24:28 +02:00
|
|
|
-v "$PWD/build":'/piston/packages' \
|
|
|
|
-dit \
|
|
|
|
-p $port:2000 \
|
|
|
|
--name builder_piston_instance \
|
|
|
|
ghcr.io/engineer-man/piston
|
2024-09-06 17:43:07 +02:00
|
|
|
|
2021-06-19 11:24:28 +02:00
|
|
|
# Ensure the CLI is installed
|
|
|
|
cd ../cli
|
|
|
|
npm i
|
|
|
|
cd -
|
|
|
|
|
|
|
|
# Evalulate the specfile
|
2024-09-06 17:43:07 +02:00
|
|
|
../cli/index.js -u "http://127.0.0.1:$port" ppman spec $1
|
2021-06-19 11:24:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
build_container(){
|
2022-01-02 10:39:24 +01:00
|
|
|
docker build -t $1 -f "Dockerfile" "$START_DIR/build"
|
2021-06-19 11:24:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-02 10:39:24 +01:00
|
|
|
SPEC_FILE=$START_DIR/$1
|
2021-06-19 11:24:28 +02:00
|
|
|
TAG=$2
|
|
|
|
|
2022-01-02 10:39:24 +01:00
|
|
|
[ -z "$1" ] && help_msg "specfile is required"
|
2021-06-19 11:24:28 +02:00
|
|
|
[ -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"
|
2024-09-06 18:13:02 +02:00
|
|
|
echo "$ docker run --privileged -dit -p 2000:2000 $TAG"
|