Skip to content

Commit 0eecf70

Browse files
authored
build: reintroduces namespacing for jormungandr/vitss (#173)
2 parents 74cae50 + 3558fc8 commit 0eecf70

File tree

10 files changed

+144
-133
lines changed

10 files changed

+144
-133
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
shell-profile-5-link
1+
shell-profile-14-link

flake.lock

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
66

77
## Std ##
8-
std.url = "github:divnix/std";
8+
std.url = "github:divnix/std/target-in-actions";
99
std.inputs.nixpkgs.follows = "nixpkgs";
1010

1111
# Rust overlay

nix/artifacts/artifacts.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
cell,
44
}: let
55
inherit (inputs) nixpkgs std;
6-
inherit (inputs.cells.lib) constants;
6+
inherit (inputs.cells.lib) lib;
77
l = nixpkgs.lib // builtins;
88

99
mkArtifact = namespace:
@@ -16,4 +16,4 @@
1616
'';
1717
};
1818
in
19-
constants.mapToNamespaces {prefix = "artifacts";} mkArtifact
19+
lib.mapToNamespaces "artifacts" mkArtifact

nix/jormungandr/containers.nix

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
cell,
44
}: let
55
inherit (inputs) nixpkgs std;
6-
inherit (inputs.cells.lib) constants;
6+
inherit (inputs.cells.lib) constants lib;
77
l = nixpkgs.lib // builtins;
88

9-
mkOCI = name: let
10-
operable = cell.operables.${name};
9+
mkOCI = namespace: let
10+
# TODO: fix git rev
11+
rev =
12+
if (inputs.self.rev != "not-a-commit")
13+
then inputs.self.rev
14+
else "dirty";
1115
in
1216
std.lib.ops.mkStandardOCI {
13-
inherit operable;
14-
name = "${constants.registry}/${name}";
17+
name = "${constants.registry}/jormungandr";
18+
tag = "${rev}-${namespace}";
19+
operable = cell.operables."jormungandr-${namespace}";
1520
debug = true;
1621
};
17-
in {
18-
jormungandr = mkOCI "jormungandr";
19-
}
22+
in
23+
{}
24+
// lib.mapToNamespaces "jormungandr" mkOCI

nix/jormungandr/operables.nix

Lines changed: 59 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,67 @@
44
}: let
55
inherit (inputs) nixpkgs std;
66
inherit (inputs.cells.artifacts) artifacts;
7-
inherit (inputs.cells.lib) constants;
7+
inherit (inputs.cells.lib) lib;
88
l = nixpkgs.lib // builtins;
99

1010
package = cell.packages.jormungandr;
11-
in {
12-
jormungandr = std.lib.ops.mkOperable {
13-
inherit package;
14-
# TODO: Remove all the bitte stuff
15-
# TODO: update artifact path to correct mount path
16-
runtimeScript = ''
17-
ulimit -n 1024
1811

19-
nodeConfig="$NOMAD_TASK_DIR/node-config.json"
20-
runConfig="$NOMAD_TASK_DIR/running.json"
21-
runYaml="$NOMAD_TASK_DIR/running.yaml"
22-
23-
chmod u+rwx -R "$NOMAD_TASK_DIR" || true
24-
25-
function convert () {
12+
mkOperable = namespace: let
13+
artifacts' = artifacts."artifacts-${namespace}";
14+
in
15+
std.lib.ops.mkOperable {
16+
inherit package;
17+
# TODO: Remove all the bitte stuff
18+
runtimeScript = ''
19+
ulimit -n 1024
20+
nodeConfig="$NOMAD_TASK_DIR/node-config.json"
21+
runConfig="$NOMAD_TASK_DIR/running.json"
22+
runYaml="$NOMAD_TASK_DIR/running.yaml"
2623
chmod u+rwx -R "$NOMAD_TASK_DIR" || true
27-
cp "$nodeConfig" "$runConfig"
28-
remarshal --if json --of yaml "$runConfig" > "$runYaml"
29-
}
30-
31-
if [ "$RESET" = "true" ]; then
32-
echo "RESET is given, will start from scratch..."
33-
rm -rf "$STORAGE_DIR"
34-
elif [ -d "$STORAGE_DIR" ]; then
35-
echo "$STORAGE_DIR found, not restoring from backup..."
36-
else
37-
echo "$STORAGE_DIR not found, restoring backup..."
38-
39-
restic restore latest \
40-
--verbose=5 \
41-
--no-lock \
42-
--tag "$NAMESPACE" \
43-
--target / \
44-
|| echo "couldn't restore backup, continue startup procedure..."
45-
fi
46-
47-
set +x
48-
echo "waiting for $REQUIRED_PEER_COUNT peers"
49-
until [ "$(jq -e -r '.p2p.trusted_peers | length' < "$nodeConfig" || echo 0)" -ge "$REQUIRED_PEER_COUNT" ]; do
50-
sleep 1
51-
done
52-
set -x
53-
54-
convert
55-
56-
if [ -n "$PRIVATE" ]; then
57-
echo "Running with node with secrets..."
58-
exec ${l.getExe package} \
59-
--storage "$STORAGE_DIR" \
60-
--config "$NOMAD_TASK_DIR/running.yaml" \
61-
--genesis-block "artifacts/block0.bin" \
62-
--secret "$NOMAD_SECRETS_DIR/bft-secret.yaml" \
63-
"$@" || true
64-
else
65-
echo "Running with follower node..."
66-
exec ${l.getExe package} \
67-
--storage "$STORAGE_DIR" \
68-
--config "$NOMAD_TASK_DIR/running.yaml" \
69-
--genesis-block "artifacts/block0.bin" \
70-
"$@" || true
71-
fi
72-
'';
73-
};
74-
}
24+
function convert () {
25+
chmod u+rwx -R "$NOMAD_TASK_DIR" || true
26+
cp "$nodeConfig" "$runConfig"
27+
remarshal --if json --of yaml "$runConfig" > "$runYaml"
28+
}
29+
if [ "$RESET" = "true" ]; then
30+
echo "RESET is given, will start from scratch..."
31+
rm -rf "$STORAGE_DIR"
32+
elif [ -d "$STORAGE_DIR" ]; then
33+
echo "$STORAGE_DIR found, not restoring from backup..."
34+
else
35+
echo "$STORAGE_DIR not found, restoring backup..."
36+
restic restore latest \
37+
--verbose=5 \
38+
--no-lock \
39+
--tag "$NAMESPACE" \
40+
--target / \
41+
|| echo "couldn't restore backup, continue startup procedure..."
42+
fi
43+
set +x
44+
echo "waiting for $REQUIRED_PEER_COUNT peers"
45+
until [ "$(jq -e -r '.p2p.trusted_peers | length' < "$nodeConfig" || echo 0)" -ge "$REQUIRED_PEER_COUNT" ]; do
46+
sleep 1
47+
done
48+
set -x
49+
convert
50+
if [ -n "$PRIVATE" ]; then
51+
echo "Running with node with secrets..."
52+
exec ${l.getExe package} \
53+
--storage "$STORAGE_DIR" \
54+
--config "$NOMAD_TASK_DIR/running.yaml" \
55+
--genesis-block "${artifacts'}/block0.bin" \
56+
--secret "$NOMAD_SECRETS_DIR/bft-secret.yaml" \
57+
"$@" || true
58+
else
59+
echo "Running with follower node..."
60+
exec ${l.getExe package} \
61+
--storage "$STORAGE_DIR" \
62+
--config "$NOMAD_TASK_DIR/running.yaml" \
63+
--genesis-block "${artifacts'}/block0.bin" \
64+
"$@" || true
65+
fi
66+
'';
67+
};
68+
in
69+
{}
70+
// lib.mapToNamespaces "jormungandr" mkOperable

nix/lib/constants.nix

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,33 @@
44
}: let
55
inherit (inputs) nixpkgs;
66
l = nixpkgs.lib // builtins;
7+
in rec {
8+
# The current funding round we are in
9+
fundRound = 10;
10+
11+
# The current SVE round we are in
12+
sveRound = 2;
713

14+
# List of target environments we generate artifacts for
815
envs = [
916
"dev"
1017
"signoff"
1118
"perf"
1219
"dryrun"
1320
"prod"
1421
];
15-
events = [
16-
"fund10"
17-
"sve1"
18-
"sve2"
19-
];
2022

21-
mkNamespaces = event: l.map (env: "${event}-${env}") envs;
22-
in rec {
23-
inherit envs events;
24-
namespaces = l.flatten (l.map (event: mkNamespaces event) events);
25-
registry = "432820653916.dkr.ecr.eu-central-1.amazonaws.com";
23+
# A list of all possible round/namespace combinations
24+
# fund10-dev, fund10-dryrun, sve2-signoff, sve2-prod, etc.
25+
namespaces = let
26+
events = [
27+
"fund${l.toString fundRound}"
28+
"sve${l.toString sveRound}"
29+
];
30+
mkNamespaces = event: l.map (env: "${event}-${env}") envs;
31+
in
32+
l.flatten (l.map (event: mkNamespaces event) events);
2633

27-
mapToNamespaces = {
28-
prefix ? "",
29-
suffix ? "",
30-
}: fn:
31-
l.listToAttrs (
32-
l.map
33-
(
34-
namespace: {
35-
name =
36-
if prefix != ""
37-
then
38-
if suffix != ""
39-
then "${prefix}-${namespace}-${suffix}"
40-
else "${prefix}-${namespace}"
41-
else "${namespace}";
42-
value = fn namespace;
43-
}
44-
)
45-
namespaces
46-
);
34+
# The OCI registry we are pushing to
35+
registry = "432820653916.dkr.ecr.eu-central-1.amazonaws.com";
4736
}

nix/lib/lib.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
cell,
44
}: let
55
inherit (inputs) nixpkgs std;
6+
inherit (inputs.cells.lib) constants;
67
inherit (cell.toolchains) naersk rustToolchain;
78
l = nixpkgs.lib // builtins;
89
in rec {
@@ -114,4 +115,19 @@ in rec {
114115
openssl
115116
];
116117
};
118+
119+
# Maps a function to all possible namespaces, returning results of the
120+
# function calls as an attribute set where the key is `{service}-{namespace}`
121+
# and the value is the function result.
122+
mapToNamespaces = service: fn:
123+
l.listToAttrs (
124+
l.map
125+
(
126+
namespace: {
127+
name = "${service}-${namespace}";
128+
value = fn namespace;
129+
}
130+
)
131+
constants.namespaces
132+
);
117133
}

nix/vit-servicing-station/containers.nix

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
cell,
44
}: let
55
inherit (inputs) nixpkgs std;
6-
inherit (inputs.cells.lib) constants;
6+
inherit (inputs.cells.lib) constants lib;
77
l = nixpkgs.lib // builtins;
88

9-
mkOCI = name: let
10-
operable = cell.operables.${name};
9+
mkOCI = namespace: let
10+
# TODO: fix git rev
11+
rev =
12+
if (inputs.self.rev != "not-a-commit")
13+
then inputs.self.rev
14+
else "dirty";
1115
in
1216
std.lib.ops.mkStandardOCI {
13-
inherit operable;
14-
name = "${constants.registry}/${name}";
17+
name = "${constants.registry}/vit-servicing-station-server";
18+
tag = "${rev}-${namespace}";
19+
operable = cell.operables."vit-servicing-station-server-${namespace}";
1520
debug = true;
1621
};
17-
in {
18-
vit-servicing-station-server = mkOCI "vit-servicing-station-server";
19-
}
22+
in
23+
{}
24+
// lib.mapToNamespaces "vit-servicing-station-server" mkOCI

nix/vit-servicing-station/operables.nix

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44
}: let
55
inherit (inputs) nixpkgs std;
66
inherit (inputs.cells.artifacts) artifacts;
7-
inherit (inputs.cells.lib) constants;
7+
inherit (inputs.cells.lib) lib;
88
l = nixpkgs.lib // builtins;
99

10-
mkSimpleOperable = {
11-
name,
12-
runtimeInputs ? [],
13-
args ? [],
14-
}: let
15-
package = cell.packages.${name};
10+
package = cell.packages.vit-servicing-station-server;
11+
12+
mkVitOperable = namespace: let
13+
artifacts' = artifacts."artifacts-${namespace}";
1614
in
1715
std.lib.ops.mkOperable {
18-
inherit package runtimeInputs;
16+
inherit package;
17+
runtimeInputs = [
18+
artifacts'
19+
];
1920
runtimeScript = std.lib.ops.mkOperableScript {
20-
inherit args package;
21+
inherit package;
22+
args = {
23+
"--in-settings-file" = "/local/station-config.json";
24+
};
2125
};
2226
};
23-
in {
24-
vit-servicing-station-server = mkSimpleOperable {
25-
name = "vit-servicing-station-server";
26-
args = {
27-
"--in-settings-file" = "/local/station-config.json";
28-
};
29-
};
30-
}
27+
in
28+
{}
29+
// lib.mapToNamespaces "vit-servicing-station-server" mkVitOperable

0 commit comments

Comments
 (0)