mirror of
https://github.com/linka-cloud/d2vm.git
synced 2024-11-21 23:36:25 +00:00
fix: dockerfile relative path when running in docker
docs: update README.md to current command line api fix: command line output white for default level Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
d97b58159c
commit
a41be6d27c
112
README.md
112
README.md
@ -13,17 +13,11 @@ Many thanks to him.
|
|||||||
|
|
||||||
**Status**: *alpha*
|
**Status**: *alpha*
|
||||||
|
|
||||||
[![asciicast](https://asciinema.org/a/4WFKxaSNWTMPMeYbZWcSNm2nm.svg)](https://asciinema.org/a/4WFKxaSNWTMPMeYbZWcSNm2nm)
|
[![asciicast](https://asciinema.org/a/520132.svg)](https://asciinema.org/a/520132)
|
||||||
|
|
||||||
## Supported Environments:
|
## Supported Environments:
|
||||||
|
|
||||||
**Only Linux is supported.**
|
**Only building Linux Virtual Machine images is supported.**
|
||||||
|
|
||||||
If you want to run it on **OSX** or **Windows** (the last one is totally untested) you can do it using Docker:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
alias d2vm='docker run --rm -i -t --privileged -v /var/run/docker.sock:/var/run/docker.sock -v $PWD:/build -w /build linkacloud/d2vm'
|
|
||||||
```
|
|
||||||
|
|
||||||
**Starting from v0.1.0, d2vm automatically run build and convert commands inside Docker when not running on linux**.
|
**Starting from v0.1.0, d2vm automatically run build and convert commands inside Docker when not running on linux**.
|
||||||
|
|
||||||
@ -47,31 +41,22 @@ Obviously, **Distroless** images are not supported.
|
|||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
|
### Install from release
|
||||||
|
|
||||||
|
Download the latest release for your platform from the [release page](https://github.com/linka-cloud/d2vm/releases/latest)
|
||||||
|
|
||||||
|
### Install from source
|
||||||
|
|
||||||
Clone the git repository:
|
Clone the git repository:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/linka-cloud/d2vm && cd d2vm
|
git clone https://github.com/linka-cloud/d2vm && cd d2vm
|
||||||
```
|
```
|
||||||
|
|
||||||
Install using the Go tool chain:
|
Install using the *make*, *docker* and the Go tool chain:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go install ./cmd/d2vm
|
make build-dev && sudo cp d2vm /usr/local/bin/
|
||||||
which d2vm
|
|
||||||
```
|
|
||||||
```
|
|
||||||
# Should be install in the $GOBIN directory
|
|
||||||
/go/bin/d2vm
|
|
||||||
```
|
|
||||||
|
|
||||||
Or use an alias to the **docker** image:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
alias d2vm='docker run --rm -i -t --privileged -v /var/run/docker.sock:/var/run/docker.sock -v $PWD:/build -w /build linkacloud/d2vm'
|
|
||||||
which d2vm
|
|
||||||
```
|
|
||||||
```
|
|
||||||
d2vm: aliased to docker run --rm -i -t --privileged -v /var/run/docker.sock:/var/run/docker.sock -v $PWD:/build -w /build linkacloud/d2vm
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Converting an existing Docker Image to VM image:
|
### Converting an existing Docker Image to VM image:
|
||||||
@ -86,13 +71,20 @@ Usage:
|
|||||||
d2vm convert [docker image] [flags]
|
d2vm convert [docker image] [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-d, --debug Enable Debug output
|
--append-to-cmdline string Extra kernel cmdline arguments to append to the generated one
|
||||||
-f, --force Override output qcow2 image
|
-f, --force Override output qcow2 image
|
||||||
-h, --help help for convert
|
-h, --help help for convert
|
||||||
-o, --output string The output image, the extension determine the image format. Supported formats: qcow2 qed raw vdi vhd vmdk (default "disk0.qcow2")
|
--network-manager string Network manager to use for the image: none, netplan, ifupdown
|
||||||
-p, --password string The Root user password (default "root")
|
-o, --output string The output image, the extension determine the image format, raw will be used if none. Supported formats: qcow2 qed raw vdi vhd vmdk (default "disk0.qcow2")
|
||||||
--pull Always pull docker image
|
-p, --password string The Root user password (default "root")
|
||||||
-s, --size string The output image size (default "10G")
|
--pull Always pull docker image
|
||||||
|
--raw Just convert the container to virtual machine image without installing anything more
|
||||||
|
-s, --size string The output image size (default "10G")
|
||||||
|
|
||||||
|
Global Flags:
|
||||||
|
-t, --time string Enable formated timed output, valide formats: 'relative (rel | r)', 'full (f)' (default "none")
|
||||||
|
-v, --verbose Enable Verbose output
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -102,27 +94,27 @@ Create an image based on the **ubuntu** official image:
|
|||||||
sudo d2vm convert ubuntu -o ubuntu.qcow2 -p MyP4Ssw0rd
|
sudo d2vm convert ubuntu -o ubuntu.qcow2 -p MyP4Ssw0rd
|
||||||
```
|
```
|
||||||
```
|
```
|
||||||
INFO[0000] pulling image ubuntu
|
Pulling image ubuntu
|
||||||
INFO[0001] inspecting image ubuntu
|
Inspecting image ubuntu
|
||||||
INFO[0002] docker image based on Ubuntu
|
No network manager specified, using distribution defaults: netplan
|
||||||
INFO[0002] building kernel enabled image
|
Docker image based on Ubuntu 22.04.1 LTS (Jammy Jellyfish)
|
||||||
INFO[0038] creating root file system archive
|
Building kernel enabled image
|
||||||
INFO[0040] creating vm image
|
Creating vm image
|
||||||
INFO[0040] creating raw image
|
Creating raw image
|
||||||
INFO[0040] mounting raw image
|
Mounting raw image
|
||||||
INFO[0040] creating raw image file system
|
Creating raw image file system
|
||||||
INFO[0040] copying rootfs to raw image
|
Copying rootfs to raw image
|
||||||
INFO[0041] setting up rootfs
|
Setting up rootfs
|
||||||
INFO[0041] installing linux kernel
|
Installing linux kernel
|
||||||
INFO[0042] unmounting raw image
|
Unmounting raw image
|
||||||
INFO[0042] writing MBR
|
Writing MBR
|
||||||
INFO[0042] converting to qcow2
|
Converting to qcow2
|
||||||
```
|
```
|
||||||
|
|
||||||
You can now run your ubuntu image using the created `ubuntu.qcow2` image with **qemu**:
|
You can now run your ubuntu image using the created `ubuntu.qcow2` image with **qemu**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./qemu.sh ununtu.qcow2
|
d2vm run qemu ubuntu.qcow2
|
||||||
```
|
```
|
||||||
```
|
```
|
||||||
SeaBIOS (version 1.13.0-1ubuntu1.1)
|
SeaBIOS (version 1.13.0-1ubuntu1.1)
|
||||||
@ -210,7 +202,7 @@ cd examples
|
|||||||
FROM ubuntu
|
FROM ubuntu
|
||||||
|
|
||||||
RUN apt update && apt install -y openssh-server && \
|
RUN apt update && apt install -y openssh-server && \
|
||||||
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config \
|
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -231,14 +223,20 @@ Usage:
|
|||||||
d2vm build [context directory] [flags]
|
d2vm build [context directory] [flags]
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
--build-arg stringArray Set build-time variables
|
--append-to-cmdline string Extra kernel cmdline arguments to append to the generated one
|
||||||
-d, --debug Enable Debug output
|
--build-arg stringArray Set build-time variables
|
||||||
-f, --file string Name of the Dockerfile
|
-f, --file string Name of the Dockerfile
|
||||||
--force Override output image
|
--force Override output image
|
||||||
-h, --help help for build
|
-h, --help help for build
|
||||||
-o, --output string The output image, the extension determine the image format. Supported formats: qcow2 qed raw vdi vhd vmdk (default "disk0.qcow2")
|
--network-manager string Network manager to use for the image: none, netplan, ifupdown
|
||||||
-p, --password string Root user password (default "root")
|
-o, --output string The output image, the extension determine the image format, raw will be used if none. Supported formats: qcow2 qed raw vdi vhd vmdk (default "disk0.qcow2")
|
||||||
-s, --size string The output image size (default "10G")
|
-p, --password string Root user password (default "root")
|
||||||
|
--raw Just convert the container to virtual machine image without installing anything more
|
||||||
|
-s, --size string The output image size (default "10G")
|
||||||
|
|
||||||
|
Global Flags:
|
||||||
|
-t, --time string Enable formated timed output, valide formats: 'relative (rel | r)', 'full (f)' (default "none")
|
||||||
|
-v, --verbose Enable Verbose output
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ var (
|
|||||||
for i, v := range dargs {
|
for i, v := range dargs {
|
||||||
switch v {
|
switch v {
|
||||||
case file:
|
case file:
|
||||||
rel, err := filepath.Rel(in, file)
|
rel, err := filepath.Rel(in, dockerFileAbsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to construct Dockerfile container paths: %w", err)
|
return fmt.Errorf("failed to construct Dockerfile container paths: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,7 @@ const (
|
|||||||
red = 31
|
red = 31
|
||||||
yellow = 33
|
yellow = 33
|
||||||
blue = 36
|
blue = 36
|
||||||
|
white = 39
|
||||||
gray = 90
|
gray = 90
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -100,14 +101,12 @@ func (f *logfmtFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|||||||
switch entry.Level {
|
switch entry.Level {
|
||||||
case logrus.DebugLevel, logrus.TraceLevel:
|
case logrus.DebugLevel, logrus.TraceLevel:
|
||||||
c = color.New(gray)
|
c = color.New(gray)
|
||||||
// case logrus.InfoLevel:
|
|
||||||
// c = color.New(blue)
|
|
||||||
case logrus.WarnLevel:
|
case logrus.WarnLevel:
|
||||||
c = color.New(yellow)
|
c = color.New(yellow)
|
||||||
case logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel:
|
case logrus.ErrorLevel, logrus.FatalLevel, logrus.PanicLevel:
|
||||||
c = color.New(red)
|
c = color.New(red)
|
||||||
default:
|
default:
|
||||||
c = color.New(color.FgWhite)
|
c = color.New(white)
|
||||||
}
|
}
|
||||||
msg := entry.Message
|
msg := entry.Message
|
||||||
if len(entry.Message) > 0 && entry.Level < logrus.DebugLevel {
|
if len(entry.Message) > 0 && entry.Level < logrus.DebugLevel {
|
||||||
|
Binary file not shown.
@ -1,5 +1,4 @@
|
|||||||
FROM debian
|
FROM debian
|
||||||
|
|
||||||
RUN apt update && apt install -y openssh-server systemctl && \
|
RUN apt update && apt install -y openssh-server && \
|
||||||
systemctl enable ssh && \
|
|
||||||
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
|
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# d2vm full example
|
# ZSH Workstation example
|
||||||
|
|
||||||
This example demonstrate the setup of a ZSH workstation.
|
This example demonstrate the setup of a ZSH workstation with *cloud-init* support.
|
||||||
|
|
||||||
*Dockerfile*
|
*Dockerfile*
|
||||||
```dockerfile
|
```dockerfile
|
||||||
@ -9,14 +9,11 @@ FROM ubuntu
|
|||||||
# Install some system packages
|
# Install some system packages
|
||||||
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
|
RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
|
||||||
qemu-guest-agent \
|
qemu-guest-agent \
|
||||||
netplan.io \
|
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
dnsutils \
|
dnsutils \
|
||||||
sudo \
|
sudo \
|
||||||
openssh-server
|
openssh-server
|
||||||
|
|
||||||
# Setup default network config
|
|
||||||
COPY 00-netconf.yaml /etc/netplan/
|
|
||||||
# Add a utility script to resize serial terminal
|
# Add a utility script to resize serial terminal
|
||||||
COPY resize /usr/local/bin/
|
COPY resize /usr/local/bin/
|
||||||
|
|
||||||
@ -33,7 +30,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends \
|
|||||||
git \
|
git \
|
||||||
vim \
|
vim \
|
||||||
tmux \
|
tmux \
|
||||||
htop
|
htop \
|
||||||
|
lsb-core \
|
||||||
|
cloud-init \
|
||||||
|
cloud-guest-utils
|
||||||
|
|
||||||
# Create user with sudo privileged and passwordless sudo
|
# Create user with sudo privileged and passwordless sudo
|
||||||
RUN useradd ${USER} -m -s /bin/zsh -G sudo && \
|
RUN useradd ${USER} -m -s /bin/zsh -G sudo && \
|
||||||
@ -54,23 +54,11 @@ RUN bash -c "$(curl -fsSL https://gist.githubusercontent.com/Adphi/f3ce3cc4b2551
|
|||||||
RUN bash -c "$(curl -fsSL https://gist.githubusercontent.com/Adphi/765e9382dd5e547633be567e2eb72476/raw/a3fe4b3f35e598dca90e2dd45d30dc1753447a48/tmux-setup)"
|
RUN bash -c "$(curl -fsSL https://gist.githubusercontent.com/Adphi/765e9382dd5e547633be567e2eb72476/raw/a3fe4b3f35e598dca90e2dd45d30dc1753447a48/tmux-setup)"
|
||||||
# Setup auto login serial console
|
# Setup auto login serial console
|
||||||
RUN sudo sed -i "s|ExecStart=.*|ExecStart=-/sbin/agetty --autologin ${USER} --keep-baud 115200,38400,9600 \%I \$TERM|" /usr/lib/systemd/system/serial-getty@.service
|
RUN sudo sed -i "s|ExecStart=.*|ExecStart=-/sbin/agetty --autologin ${USER} --keep-baud 115200,38400,9600 \%I \$TERM|" /usr/lib/systemd/system/serial-getty@.service
|
||||||
```
|
|
||||||
|
|
||||||
*00-netconf.yaml*
|
|
||||||
```yaml
|
|
||||||
network:
|
|
||||||
version: 2
|
|
||||||
renderer: networkd
|
|
||||||
ethernets:
|
|
||||||
eth0:
|
|
||||||
dhcp4: true
|
|
||||||
nameservers:
|
|
||||||
addresses:
|
|
||||||
- 8.8.8.8
|
|
||||||
- 8.8.4.4
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
There is no need to configure the network as **d2vm** will generate a *netplan* configuration that use DHCP.
|
||||||
|
|
||||||
**Build**
|
**Build**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -78,23 +66,29 @@ USER=mygithubuser
|
|||||||
PASSWORD=mysecurepasswordthatIwillneverusebecauseIuseMostlySSHkeys
|
PASSWORD=mysecurepasswordthatIwillneverusebecauseIuseMostlySSHkeys
|
||||||
OUTPUT=workstation.qcow2
|
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 .
|
d2vm build -o $OUTPUT --build-arg USER=$USER --build-arg PASSWORD=$PASSWORD --build-arg SSH_KEY=https://github.com/$USER.keys --force -v .
|
||||||
```
|
```
|
||||||
|
|
||||||
Run it using *libvirt's virt-install*:
|
Run it:
|
||||||
|
|
||||||
```bash
|
```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'
|
d2vm run qemu --mem 4096 --cpus 4 $IMAGE
|
||||||
```
|
```
|
||||||
... you should be automatically logged in with a **oh-my-zsh** shell
|
... you should be automatically logged in with a **oh-my-zsh** shell
|
||||||
|
|
||||||
From an other terminal you should be able to find the VM ip address using:
|
You should be able to find the ip address inside the VM using:
|
||||||
```bash
|
```bash
|
||||||
virsh domifaddr --domain workstation
|
hostname -I
|
||||||
|
# or
|
||||||
|
ip a show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1
|
||||||
```
|
```
|
||||||
|
|
||||||
And connect using ssh...
|
And connect using ssh...
|
||||||
|
|
||||||
|
In order to quit the terminal you need to shut down the VM with the `poweroff` command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo poweroff
|
||||||
|
```
|
||||||
|
|
||||||
*I hope you will find it useful and that you will have fun...*
|
*I hope you will find it useful and that you will have fun...*
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
FROM ubuntu
|
FROM ubuntu
|
||||||
|
|
||||||
RUN apt update && apt install -y openssh-server systemctl && \
|
RUN apt update && apt install -y openssh-server && \
|
||||||
systemctl enable ssh && \
|
|
||||||
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
|
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
|
||||||
|
Loading…
Reference in New Issue
Block a user