Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add screen-recording script for vagrant-demo #9

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
go.work

.direnv
.vagrant
debug.log
result
/examples/vagrant-demo/.vagrant
/labcoat
/examples/vagrant-demo/labcoat
/examples/vagrant-demo/*.mp4
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ know if your configuration works correctly.
For production NixOS environments with many instances of the same configuration,
you will be better served by a parallel deployment tool such as [Colmena].

![Demo Screencast](/examples/vagrant-demo/demo.gif)


## Features

Expand Down
53 changes: 53 additions & 0 deletions examples/vagrant-demo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
SHELL = /bin/sh
.PHONY = build clean destroy prepare

configs = flake.nix
srcs = demo.tape
tapes = $(srcs:.tape=.mp4)

db_ip = 192.168.33.10
web_ip = 192.168.33.11
host_ips = $(db_ip) $(web_ip)

all: clean build

clean:
git restore $(configs)
rm -f labcoat $(tapes)
nixos-rebuild \
--flake ".#db-lab" \
--target-host root@$(db_ip) \
--build-host localhost switch
ssh root@$(db_ip) nix-collect-garbage -d || true

destroy:
vagrant destroy --force
for ip in $(host_ips); do \
ssh-keygen -R $$ip; \
done

prepare:
git restore $(configs)
vagrant up
ssh-keyscan $(host_ips) >> $$HOME/.ssh/known_hosts
nixos-rebuild \
--flake ".#db-lab" \
--target-host root@$(db_ip) \
--build-host localhost boot
# Kernel upgrade, reboot.
ssh root@$(db_ip) reboot || true
nixos-rebuild \
--flake ".#web-lab" \
--target-host root@$(web_ip) \
--build-host localhost boot
# Kernel upgrade, reboot.
ssh root@$(web_ip) reboot || true

build: labcoat $(tapes)

labcoat:
go build ../..

%.mp4: %.tape
vhs $<
git restore $(configs)
18 changes: 18 additions & 0 deletions examples/vagrant-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# vagrant-demo

Used to generated screen recordings of labcoat.

## Usage

Warning: The `Makefile` will make changes to your SSH `known_hosts` file.

```sh
# Setup VMs
make prepare

# Generate recordings
make

# Teardown VMs
make destroy
```
Binary file added examples/vagrant-demo/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions examples/vagrant-demo/demo.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
Output demo.gif

Set Width 1600
Set Height 850
Set WindowBar Colorful
Set FontSize 14
Set PlaybackSpeed 0.75

Set Shell fish

# Show off UI.
Sleep 500ms
Type "./labcoat -config labcoat-config.toml"
Enter
Sleep 5s
Type "j"
Sleep 3s
Type "j"
Sleep 3s
Type "j"
Sleep 3s
Type "/"
Sleep 1s
Type "lab"
Sleep 500ms
Enter
Sleep 1.5s
Type "fd"
Sleep 3s
Type "!"
Sleep 500ms
Type "systemctl status "
Sleep 500ms
Type "postgresql"
Sleep 1.5s
Enter
Sleep 3.5s
Type "q"
Sleep 2s

# Add PostgreSQL to db-lab config.
Type "vim flake.nix"
Enter
Sleep 3s
Type "/d"
Sleep 500ms
Type "b-lab"
Sleep 1.5s
Enter
Sleep 500ms
Type "zz"
Sleep 1.5s
Type "jjo"
Sleep 500ms
Type "{ services.postgresql.enable"
Sleep 200ms
Type " = true; }"
Sleep 500ms
Escape
Type ":wq"
Sleep 500ms
Enter
Sleep 2s

# Deploy db-lab.
Up
Up
Sleep 500ms
Enter
Sleep 3s
Type "d"
Sleep 10.5s
Type "s"
Sleep 2.5s
Type "!systemctl status "
Sleep 200ms
Type "postgresql"
Enter
Sleep 3s

# SSH demo.
Type "i"
Sleep 2s
Type "# <<< on the db-lab host; one touch SSH!"
Enter
Sleep 1s
Type "su - postgres"
Enter
Sleep 500ms
Type "psql"
Enter
Sleep 1s
Type "\conninfo"
Enter
Sleep 2s
Type "\q"
Enter
Ctrl+D
Sleep 500ms
Ctrl+D
Sleep 3s
Tab
Sleep 3s
Tab
Sleep 3s
Tab
Sleep 3s
Tab
Sleep 5s
19 changes: 19 additions & 0 deletions examples/vagrant-demo/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@
(networkModule { hostName = "web-lab"; ipAddr = "192.168.33.11"; })
];
};

# Fake systems to pad the labcoat host list.
fake-host-1 = lib.nixosSystem {
system = "x86_64-linux";
modules = [
commonModule
./hardware-configuration.nix
(networkModule { hostName = "fake-host-1"; ipAddr = "192.168.33.11"; })
];
};

fake-host-2 = lib.nixosSystem {
system = "x86_64-linux";
modules = [
commonModule
./hardware-configuration.nix
(networkModule { hostName = "fake-host-2"; ipAddr = "192.168.33.10"; })
];
};
};
};
}
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" ];

perSystem = { config, self', inputs', pkgs, system, ... }:
perSystem = { self', pkgs, ... }:
let
# Generate a user-friendly version number.
version = builtins.substring 0 8 self.lastModifiedDate;
Expand All @@ -37,6 +37,7 @@
go_1_22
golint
gopls
vhs
];

hardeningDisable = [ "fortify" ];
Expand Down