Use Docker volumes and nodemon in development

This commit is contained in:
Omar Brikaa 2022-02-10 15:28:17 +02:00
parent c238ff6254
commit a013613a59
5 changed files with 712 additions and 34 deletions

View File

@ -1,9 +1,9 @@
# This "FROM" image is previously emitted by nix # This "FROM" image is previously emitted by nix
FROM ghcr.io/engineer-man/piston:base-latest FROM ghcr.io/engineer-man/piston:base-latest
ENV PISTON_FLAKE_PATH=/piston/packages ENV PISTON_FLAKE_PATH=/piston/src
COPY runtimes/ /piston/packages/runtimes COPY runtimes/ /piston/src/runtimes
COPY flake.nix flake.lock /piston/packages/ COPY flake.nix flake.lock /piston/src/
ARG RUNTIMESET=all ARG RUNTIMESET=all

View File

@ -42,6 +42,12 @@ with pkgs; rec {
gnugrep gnugrep
rename rename
util-linux util-linux
nodejs-16_x
yarn
python3
gcc
gnumake
gnused
]; ];
extraCommands = '' extraCommands = ''
@ -53,6 +59,9 @@ with pkgs; rec {
echo "nixbld$i:x:$(( $i + 30000 )):30000:Nix build user $i:/var/empty:/run/current-system/sw/bin/nologin" >> etc/passwd echo "nixbld$i:x:$(( $i + 30000 )):30000:Nix build user $i:/var/empty:/run/current-system/sw/bin/nologin" >> etc/passwd
done done
mkdir -p usr/bin
ln -s /bin/env usr/bin/env
chmod -R 1777 usr
chmod 1777 {,var/}tmp/ chmod 1777 {,var/}tmp/
''; '';

View File

@ -8,18 +8,20 @@
"express": "^4.17.1", "express": "^4.17.1",
"express-ws": "^5.0.2", "express-ws": "^5.0.2",
"logplease": "^1.2.15", "logplease": "^1.2.15",
"nocamel": "git://github.com/HexF/nocamel.git#patch-1",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"uuid": "^8.3.2", "uuid": "^8.3.2",
"nocamel": "git://github.com/HexF/nocamel.git#patch-1",
"waitpid": "git://github.com/HexF/node-waitpid.git" "waitpid": "git://github.com/HexF/node-waitpid.git"
}, },
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"dev": "nodemon .",
"lint": "prettier . --write", "lint": "prettier . --write",
"prepack": "yarn2nix > yarn.nix" "prepack": "yarn2nix > yarn.nix"
}, },
"devDependencies": { "devDependencies": {
"node2nix": "^1.6.0", "node2nix": "^1.6.0",
"nodemon": "^2.0.15",
"prettier": "2.2.1" "prettier": "2.2.1"
}, },
"bin": { "bin": {

File diff suppressed because it is too large Load Diff

58
piston
View File

@ -3,6 +3,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CONTAINER_NAME="piston_api" CONTAINER_NAME="piston_api"
DEV_VOLUME_NAME="piston_nix"
IMAGE_TAG="base-latest" IMAGE_TAG="base-latest"
IMAGE_NAME="ghcr.io/engineer-man/piston" IMAGE_NAME="ghcr.io/engineer-man/piston"
@ -37,6 +38,19 @@ case "$SUBCOMMAND" in
docker pull "$IMAGE_NAME:$IMAGE_TAG" docker pull "$IMAGE_NAME:$IMAGE_TAG"
;; ;;
build)
runtime_set=all
if [[ ! -z "$1" ]]; then
runtime_Set=$1
fi
# $1 contains a variant to build
docker build \
--build-arg RUNTIMESET=$1 \
-f "$SCRIPT_DIR"/Dockerfile.withset \
-t "$IMAGE_NAME_DEV:$1-latest" \
.
;;
# dev commands # dev commands
scaffold) scaffold)
@ -45,20 +59,27 @@ case "$SUBCOMMAND" in
popd > /dev/null popd > /dev/null
;; ;;
build) build-dev)
echo "Removing the Nix volume if it exists"
docker volume rm -f $DEV_VOLUME_NAME
echo "Building the base docker image"
build_base build_base
if [[ ! -z "$1" ]]; then echo "Installing the required node modules"
# $1 contains a variant to build docker run \
docker build \ --rm \
--build-arg RUNTIMESET=$1 \ -p 2000:2000 \
-f "$SCRIPT_DIR"/Dockerfile.withset \ -it \
-t "$IMAGE_NAME_DEV:$1-latest" \ --name $CONTAINER_NAME \
. -e PISTON_LOG_LEVEL=DEBUG \
fi -e PISTON_FLAKE_PATH=/piston/src \
-e PISTON_RUNTIME_SET=none \
-v "$SCRIPT_DIR":/piston/src \
"$IMAGE_NAME_DEV:$IMAGE_TAG" \
bash -c "cd /piston/src/api && yarn install"
echo "Done building"
;; ;;
start-dev) start-dev)
build_base
runtime_set=all runtime_set=all
if [[ ! -z "$1" ]]; then if [[ ! -z "$1" ]]; then
runtime_set=$1 runtime_set=$1
@ -69,23 +90,24 @@ case "$SUBCOMMAND" in
-it \ -it \
--name $CONTAINER_NAME \ --name $CONTAINER_NAME \
-e PISTON_LOG_LEVEL=DEBUG \ -e PISTON_LOG_LEVEL=DEBUG \
-e PISTON_FLAKE_PATH=/piston/packages \ -e PISTON_FLAKE_PATH=/piston/src \
-e PISTON_RUNTIME_SET=$runtime_set \ -e PISTON_RUNTIME_SET=$runtime_set \
-v "$SCRIPT_DIR":/piston/packages \ -v "$SCRIPT_DIR":/piston/src \
-d "$IMAGE_NAME_DEV:$IMAGE_TAG" -v $DEV_VOLUME_NAME:/nix \
-d "$IMAGE_NAME_DEV:$IMAGE_TAG" \
bash -c "cd /piston/src/api && yarn run dev"
;; ;;
test) test)
build_base
docker run \ docker run \
--rm \ --rm \
-it \ -it \
-e PISTON_FLAKE_PATH=/piston/packages \ -e PISTON_FLAKE_PATH=/piston/src \
-v "$SCRIPT_DIR":/piston/packages \ -v "$SCRIPT_DIR":/piston/src \
-v $DEV_VOLUME_NAME:/nix \
--name piston_test_runner \ --name piston_test_runner \
"$IMAGE_NAME_DEV:$IMAGE_TAG" \ "$IMAGE_NAME_DEV:$IMAGE_TAG" \
piston-test $1 bash -c "/piston/src/api/src/bin/test.js $1"
;; ;;
*) *)