-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
330 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Development in a vm | ||
:copyright: Copyright (c) 2023 RadiaSoft LLC. All Rights Reserved. | ||
:license: http://www.apache.org/licenses/LICENSE-2.0.html | ||
""" | ||
from pykern import pkconfig | ||
from pykern import pkio | ||
from pykern.pkcollections import PKDict | ||
from pykern.pkdebug import pkdp | ||
from rsconf import component | ||
from rsconf import systemd | ||
|
||
_VM_DIR = "v" | ||
|
||
|
||
class T(component.T): | ||
def internal_build_compile(self): | ||
jc, z = self.j2_ctx_init() | ||
if "user_name" not in self: | ||
for u in self.hdb.vm_devbox.users: | ||
self.buildt.build_component( | ||
T( | ||
f"{self.name}_{u}", | ||
self.buildt, | ||
user_name=u, | ||
module_name=self.name, | ||
) | ||
) | ||
return | ||
self.buildt.require_component("network") | ||
z.vm_d = systemd.custom_unit_prepare(self, self.j2_ctx).join(_VM_DIR) | ||
z.ssh_port = jc.base_users.spec[self.user_name].vm_devbox_ssh_port | ||
z.ssh_guest_host_key_f = "/etc/ssh/host_key" | ||
z.ssh_guest_identity_pub_f = "/etc/ssh/identity.pub" | ||
self._network(jc, z) | ||
self._ssh(jc, z) | ||
|
||
def internal_build_write(self): | ||
jc = self.j2_ctx | ||
if "user_name" not in self: | ||
self.append_root_bash_with_main(jc) | ||
return | ||
z = jc[self.module_name] | ||
systemd.install_unit_override(self, self.j2_ctx) | ||
systemd.custom_unit_enable( | ||
self, self.j2_ctx, run_u=jc.rsconf_db.run_u, run_group=jc.rsconf_db.run_u | ||
) | ||
self.install_access(mode="700", owner=jc.rsconf_db.run_u) | ||
self.install_directory(z.vm_d) | ||
|
||
def _network(self, jc, z): | ||
n = self.buildt.get_component("network") | ||
n.add_public_tcp_ports([str(z.ssh_port)]) | ||
|
||
def _ssh(self, jc, z): | ||
z.sshd_config_f = z.vm_d.join("sshd_config") | ||
s = super().gen_identity_and_host_ssh_keys(jc, "host", encrypt_identity=True) | ||
z.pkupdate( | ||
PKDict( | ||
ssh_identity_pub_key=pkio.read_text(s["identity_pub_f"]), | ||
ssh_host_key=pkio.read_text(s["host_key_f"]), | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
vm_devbox_main() { | ||
if vagrant --version > /dev/null 2>&1; then | ||
return | ||
fi | ||
declare p=kernel-devel-$(uname -r) | ||
if ! yum list "$p" &> /dev/null; then | ||
install_err "rpm $p not found. | ||
Virtualbox needs the kernel-devel rpm for the host kernel to be installed. | ||
Maybe try updating the kernel? The repos only have kernel-devel for recent versions of the kernel." | ||
fi | ||
rsconf_yum_install "$p" | ||
yum-config-manager --add-repo https://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo | ||
yum makecache -y | ||
rsconf_yum_install VirtualBox-7.0 | ||
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo | ||
rsconf_yum_install vagrant | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/bin/bash | ||
set -eou pipefail | ||
|
||
vm_devbox_first_start() { | ||
if [[ -e Vagrantfile ]]; then | ||
return | ||
fi | ||
# Put vms in this dir so we don't scatter them around the machine. | ||
# The default is under $HOME which doesn't make sense for this kind | ||
# of service. | ||
declare d=virtualbox_vms | ||
mkdir "$d" | ||
vboxmanage setproperty machinefolder "$PWD/$d" | ||
curl https://radia.run | vagrant_dev_private_net= \ | ||
vagrant_dev_provision_eth1= \ | ||
vagrant_dev_no_mounts=1 \ | ||
vagrant_dev_no_nfs_src=1 \ | ||
vagrant_dev_no_vbguest=1 \ | ||
bash -s vagrant-sirepo-dev | ||
vboxmanage setproperty machinefolder default | ||
} | ||
|
||
vm_devbox_set_forwarded_port() { | ||
declare r= | ||
if ! grep -q 'forwarded_port' Vagrantfile; then | ||
perl -pi -e 's{^\s*(config.vm.hostname.*)$}{$1\nconfig.vm.network "forwarded_port", guest: {{ vm_devbox.ssh_port }}, host: {{ vm_devbox.ssh_port }}}' Vagrantfile | ||
r=1 | ||
elif ! grep -q 'guest: {{ vm_devbox.ssh_port }}, host: {{ vm_devbox.ssh_port }}' Vagrantfile; then | ||
perl -pi -e 's{^\s*config.vm.network "forwarded_port"}{config.vm.network "forwarded_port", guest: {{ vm_devbox.ssh_port }}, host: {{ vm_devbox.ssh_port }}}' Vagrantfile | ||
r=1 | ||
fi | ||
if [[ ${r:-} ]]; then | ||
vagrant reload | ||
fi | ||
} | ||
|
||
vm_devbox_set_ssh_config() { | ||
if ! vagrant status | grep -q running; then | ||
vagrant up | ||
fi | ||
vagrant ssh <<'EOF' | ||
sudo bash -s <<'EOF_BASH' | ||
set -eou pipefail | ||
install --mode=400 --owner=root --group=root /dev/stdin /etc/sshd_config<<EOF_INSTALL | ||
# DO NOT EDIT THIS FILE | ||
# MANAGED BY RSCONF | ||
# Keep vagrant ssh working | ||
Include /etc/ssh/sshd_config.d/*.conf | ||
ListenAddress 0.0.0.0:22 | ||
HostKey {{ vm_devbox.ssh_guest_host_key_f }} | ||
ListenAddress 0.0.0.0:{{ vm_devbox.ssh_port }} | ||
AuthorizedKeysFile .ssh/authorized_keys | ||
PasswordAuthentication no | ||
PrintLastLog no | ||
Protocol 2 | ||
X11Forwarding yes | ||
EOF_INSTALL | ||
echo '{{ vm_devbox.ssh_identity_pub_key }}' >> '/home/{{ rsconf_db.run_u }}/.ssh/authorized_keys' | ||
install --mode=400 --owner=root --group=root /dev/stdin "{{ vm_devbox.ssh_guest_host_key_f }}"<<EOF_INSTALL | ||
{{ vm_devbox.ssh_host_key }} | ||
EOF_INSTALL | ||
sshd -t | ||
systemctl restart sshd | ||
EOF_BASH | ||
EOF | ||
} | ||
|
||
cd {{ vm_devbox.vm_d }} | ||
vm_devbox_create_vm | ||
vm_devbox_set_forwarded_port | ||
vm_devbox_set_ssh_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[Service] | ||
RemainAfterExit=yes | ||
Restart=no | ||
Type=oneshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/joeblow/host_key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW | ||
QyNTUxOQAAACCT/PsL9/XcOTmEXAvGVhJj5+MlLl/UBUNDiC+H84AAHQAAAJBriK60a4iu | ||
tAAAAAtzc2gtZWQyNTUxOQAAACCT/PsL9/XcOTmEXAvGVhJj5+MlLl/UBUNDiC+H84AAHQ | ||
AAAEBVP+MksqPH64Pi3Rfb8lieY9ofTRBWZqvKWk2oYjuqsJP8+wv39dw5OYRcC8ZWEmPn | ||
4yUuX9QFQ0OIL4fzgAAdAAAADHY5LnJhZGlhLnJ1bgE= | ||
-----END OPENSSH PRIVATE KEY----- |
1 change: 1 addition & 0 deletions
1
tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/joeblow/host_key.pub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJP8+wv39dw5OYRcC8ZWEmPn4yUuX9QFQ0OIL4fzgAAd v9.radia.run |
8 changes: 8 additions & 0 deletions
8
tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/joeblow/identity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAmx+HJoQ | ||
g2f+QIRjDUx9W9AAAAEAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAINhimES0Iw3kh1fB | ||
0/VMNaXlwhWRDfEXt+3ZwEQNrvC9AAAAkKQ97+C2iZDRbWymbxMoPwqugDvdGtMAa2GmIg | ||
675vuEmzzETJcyz46jBqjgSMvaz2M0eF0o669pxO0tUC01YDSVXXcMQWoozwOgnwn9ljyl | ||
IOkUCH60EnKY4X7YgYEDUVG4ccfFiWNPggcD9H6y94TIbbd3MQ/7+he/9iVeuQFmmy/I5b | ||
qveSMj3DfuLReEnQ== | ||
-----END OPENSSH PRIVATE KEY----- |
1 change: 1 addition & 0 deletions
1
tests/pkcli/build_data/1.in/db/secret/v9.radia.run/vm_devbox/joeblow/identity.pub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKe3wWXD3GUVd/5viGVhf6L/ttJJfmksXauPSpC8zWru v9.radia.run |
8 changes: 8 additions & 0 deletions
8
tests/pkcli/build_data/1.out/db/secret/v9.radia.run/vm_devbox/joeblow/identity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAmx+HJoQ | ||
g2f+QIRjDUx9W9AAAAEAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAINhimES0Iw3kh1fB | ||
0/VMNaXlwhWRDfEXt+3ZwEQNrvC9AAAAkKQ97+C2iZDRbWymbxMoPwqugDvdGtMAa2GmIg | ||
675vuEmzzETJcyz46jBqjgSMvaz2M0eF0o669pxO0tUC01YDSVXXcMQWoozwOgnwn9ljyl | ||
IOkUCH60EnKY4X7YgYEDUVG4ccfFiWNPggcD9H6y94TIbbd3MQ/7+he/9iVeuQFmmy/I5b | ||
qveSMj3DfuLReEnQ== | ||
-----END OPENSSH PRIVATE KEY----- |
1 change: 1 addition & 0 deletions
1
tests/pkcli/build_data/1.out/db/secret/v9.radia.run/vm_devbox/joeblow/identity.pub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKe3wWXD3GUVd/5viGVhf6L/ttJJfmksXauPSpC8zWru v9.radia.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
tests/pkcli/build_data/1.out/srv/host/v9.radia.run/srv/vm_devbox_joeblow/start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/bin/bash | ||
set -eou pipefail | ||
|
||
vm_devbox_first_start() { | ||
if [[ -e Vagrantfile ]]; then | ||
return | ||
fi | ||
# Put vms in this dir so we don't scatter them around the machine. | ||
# The default is under $HOME which doesn't make sense for this kind | ||
# of service. | ||
declare d=virtualbox_vms | ||
mkdir "$d" | ||
vboxmanage setproperty machinefolder "$PWD/$d" | ||
curl https://radia.run | vagrant_dev_private_net= \ | ||
vagrant_dev_provision_eth1= \ | ||
vagrant_dev_no_mounts=1 \ | ||
vagrant_dev_no_nfs_src=1 \ | ||
vagrant_dev_no_vbguest=1 \ | ||
bash -s vagrant-sirepo-dev | ||
vboxmanage setproperty machinefolder default | ||
} | ||
|
||
vm_devbox_set_forwarded_port() { | ||
declare r= | ||
if ! grep -q 'forwarded_port' Vagrantfile; then | ||
perl -pi -e 's{^\s*(config.vm.hostname.*)$}{$1\nconfig.vm.network "forwarded_port", guest: 102002, host: 102002}' Vagrantfile | ||
r=1 | ||
elif ! grep -q 'guest: 102002, host: 102002' Vagrantfile; then | ||
perl -pi -e 's{^\s*config.vm.network "forwarded_port"}{config.vm.network "forwarded_port", guest: 102002, host: 102002}' Vagrantfile | ||
r=1 | ||
fi | ||
if [[ ${r:-} ]]; then | ||
vagrant reload | ||
fi | ||
} | ||
|
||
vm_devbox_set_ssh_config() { | ||
if ! vagrant status | grep -q running; then | ||
vagrant up | ||
fi | ||
vagrant ssh <<'EOF' | ||
sudo bash -s <<'EOF_BASH' | ||
set -eou pipefail | ||
install --mode=400 --owner=root --group=root /dev/stdin /etc/sshd_config<<EOF_INSTALL | ||
# DO NOT EDIT THIS FILE | ||
# MANAGED BY RSCONF | ||
# Keep vagrant ssh working | ||
Include /etc/ssh/sshd_config.d/*.conf | ||
ListenAddress 0.0.0.0:22 | ||
HostKey /etc/ssh/host_key | ||
ListenAddress 0.0.0.0:102002 | ||
AuthorizedKeysFile .ssh/authorized_keys | ||
PasswordAuthentication no | ||
PrintLastLog no | ||
Protocol 2 | ||
X11Forwarding yes | ||
EOF_INSTALL | ||
echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKe3wWXD3GUVd/5viGVhf6L/ttJJfmksXauPSpC8zWru v9.radia.run | ||
' >> '/home/vagrant/.ssh/authorized_keys' | ||
install --mode=400 --owner=root --group=root /dev/stdin "/etc/ssh/host_key"<<EOF_INSTALL | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW | ||
QyNTUxOQAAACCT/PsL9/XcOTmEXAvGVhJj5+MlLl/UBUNDiC+H84AAHQAAAJBriK60a4iu | ||
tAAAAAtzc2gtZWQyNTUxOQAAACCT/PsL9/XcOTmEXAvGVhJj5+MlLl/UBUNDiC+H84AAHQ | ||
AAAEBVP+MksqPH64Pi3Rfb8lieY9ofTRBWZqvKWk2oYjuqsJP8+wv39dw5OYRcC8ZWEmPn | ||
4yUuX9QFQ0OIL4fzgAAdAAAADHY5LnJhZGlhLnJ1bgE= | ||
-----END OPENSSH PRIVATE KEY----- | ||
EOF_INSTALL | ||
sshd -t | ||
systemctl restart sshd | ||
EOF_BASH | ||
EOF | ||
} | ||
|
||
cd /srv/vm_devbox_joeblow/v | ||
vm_devbox_create_vm | ||
vm_devbox_set_forwarded_port | ||
vm_devbox_set_ssh_config |
Oops, something went wrong.