Skip to content

Commit 4578a9d

Browse files
committed
Nix Piston: dev and prod containers
- Change appEnv to isDev - Determine the image name in api/default.nix - Use production image in ./piston test
1 parent c2bc1eb commit 4578a9d

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

api/default.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{pkgs, nosocket, appEnv, ...}:
1+
{pkgs, nosocket, isDev, ...}:
22
with pkgs; rec {
33
package = mkYarnPackage {
44
name = "piston";
@@ -67,12 +67,12 @@ with pkgs; rec {
6767
'';
6868

6969
container = pkgs.dockerTools.buildLayeredImageWithNixDb {
70-
name = "piston";
70+
name = if isDev then "piston" else "ghcr.io/engineer-man/piston";
7171
tag = "base-latest";
7272

73-
contents = if appEnv == "dev" then basePackages ++ devPackages else basePackages;
73+
contents = if isDev then basePackages ++ devPackages else basePackages;
7474

75-
extraCommands = if appEnv == "dev" then baseCommands + devCommands else baseCommands;
75+
extraCommands = if isDev then baseCommands + devCommands else baseCommands;
7676

7777
config = {
7878
Cmd = ["${package}/bin/pistond"];

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@
7474
containers = {
7575
dev = (import ./api {
7676
inherit pkgs nosocket;
77-
appEnv = "dev";
77+
isDev = true;
7878
}).container;
7979

8080
prod = (import ./api {
8181
inherit pkgs nosocket;
82-
appEnv = "prod";
82+
isDev = false;
8383
}).container;
8484
};
8585
};

piston

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ build_base() {
1717
CONTAINER_PATH="$(nix build ".#$container_flake_key" --no-link --json | jq '.[0].outputs.out' -r)"
1818
echo "The image archive was created at: $CONTAINER_PATH"
1919
docker load -i $CONTAINER_PATH || exit 1
20-
docker tag "$IMAGE_NAME_DEV:$IMAGE_TAG" "$IMAGE_NAME:$IMAGE_TAG" || exit 1
2120
}
2221

2322
case "$SUBCOMMAND" in
@@ -41,16 +40,15 @@ case "$SUBCOMMAND" in
4140

4241
build)
4342
build_base
44-
runtime_set=all
4543
if [[ ! -z "$1" ]]; then
44+
# $1 contains a variant to build
4645
runtime_set=$1
46+
docker build \
47+
--build-arg RUNTIMESET=$runtime_set \
48+
-f "$SCRIPT_DIR"/Dockerfile.withset \
49+
-t "$IMAGE_NAME_DEV:$runtime_set-latest" \
50+
.
4751
fi
48-
# $1 contains a variant to build
49-
docker build \
50-
--build-arg RUNTIMESET=$runtime_set \
51-
-f "$SCRIPT_DIR"/Dockerfile.withset \
52-
-t "$IMAGE_NAME_DEV:$runtime_set-latest" \
53-
.
5452
;;
5553

5654
# dev commands
@@ -107,11 +105,11 @@ case "$SUBCOMMAND" in
107105
-e PISTON_FLAKE_PATH=/piston/src \
108106
-v "$SCRIPT_DIR":/piston/src \
109107
--name piston_test_runner \
110-
"$IMAGE_NAME_DEV:$IMAGE_TAG" \
108+
"$IMAGE_NAME:$IMAGE_TAG" \
111109
piston-test $1
112110
;;
113111

114-
test-with-cache)
112+
test-dev)
115113
docker run \
116114
--rm \
117115
-it \
@@ -147,6 +145,7 @@ case "$SUBCOMMAND" in
147145
echo " including the runtime set within it"
148146
echo " scaffold <language> [runtime] Initializes a new runtime"
149147
echo " test <runtime> Runs unit tests on the given runtime"
148+
echo " test-dev <runtime> Same as test, but using the development container and volume"
150149
echo " Optionally set runtime to --all to test all"
151150
echo " NOTE: This is only for the runtimes contained"
152151
echo " within this repo"

0 commit comments

Comments
 (0)