-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpipelight.old.ts
More file actions
156 lines (143 loc) · 4.08 KB
/
Copy pathpipelight.old.ts
File metadata and controls
156 lines (143 loc) · 4.08 KB
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
import type { Config } from "https://deno.land/x/pipelight/mod.ts";
import { Mode, pipeline, step } from "https://deno.land/x/pipelight/mod.ts";
// Binaries
const bin = {
test: "cargo run --bin virshle",
default: "virshle",
};
const test = pipeline("test", () => [
step("build nixos iso file", () => [
"pipelight run create_env --attach",
// "pipelight run create_luks --attach",
// "pipelight run test_templates --attach",
]),
]).detach();
/**
* Build raw-efi image
*
*/
const create_env = pipeline("build_image", () => [
step("build crocuda nixos standard images", () => [
// "nix flake update ~/Fast/nixos/general",
"nix build \
~/Fast/nixos/general/#vm.iso \
--override-input crocuda \
~/Fast/nixos/crocuda.nixos",
"cp ~/Fast/nixos/general/result/nixos.img \
~/Iso/nixos.efi.img",
]),
]);
/**
* Build pipelight init raw image
*/
const create_init = pipeline("create_init", () => [
step("create files", () => [
"dd if=/dev/null of=./scripts/pipelight-init.img bs=1M seek=10",
"mkfs.ext4 -F -L INIT ./scripts/pipelight-init.img",
"mkdir -p ./scripts/mnt/pipelight-init",
"mount -t ext4 -o loop ./scripts/pipelight-init.img ./scripts/mnt/pipelight-init",
"cp -r /pipelight-init/.* ./scripts/mnt/pipelight-init",
"cp -r /pipelight-init/* ./scripts/mnt/pipelight-init",
"umount ./scripts/mnt/pipelight-init",
]),
]).detach();
const create_luks = pipeline("create_luks", () => [
step("encrypt root", () => [
`qemu-img create \
-f qcow2 \
--object secret,id=password,data=abc123 \
-o encrypt.format=luks,encrypt.key-secret=password \
./iso/encrypted.qcow2 50G`,
// Copy and encrypt device
`qemu-img convert \
--object secret,id=password,data=abc123 \
--image-opts driver=qcow2,file.filename=./iso/nixos.qcow2 \
--target-image-opts driver=qcow2,encrypt.key-secret=password,file.filename=./iso/encrypted.qcow2 \
-n -p`,
]).set_mode(Mode.JumpNextOnFailure),
]);
/**
* Create template network and vm
*/
const test_templates = pipeline("test_templates", () => [
step("delete existing testing resources", () => [
`${bin.test} net rm \
default_6`,
`${bin.test} vm rm \
vm-nixos`,
]).set_mode(Mode.JumpNextOnFailure),
step("ensure network", () => [
`${bin.test} create \
./templates/net/base.toml -vvv`,
]),
step("create vm", () => [
`${bin.test} create \
./templates/vm/base.toml -vvv`,
]),
]);
/**
* Create empty template volume with standard sizes
*/
const generate_standard_empty_volumes = pipeline(
"generate_standard_empty_volumes",
() => {
const dir = "~/.libvirt/volumes/standard";
const steps = [step(`ensure storage directory`, () => [`mkdir -p ${dir}`])];
const sizes = [
{
count: "20",
unit: "M",
},
{
count: "10",
unit: "G",
},
];
for (const { count, unit } of sizes) {
steps.push(
step(`create empty storage volume of ${count}${unit}`, () => [
`dd if=/dev/zero of=${dir}/${count}${unit}.img bs=1${unit} count=${count}`,
]),
);
}
return steps;
},
).log_level("info");
/**
* Create a cdrom volume
* with the pipelight-init data inside
*/
const make_ci_vol = pipeline("make_ci_vol", () => [
// step("create user-data iso file", () => [
// `genisoimage \
// -output ./iso/pipelight-init.img \
// -volid pipelight-init -rational-rock -joliet \
// ./base/pipelight-init`,
// ]),
step("create user-data iso file", () => [
`virt-make-fs \
--partition=gpt \
./base/pipelight-init/ ./iso/pipelight-init.img`,
]),
]);
const clean_env = pipeline("clean_env", () => [
step("delete vm(domain)", () => [`${bin.test} vm delete vm-nixos -vvv`]),
step("delete network", () => [`${bin.test} net remove default_6 -vvv`]),
]);
const config = {
options: {
attach: false,
log_level: "info",
},
pipelines: [
test,
test_templates,
create_init,
create_env,
create_luks,
make_ci_vol,
clean_env,
generate_standard_empty_volumes,
],
};
export default config;