mirror of
https://github.com/linka-cloud/d2vm.git
synced 2025-06-23 13:52:26 +00:00
cli: improve flags and commands
docs: add README.md and examples centos/rhel: fix dracut initramfs Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
1
examples/.dockerignore
Normal file
1
examples/.dockerignore
Normal file
@ -0,0 +1 @@
|
||||
**/*.qcow2
|
13
examples/centos.Dockerfile
Normal file
13
examples/centos.Dockerfile
Normal file
@ -0,0 +1,13 @@
|
||||
FROM centos
|
||||
|
||||
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \
|
||||
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
|
||||
|
||||
RUN yum update -y
|
||||
RUN yum install -y qemu-guest-agent openssh-server && \
|
||||
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && \
|
||||
systemctl enable dbus.service && \
|
||||
systemctl set-default graphical.target
|
||||
|
||||
RUN echo "NETWORKING=yes" >> /etc/sysconfig/network && \
|
||||
echo -e 'DEVICE="eth0"\nONBOOT="yes"\nBOOTPROTO="dhcp"\n' > /etc/sysconfig/network-scripts/ifcfg-eth0
|
1
examples/full/.dockerignore
Normal file
1
examples/full/.dockerignore
Normal file
@ -0,0 +1 @@
|
||||
**/*.qcow2
|
10
examples/full/00-netconf.yaml
Normal file
10
examples/full/00-netconf.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
network:
|
||||
version: 2
|
||||
renderer: networkd
|
||||
ethernets:
|
||||
eth0:
|
||||
dhcp4: true
|
||||
nameservers:
|
||||
addresses:
|
||||
- 8.8.8.8
|
||||
- 8.8.4.4
|
47
examples/full/Dockerfile
Normal file
47
examples/full/Dockerfile
Normal file
@ -0,0 +1,47 @@
|
||||
FROM ubuntu
|
||||
|
||||
# Install netplan sudo ssh-server and dns utils
|
||||
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y \
|
||||
ameu-guest-agent \
|
||||
netplan.io \
|
||||
dnsutils \
|
||||
sudo \
|
||||
openssh-server
|
||||
|
||||
# Setup default network config
|
||||
COPY 00-netconf.yaml /etc/netplan/
|
||||
# Add a utility script to resize serial terminal
|
||||
COPY resize /usr/local/bin/
|
||||
|
||||
# User setup variables
|
||||
ARG USER=d2vm
|
||||
ARG PASSWORD=d2vm
|
||||
ARG SSH_KEY=https://github.com/${USER}.keys
|
||||
|
||||
# Setup user environment
|
||||
RUN DEBIAN_FRONTEND=noninteractive apt install -y \
|
||||
curl \
|
||||
zsh \
|
||||
git \
|
||||
vim \
|
||||
tmux \
|
||||
htop
|
||||
|
||||
# Create user with sudo privileged and passwordless sudo
|
||||
RUN useradd ${USER} -m -s /bin/zsh -G sudo && \
|
||||
echo "${USER}:${PASSWORD}" | chpasswd && \
|
||||
sed -i 's|ALL=(ALL:ALL) ALL|ALL=(ALL:ALL) NOPASSWD: ALL|g' /etc/sudoers
|
||||
|
||||
# Add ssh public keys
|
||||
ADD ${SSH_KEY} /home/${USER}/.ssh/authorized_keys
|
||||
# Setup permission on .ssh directory
|
||||
RUN chown -R ${USER}:${USER} /home/${USER}/.ssh
|
||||
|
||||
# Run everything else as the created user
|
||||
USER ${USER}
|
||||
|
||||
# Setup zsh environment
|
||||
RUN bash -c "$(curl -fsSL https://gist.githubusercontent.com/Adphi/f3ce3cc4b2551c437eb667f3a5873a16/raw/be05553da87f6e9d8b0d290af5aa036d07de2e25/env.setup)"
|
||||
# Setup tmux environment
|
||||
RUN bash -c "$(curl -fsSL https://gist.githubusercontent.com/Adphi/765e9382dd5e547633be567e2eb72476/raw/a3fe4b3f35e598dca90e2dd45d30dc1753447a48/tmux-setup)"
|
||||
|
95
examples/full/README.md
Normal file
95
examples/full/README.md
Normal file
@ -0,0 +1,95 @@
|
||||
# d2vm full example
|
||||
|
||||
This example demonstrate the setup of a ZSH workstation.
|
||||
|
||||
*Dockerfile*
|
||||
```dockerfile
|
||||
FROM ubuntu
|
||||
|
||||
# Install netplan sudo ssh-server and dns utils
|
||||
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y \
|
||||
ameu-guest-agent \
|
||||
netplan.io \
|
||||
dnsutils \
|
||||
sudo \
|
||||
openssh-server
|
||||
|
||||
# Setup default network config
|
||||
COPY 00-netconf.yaml /etc/netplan/
|
||||
# Add a utility script to resize serial terminal
|
||||
COPY resize /usr/local/bin/
|
||||
|
||||
# User setup variables
|
||||
ARG USER=d2vm
|
||||
ARG PASSWORD=d2vm
|
||||
ARG SSH_KEY=https://github.com/${USER}.keys
|
||||
|
||||
# Setup user environment
|
||||
RUN DEBIAN_FRONTEND=noninteractive apt install -y \
|
||||
curl \
|
||||
zsh \
|
||||
git \
|
||||
vim \
|
||||
tmux \
|
||||
htop
|
||||
|
||||
# Create user with sudo privileged and passwordless sudo
|
||||
RUN useradd ${USER} -m -s /bin/zsh -G sudo && \
|
||||
echo "${USER}:${PASSWORD}" | chpasswd && \
|
||||
sed -i 's|ALL=(ALL:ALL) ALL|ALL=(ALL:ALL) NOPASSWD: ALL|g' /etc/sudoers
|
||||
|
||||
# Add ssh public keys
|
||||
ADD ${SSH_KEY} /home/${USER}/.ssh/authorized_keys
|
||||
# Setup permission on .ssh directory
|
||||
RUN chown -R ${USER}:${USER} /home/${USER}/.ssh
|
||||
|
||||
# Run everything else as the created user
|
||||
USER ${USER}
|
||||
|
||||
# Setup zsh environment
|
||||
RUN bash -c "$(curl -fsSL https://gist.githubusercontent.com/Adphi/f3ce3cc4b2551c437eb667f3a5873a16/raw/be05553da87f6e9d8b0d290af5aa036d07de2e25/env.setup)"
|
||||
# Setup tmux environment
|
||||
RUN bash -c "$(curl -fsSL https://gist.githubusercontent.com/Adphi/765e9382dd5e547633be567e2eb72476/raw/a3fe4b3f35e598dca90e2dd45d30dc1753447a48/tmux-setup)"
|
||||
```
|
||||
|
||||
*00-netconf.yaml*
|
||||
```yaml
|
||||
network:
|
||||
version: 2
|
||||
renderer: networkd
|
||||
ethernets:
|
||||
eth0:
|
||||
dhcp4: true
|
||||
nameservers:
|
||||
addresses:
|
||||
- 8.8.8.8
|
||||
- 8.8.4.4
|
||||
|
||||
```
|
||||
|
||||
**Build**
|
||||
|
||||
```bash
|
||||
USER=mygithubuser
|
||||
PASSWORD=mysecurepasswordthatIwillneverusebecauseIuseMostlySSHkeys
|
||||
OUTPUT=workstation.qcow2
|
||||
|
||||
d2vm build -o $OUTPUT --force --build-arg USER=$USER --build-arg PASSWORD=$PASSWORD --build-arg SSH_KEY=https://github.com/$USER.keys .
|
||||
```
|
||||
|
||||
Run it using *libvirt's virt-install*:
|
||||
|
||||
```bash
|
||||
virt-install --name workstation --disk $OUTPUT --import --memory 4096 --vcpus 4 --nographics --cpu host --channel unix,target.type=virtio,target.name='org.qemu.guest_agent.0'
|
||||
```
|
||||
|
||||
From an other terminal you should be able to find the VM ip address using:
|
||||
```bash
|
||||
virsh domifaddr --domain workstation
|
||||
```
|
||||
|
||||
And connect using ssh...
|
||||
|
||||
|
||||
|
||||
*I hope you will find it useful and that you will have fun...*
|
6
examples/full/build.sh
Normal file
6
examples/full/build.sh
Normal file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
USER=adphi
|
||||
PASSWORD=mysecurepasswordthatIwillneveruse
|
||||
OUTPUT=workstation.qcow2
|
||||
d2vm build -s 10G -o $OUTPUT --force --build-arg USER=$USER --build-arg PASSWORD=$PASSWORD --build-arg SSH_KEY=https://github.com/$USER.keys .
|
13
examples/full/resize
Executable file
13
examples/full/resize
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
old=$(stty -g)
|
||||
stty raw -echo min 0 time 5
|
||||
|
||||
printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
|
||||
IFS='[;R' read -r _ rows cols _ < /dev/tty
|
||||
|
||||
stty "$old"
|
||||
|
||||
# echo "cols:$cols"
|
||||
# echo "rows:$rows"
|
||||
stty cols "$cols" rows "$rows"
|
Reference in New Issue
Block a user