From 4578a9d15b08a4e1ab43f8004810d7a22da69c00 Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Sat, 19 Feb 2022 20:22:13 +0200 Subject: [PATCH] Nix Piston: dev and prod containers - Change appEnv to isDev - Determine the image name in api/default.nix - Use production image in ./piston test --- api/default.nix | 8 ++++---- flake.nix | 4 ++-- piston | 19 +++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/api/default.nix b/api/default.nix index 84e7cf6..81022ad 100644 --- a/api/default.nix +++ b/api/default.nix @@ -1,4 +1,4 @@ -{pkgs, nosocket, appEnv, ...}: +{pkgs, nosocket, isDev, ...}: with pkgs; rec { package = mkYarnPackage { name = "piston"; @@ -67,12 +67,12 @@ with pkgs; rec { ''; container = pkgs.dockerTools.buildLayeredImageWithNixDb { - name = "piston"; + name = if isDev then "piston" else "ghcr.io/engineer-man/piston"; 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 = { Cmd = ["${package}/bin/pistond"]; diff --git a/flake.nix b/flake.nix index ca93d8c..d53fc00 100644 --- a/flake.nix +++ b/flake.nix @@ -74,12 +74,12 @@ containers = { dev = (import ./api { inherit pkgs nosocket; - appEnv = "dev"; + isDev = true; }).container; prod = (import ./api { inherit pkgs nosocket; - appEnv = "prod"; + isDev = false; }).container; }; }; diff --git a/piston b/piston index 54b9b01..84001d6 100755 --- a/piston +++ b/piston @@ -17,7 +17,6 @@ build_base() { CONTAINER_PATH="$(nix build ".#$container_flake_key" --no-link --json | jq '.[0].outputs.out' -r)" echo "The image archive was created at: $CONTAINER_PATH" docker load -i $CONTAINER_PATH || exit 1 - docker tag "$IMAGE_NAME_DEV:$IMAGE_TAG" "$IMAGE_NAME:$IMAGE_TAG" || exit 1 } case "$SUBCOMMAND" in @@ -41,16 +40,15 @@ case "$SUBCOMMAND" in build) build_base - runtime_set=all if [[ ! -z "$1" ]]; then + # $1 contains a variant to build runtime_set=$1 + docker build \ + --build-arg RUNTIMESET=$runtime_set \ + -f "$SCRIPT_DIR"/Dockerfile.withset \ + -t "$IMAGE_NAME_DEV:$runtime_set-latest" \ + . 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 @@ -107,11 +105,11 @@ case "$SUBCOMMAND" in -e PISTON_FLAKE_PATH=/piston/src \ -v "$SCRIPT_DIR":/piston/src \ --name piston_test_runner \ - "$IMAGE_NAME_DEV:$IMAGE_TAG" \ + "$IMAGE_NAME:$IMAGE_TAG" \ piston-test $1 ;; - test-with-cache) + test-dev) docker run \ --rm \ -it \ @@ -147,6 +145,7 @@ case "$SUBCOMMAND" in echo " including the runtime set within it" echo " scaffold [runtime] Initializes a new runtime" echo " test Runs unit tests on the given runtime" + echo " test-dev Same as test, but using the development container and volume" echo " Optionally set runtime to --all to test all" echo " NOTE: This is only for the runtimes contained" echo " within this repo"