Use Docker volumes and nodemon in development
This commit is contained in:
parent
c238ff6254
commit
a013613a59
|
@ -1,9 +1,9 @@
|
|||
# This "FROM" image is previously emitted by nix
|
||||
FROM ghcr.io/engineer-man/piston:base-latest
|
||||
|
||||
ENV PISTON_FLAKE_PATH=/piston/packages
|
||||
COPY runtimes/ /piston/packages/runtimes
|
||||
COPY flake.nix flake.lock /piston/packages/
|
||||
ENV PISTON_FLAKE_PATH=/piston/src
|
||||
COPY runtimes/ /piston/src/runtimes
|
||||
COPY flake.nix flake.lock /piston/src/
|
||||
|
||||
|
||||
ARG RUNTIMESET=all
|
||||
|
|
|
@ -42,6 +42,12 @@ with pkgs; rec {
|
|||
gnugrep
|
||||
rename
|
||||
util-linux
|
||||
nodejs-16_x
|
||||
yarn
|
||||
python3
|
||||
gcc
|
||||
gnumake
|
||||
gnused
|
||||
];
|
||||
|
||||
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
|
||||
done
|
||||
|
||||
mkdir -p usr/bin
|
||||
ln -s /bin/env usr/bin/env
|
||||
chmod -R 1777 usr
|
||||
chmod 1777 {,var/}tmp/
|
||||
'';
|
||||
|
||||
|
@ -86,4 +95,4 @@ with pkgs; rec {
|
|||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,18 +8,20 @@
|
|||
"express": "^4.17.1",
|
||||
"express-ws": "^5.0.2",
|
||||
"logplease": "^1.2.15",
|
||||
"nocamel": "git://github.com/HexF/nocamel.git#patch-1",
|
||||
"node-fetch": "^2.6.1",
|
||||
"uuid": "^8.3.2",
|
||||
"nocamel": "git://github.com/HexF/nocamel.git#patch-1",
|
||||
"waitpid": "git://github.com/HexF/node-waitpid.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"dev": "nodemon .",
|
||||
"lint": "prettier . --write",
|
||||
"prepack": "yarn2nix > yarn.nix"
|
||||
},
|
||||
"devDependencies": {
|
||||
"node2nix": "^1.6.0",
|
||||
"nodemon": "^2.0.15",
|
||||
"prettier": "2.2.1"
|
||||
},
|
||||
"bin": {
|
||||
|
|
665
api/yarn.lock
665
api/yarn.lock
File diff suppressed because it is too large
Load Diff
60
piston
60
piston
|
@ -3,6 +3,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|||
|
||||
|
||||
CONTAINER_NAME="piston_api"
|
||||
DEV_VOLUME_NAME="piston_nix"
|
||||
|
||||
IMAGE_TAG="base-latest"
|
||||
IMAGE_NAME="ghcr.io/engineer-man/piston"
|
||||
|
@ -37,6 +38,19 @@ case "$SUBCOMMAND" in
|
|||
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
|
||||
|
||||
scaffold)
|
||||
|
@ -45,20 +59,27 @@ case "$SUBCOMMAND" in
|
|||
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
|
||||
if [[ ! -z "$1" ]]; then
|
||||
# $1 contains a variant to build
|
||||
docker build \
|
||||
--build-arg RUNTIMESET=$1 \
|
||||
-f "$SCRIPT_DIR"/Dockerfile.withset \
|
||||
-t "$IMAGE_NAME_DEV:$1-latest" \
|
||||
.
|
||||
fi
|
||||
echo "Installing the required node modules"
|
||||
docker run \
|
||||
--rm \
|
||||
-p 2000:2000 \
|
||||
-it \
|
||||
--name $CONTAINER_NAME \
|
||||
-e PISTON_LOG_LEVEL=DEBUG \
|
||||
-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)
|
||||
build_base
|
||||
runtime_set=all
|
||||
if [[ ! -z "$1" ]]; then
|
||||
runtime_set=$1
|
||||
|
@ -69,23 +90,24 @@ case "$SUBCOMMAND" in
|
|||
-it \
|
||||
--name $CONTAINER_NAME \
|
||||
-e PISTON_LOG_LEVEL=DEBUG \
|
||||
-e PISTON_FLAKE_PATH=/piston/packages \
|
||||
-e PISTON_FLAKE_PATH=/piston/src \
|
||||
-e PISTON_RUNTIME_SET=$runtime_set \
|
||||
-v "$SCRIPT_DIR":/piston/packages \
|
||||
-d "$IMAGE_NAME_DEV:$IMAGE_TAG"
|
||||
;;
|
||||
-v "$SCRIPT_DIR":/piston/src \
|
||||
-v $DEV_VOLUME_NAME:/nix \
|
||||
-d "$IMAGE_NAME_DEV:$IMAGE_TAG" \
|
||||
bash -c "cd /piston/src/api && yarn run dev"
|
||||
;;
|
||||
|
||||
test)
|
||||
build_base
|
||||
docker run \
|
||||
--rm \
|
||||
-it \
|
||||
-e PISTON_FLAKE_PATH=/piston/packages \
|
||||
-v "$SCRIPT_DIR":/piston/packages \
|
||||
-e PISTON_FLAKE_PATH=/piston/src \
|
||||
-v "$SCRIPT_DIR":/piston/src \
|
||||
-v $DEV_VOLUME_NAME:/nix \
|
||||
--name piston_test_runner \
|
||||
"$IMAGE_NAME_DEV:$IMAGE_TAG" \
|
||||
piston-test $1
|
||||
|
||||
bash -c "/piston/src/api/src/bin/test.js $1"
|
||||
;;
|
||||
|
||||
*)
|
||||
|
|
Loading…
Reference in New Issue