Skip to content

Commit 9083a86

Browse files
authored
build: migrates cache (#171)
2 parents 2d171dd + 1b99f41 commit 9083a86

File tree

7 files changed

+105
-94
lines changed

7 files changed

+105
-94
lines changed

.github/workflows/nix.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ concurrency:
2626
group: ${{ github.sha }}
2727
cancel-in-progress: true
2828

29+
env:
30+
ECR_REGISTRY: 432820653916.dkr.ecr.eu-central-1.amazonaws.com
31+
S3_CACHE: s3://iog-catalyst-nix-cache?region=eu-central-1
32+
2933
jobs:
3034
discover:
3135
outputs:
@@ -47,11 +51,13 @@ jobs:
4751
name: ${{ matrix.target.cell }} - ${{ matrix.target.name }}
4852
runs-on: ubuntu-latest
4953
steps:
50-
- run: |
51-
config="$HOME/.docker/config.json"
52-
mkdir -p "${config%/*}"
53-
jq -n --arg token "${{ secrets.DOCKER_AUTH_TOKEN }}" '{ "auths": { "registry.ci.iog.io": { auth: $token } } }' > "$config"
54-
chmod 0600 "$config"
54+
- name: Configure Registry
55+
run: |
56+
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin "${{ env.ECR_REGISTRY }}"
57+
env:
58+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
59+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
60+
AWS_DEFAULT_REGION: eu-central-1
5561
- uses: divnix/std-action/run@main
5662
with:
5763
extra_nix_config: |
@@ -60,7 +66,7 @@ jobs:
6066
nix_key: ${{ secrets.NIX_SIGNING_KEY }}
6167
s3_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
6268
s3_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
63-
cache: s3://iog-catalyst-cache?region=eu-central-1
69+
cache: ${{ env.S3_CACHE }}
6470
build-packages:
6571
if: always()
6672
needs:
@@ -81,7 +87,7 @@ jobs:
8187
nix_key: ${{ secrets.NIX_SIGNING_KEY }}
8288
s3_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
8389
s3_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
84-
cache: s3://iog-catalyst-cache?region=eu-central-1
90+
cache: ${{ env.S3_CACHE }}
8591
build-devshells:
8692
if: always()
8793
needs:
@@ -102,4 +108,4 @@ jobs:
102108
nix_key: ${{ secrets.NIX_SIGNING_KEY }}
103109
s3_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
104110
s3_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
105-
cache: s3://iog-catalyst-cache?region=eu-central-1
111+
cache: ${{ env.S3_CACHE }}

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
nixConfig = {
7676
extra-substituters = [
7777
"https://cache.iog.io"
78-
"https://iog-catalyst-cache.s3.eu-central-1.amazonaws.com"
78+
"https://iog-catalyst-nix-cache.s3.eu-central-1.amazonaws.com"
7979
];
8080
extra-trusted-public-keys = [
8181
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="

nix/jormungandr/containers.nix

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
inherit (inputs.cells.lib) constants;
77
l = nixpkgs.lib // builtins;
88

9-
mkOCI = name: namespace:
9+
mkOCI = name: let
10+
operable = cell.operables.${name};
11+
in
1012
std.lib.ops.mkStandardOCI {
11-
name = "${constants.registry}/${name}-${namespace}";
12-
operable = cell.operables."${name}-${namespace}";
13+
inherit operable;
14+
name = "${constants.registry}/${name}";
1315
debug = true;
1416
};
15-
in
16-
{}
17-
// constants.mapToNamespaces {prefix = "jormungandr";} (mkOCI "jormungandr")
17+
in {
18+
jormungandr = mkOCI "jormungandr";
19+
}

nix/jormungandr/operables.nix

Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,68 @@
77
inherit (inputs.cells.lib) constants;
88
l = nixpkgs.lib // builtins;
99

10-
mkOperable = package: namespace: let
11-
artifacts' = artifacts."artifacts-${namespace}";
12-
in
13-
std.lib.ops.mkOperable {
14-
inherit package;
15-
# TODO: Remove all the bitte stuff
16-
runtimeScript = ''
17-
ulimit -n 1024
10+
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
1818
19-
nodeConfig="$NOMAD_TASK_DIR/node-config.json"
20-
runConfig="$NOMAD_TASK_DIR/running.json"
21-
runYaml="$NOMAD_TASK_DIR/running.yaml"
19+
nodeConfig="$NOMAD_TASK_DIR/node-config.json"
20+
runConfig="$NOMAD_TASK_DIR/running.json"
21+
runYaml="$NOMAD_TASK_DIR/running.yaml"
2222
23-
chmod u+rwx -R "$NOMAD_TASK_DIR" || true
23+
chmod u+rwx -R "$NOMAD_TASK_DIR" || true
2424
25-
function convert () {
26-
chmod u+rwx -R "$NOMAD_TASK_DIR" || true
27-
cp "$nodeConfig" "$runConfig"
28-
remarshal --if json --of yaml "$runConfig" > "$runYaml"
29-
}
25+
function convert () {
26+
chmod u+rwx -R "$NOMAD_TASK_DIR" || true
27+
cp "$nodeConfig" "$runConfig"
28+
remarshal --if json --of yaml "$runConfig" > "$runYaml"
29+
}
3030
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..."
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..."
3838
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
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
4646
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
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
5353
54-
convert
54+
convert
5555
56-
if [ -n "$PRIVATE" ]; then
57-
echo "Running with node with secrets..."
58-
exec jormungandr \
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 jormungandr \
67-
--storage "$STORAGE_DIR" \
68-
--config "$NOMAD_TASK_DIR/running.yaml" \
69-
--genesis-block "${artifacts'}/block0.bin" \
70-
"$@" || true
71-
fi
72-
'';
73-
};
74-
in
75-
{}
76-
// constants.mapToNamespaces {prefix = "jormungandr";} (mkOperable cell.packages.jormungandr)
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+
}

nix/lib/constants.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
in rec {
2323
inherit envs events;
2424
namespaces = l.flatten (l.map (event: mkNamespaces event) events);
25-
registry = "registry.ci.iog.io";
25+
registry = "432820653916.dkr.ecr.eu-central-1.amazonaws.com";
2626

2727
mapToNamespaces = {
2828
prefix ? "",

nix/vit-servicing-station/containers.nix

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
inherit (inputs.cells.lib) constants;
77
l = nixpkgs.lib // builtins;
88

9-
mkOCI = name: namespace:
9+
mkOCI = name: let
10+
operable = cell.operables.${name};
11+
in
1012
std.lib.ops.mkStandardOCI {
11-
name = "${constants.registry}/${name}-${namespace}";
12-
operable = cell.operables."${name}-${namespace}";
13+
inherit operable;
14+
name = "${constants.registry}/${name}";
1315
debug = true;
1416
};
15-
in
16-
{}
17-
// constants.mapToNamespaces {prefix = "vit-servicing-station-server";} (mkOCI "vit-servicing-station-server")
17+
in {
18+
vit-servicing-station-server = mkOCI "vit-servicing-station-server";
19+
}

nix/vit-servicing-station/operables.nix

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@
77
inherit (inputs.cells.lib) constants;
88
l = nixpkgs.lib // builtins;
99

10-
mkVitOperable = package: namespace: let
11-
artifacts' = artifacts."artifacts-${namespace}";
10+
mkSimpleOperable = {
11+
name,
12+
runtimeInputs ? [],
13+
args ? [],
14+
}: let
15+
package = cell.packages.${name};
1216
in
1317
std.lib.ops.mkOperable {
14-
inherit package;
15-
runtimeInputs = [
16-
artifacts'
17-
];
18+
inherit package runtimeInputs;
1819
runtimeScript = std.lib.ops.mkOperableScript {
19-
inherit package;
20-
args = {
21-
"--in-settings-file" = "/local/station-config.json";
22-
};
20+
inherit args package;
2321
};
2422
};
25-
in
26-
{}
27-
// constants.mapToNamespaces {prefix = "vit-servicing-station-server";} (mkVitOperable cell.packages.vit-servicing-station-server)
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+
}

0 commit comments

Comments
 (0)