Nix Piston: dev and prod containers

- Change appEnv to isDev
- Determine the image name in api/default.nix
- Use production image in ./piston test
This commit is contained in:
Omar Brikaa 2022-02-19 20:22:13 +02:00
parent c2bc1ebf94
commit 4578a9d15b
3 changed files with 15 additions and 16 deletions

View File

@ -1,4 +1,4 @@
{pkgs, nosocket, appEnv, ...}: {pkgs, nosocket, isDev, ...}:
with pkgs; rec { with pkgs; rec {
package = mkYarnPackage { package = mkYarnPackage {
name = "piston"; name = "piston";
@ -67,12 +67,12 @@ with pkgs; rec {
''; '';
container = pkgs.dockerTools.buildLayeredImageWithNixDb { container = pkgs.dockerTools.buildLayeredImageWithNixDb {
name = "piston"; name = if isDev then "piston" else "ghcr.io/engineer-man/piston";
tag = "base-latest"; tag = "base-latest";
contents = if appEnv == "dev" then basePackages ++ devPackages else basePackages; contents = if isDev then basePackages ++ devPackages else basePackages;
extraCommands = if appEnv == "dev" then baseCommands + devCommands else baseCommands; extraCommands = if isDev then baseCommands + devCommands else baseCommands;
config = { config = {
Cmd = ["${package}/bin/pistond"]; Cmd = ["${package}/bin/pistond"];

View File

@ -74,12 +74,12 @@
containers = { containers = {
dev = (import ./api { dev = (import ./api {
inherit pkgs nosocket; inherit pkgs nosocket;
appEnv = "dev"; isDev = true;
}).container; }).container;
prod = (import ./api { prod = (import ./api {
inherit pkgs nosocket; inherit pkgs nosocket;
appEnv = "prod"; isDev = false;
}).container; }).container;
}; };
}; };

19
piston
View File

@ -17,7 +17,6 @@ build_base() {
CONTAINER_PATH="$(nix build ".#$container_flake_key" --no-link --json | jq '.[0].outputs.out' -r)" CONTAINER_PATH="$(nix build ".#$container_flake_key" --no-link --json | jq '.[0].outputs.out' -r)"
echo "The image archive was created at: $CONTAINER_PATH" echo "The image archive was created at: $CONTAINER_PATH"
docker load -i $CONTAINER_PATH || exit 1 docker load -i $CONTAINER_PATH || exit 1
docker tag "$IMAGE_NAME_DEV:$IMAGE_TAG" "$IMAGE_NAME:$IMAGE_TAG" || exit 1
} }
case "$SUBCOMMAND" in case "$SUBCOMMAND" in
@ -41,16 +40,15 @@ case "$SUBCOMMAND" in
build) build)
build_base build_base
runtime_set=all
if [[ ! -z "$1" ]]; then if [[ ! -z "$1" ]]; then
# $1 contains a variant to build
runtime_set=$1 runtime_set=$1
docker build \
--build-arg RUNTIMESET=$runtime_set \
-f "$SCRIPT_DIR"/Dockerfile.withset \
-t "$IMAGE_NAME_DEV:$runtime_set-latest" \
.
fi fi
# $1 contains a variant to build
docker build \
--build-arg RUNTIMESET=$runtime_set \
-f "$SCRIPT_DIR"/Dockerfile.withset \
-t "$IMAGE_NAME_DEV:$runtime_set-latest" \
.
;; ;;
# dev commands # dev commands
@ -107,11 +105,11 @@ case "$SUBCOMMAND" in
-e PISTON_FLAKE_PATH=/piston/src \ -e PISTON_FLAKE_PATH=/piston/src \
-v "$SCRIPT_DIR":/piston/src \ -v "$SCRIPT_DIR":/piston/src \
--name piston_test_runner \ --name piston_test_runner \
"$IMAGE_NAME_DEV:$IMAGE_TAG" \ "$IMAGE_NAME:$IMAGE_TAG" \
piston-test $1 piston-test $1
;; ;;
test-with-cache) test-dev)
docker run \ docker run \
--rm \ --rm \
-it \ -it \
@ -147,6 +145,7 @@ case "$SUBCOMMAND" in
echo " including the runtime set within it" echo " including the runtime set within it"
echo " scaffold <language> [runtime] Initializes a new runtime" echo " scaffold <language> [runtime] Initializes a new runtime"
echo " test <runtime> Runs unit tests on the given runtime" echo " test <runtime> Runs unit tests on the given runtime"
echo " test-dev <runtime> Same as test, but using the development container and volume"
echo " Optionally set runtime to --all to test all" echo " Optionally set runtime to --all to test all"
echo " NOTE: This is only for the runtimes contained" echo " NOTE: This is only for the runtimes contained"
echo " within this repo" echo " within this repo"