-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
buildkite.nix
158 lines (128 loc) · 4.47 KB
/
buildkite.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
let
channel = "nixpkgs=channel:nixos-unstable-small";
devices = let
raw_data = builtins.fromJSON (builtins.readFile ./devices.json);
is_interesting = device: (
(builtins.elem "hydra" device.tags)
&& (device.operating_system.slug == "custom_ipxe")
);
in
builtins.filter is_interesting raw_data.devices;
env = {
NIX_PATH = "nixpkgs=https://nixos.org/channels/nixos-20.09/nixexprs.tar.xz";
};
buildId = { platform } @ args: "build-${builtins.replaceStrings [ "." ] [ "-" ] (sourceSlug args) }";
sourceSlug = { platform }:
"${platform}";
toBuildUrl = { platform }:
"https://netboot.gsc.io/hydra-${sourceSlug { inherit platform; }}/netboot.ipxe";
mkBuildStep = { platform }: {
id = buildId { inherit platform; };
label = "build: ${sourceSlug { inherit platform; }}";
command = ''
set -eux
export NIX_PATH=${channel}
./enter-env.sh ./build-${platform}.sh ${sourceSlug { inherit platform; }}
'';
inherit env;
agents.nixos-foundation-netboot = true;
concurrency = 1;
concurrency_group = "build-${platform}-pxe";
concurrency_method = "eager";
};
mkDrainStep = device: { platform, ... } @ info: {
id = "drain-${device.id}";
depends_on = buildId { inherit platform; };
label = "drain: ${sourceSlug { inherit platform; }} -- ${device.plan.slug} -- ${device.facility.code} -- ${device.id}";
command = let
dns_target = device.short_id + ".packethost.net";
in
''
set -eux
export NIX_PATH=${channel}
./enter-env.sh ./drain.sh ${device.id} ${dns_target} ${device.id}@sos.${device.facility.code}.packet.net
'';
inherit env;
agents.nixos-foundation-netboot = true;
concurrency = 4;
concurrency_group = "reboot-${sourceSlug { inherit platform; } }";
concurrency_method = "eager";
};
mkRebootStep = device: { platform, ... } @ info: {
id = "reboot-${device.id}";
depends_on = "drain-${device.id}";
label = "reboot: ${sourceSlug { inherit platform; }} -- ${device.plan.slug} -- ${device.facility.code} -- ${device.id}";
command = let
dns_target = device.short_id + ".packethost.net";
in
''
set -eux
export NIX_PATH=${channel}
if ! ./enter-env.sh ./reboot.sh ${device.id} ${dns_target} ${device.id}@sos.${device.facility.code}.packet.net; then
cat ./buildkite-terminate.yml | sed -e 's/DEVICE_ID/${device.id}/g' > terminate.yml
buildkite-agent pipeline upload terminate.yml
fi
'';
inherit env;
retry.automatic = [
{
exit_status = 10;
limit = 2;
}
];
agents.nixos-foundation-netboot = true;
concurrency = 4;
concurrency_group = "reboot-${sourceSlug { inherit platform; } }";
concurrency_method = "eager";
};
mkRestoreStep = device: { platform, ... } @ info: {
id = "restore-${device.id}";
depends_on = "reboot-${device.id}";
label = "restore: ${sourceSlug { inherit platform; }} -- ${device.plan.slug} -- ${device.facility.code} -- ${device.id}";
command = let
dns_target = device.short_id + ".packethost.net";
in
''
set -eux
export NIX_PATH=${channel}
./enter-env.sh ./restore.sh ${device.id} ${dns_target} ${device.id}@sos.${device.facility.code}.packet.net
'';
inherit env;
agents.nixos-foundation-netboot = true;
concurrency = 4;
concurrency_group = "reboot-${sourceSlug { inherit platform; } }";
concurrency_method = "eager";
};
to_build = [
{ platform = "x86_64-linux"; }
{ platform = "aarch64-linux"; }
];
in
{
dag = true;
steps = let
build_steps = map mkBuildStep to_build;
reboot_steps = let
plan_urls = map (todo: { inherit (todo) platform; url = toBuildUrl todo; })
to_build;
arch_by_url = builtins.listToAttrs (
map (todo: { name = todo.url; value = { inherit (todo) platform; }; })
plan_urls
);
interesting_urls = builtins.attrNames arch_by_url;
devices_to_reboot = builtins.filter
(device: builtins.elem device.ipxe_script_url interesting_urls)
devices;
in
(
builtins.concatMap (
device: [
(mkDrainStep device arch_by_url."${device.ipxe_script_url}")
(mkRebootStep device arch_by_url."${device.ipxe_script_url}")
(mkRestoreStep device arch_by_url."${device.ipxe_script_url}")
]
) devices_to_reboot
);
in
build_steps ++ reboot_steps;
}