forked from vrnetlab/vrnetlab
-
Notifications
You must be signed in to change notification settings - Fork 162
Add Debian - with the option of running a startup script and... #330
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
Open
joolli
wants to merge
2
commits into
srl-labs:master
Choose a base branch
from
joolli:debian
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,18 @@ | ||
| VENDOR=Debian | ||
| NAME=Debian | ||
| IMAGE_FORMAT=qcow2 | ||
| IMAGE_GLOB=*.qcow2 | ||
|
|
||
| # match versions like: | ||
| # debian-bookworm-genericcloud.qcow2 | ||
| VERSION=$(shell echo $(IMAGE) | sed -e 's/debian-\([a-z]\+\)-genericcloud.*/\1/') | ||
|
|
||
|
|
||
| -include ../makefile-sanity.include | ||
| -include ../makefile.include | ||
|
|
||
| download: | ||
| /bin/bash download.sh | ||
|
|
||
| build: download | ||
| $(MAKE) docker-image |
This file contains hidden or 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,21 @@ | ||
| # Debian VM | ||
|
|
||
| To download a compatible image of the Debian VM execute the [download.sh](download.sh) script that will download a cloud-init image of Debian from <https://cloud.debian.org/images/cloud>. The version is set in the script and can be changed manually. | ||
|
|
||
| Once the qcow2 image is downloaded, build the container with the following command: | ||
|
|
||
| ```bash | ||
| make | ||
| ``` | ||
|
|
||
| The resulting container will be tagged as `vrnetlab/vr-debian:<version>`, e.g. `vrnetlab/vr-debian:bookworm`. | ||
|
|
||
| ## Host requirements | ||
|
|
||
| * 1 vCPU, 512 MB RAM | ||
|
|
||
| ## Configuration | ||
|
|
||
| Initial config is carried out via cloud-init. | ||
|
|
||
| * `9.9.9.9` configured as the DNS resolver. Change it with `resolvectl` if required. |
This file contains hidden or 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,33 @@ | ||
| FROM debian:bookworm-slim | ||
|
|
||
| ARG DEBIAN_FRONTEND=noninteractive | ||
| ARG DISK_SIZE=4G | ||
|
|
||
| RUN apt-get update -qy \ | ||
| && apt-get install -y \ | ||
| bridge-utils \ | ||
| iproute2 \ | ||
| socat \ | ||
| qemu-kvm \ | ||
| tcpdump \ | ||
| ssh \ | ||
| inetutils-ping \ | ||
| dnsutils \ | ||
| iptables \ | ||
| nftables \ | ||
| telnet \ | ||
| cloud-utils \ | ||
| sshpass \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| ARG IMAGE | ||
| COPY $IMAGE* / | ||
| COPY *.py / | ||
| COPY backup.sh / | ||
| COPY copy_etc_and_run_startupscript.sh / | ||
|
|
||
| RUN qemu-img resize /${IMAGE} ${DISK_SIZE} | ||
|
|
||
| EXPOSE 22 5000 10000-10099 | ||
| HEALTHCHECK CMD ["/healthcheck.py"] | ||
| ENTRYPOINT ["/launch.py"] | ||
This file contains hidden or 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,84 @@ | ||
| #!/bin/bash | ||
|
|
||
| DEFAULT_USER="admin" | ||
| DEFAULT_PASSWORD="admin" | ||
| BACKUP_FILE="backup.tar.gz" | ||
| BACKUP_PATH=/config/$BACKUP_FILE | ||
| REMOTE_BACKUP_PATH=/tmp/$BACKUP_FILE | ||
|
|
||
| handle_args() { | ||
| # Parse options | ||
| while getopts 'u:p:' OPTION; do | ||
| case "$OPTION" in | ||
| u) | ||
| user="$OPTARG" | ||
| ;; | ||
| p) | ||
| password="$OPTARG" | ||
| ;; | ||
| ?) | ||
| usage | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
| shift "$(($OPTIND -1))" | ||
|
|
||
| # Assign defaults if options weren't provided | ||
| if [ -z "$user" ] ; then | ||
| user=$DEFAULT_USER | ||
| fi | ||
| if [ -z "$password" ] ; then | ||
| password=$DEFAULT_PASSWORD | ||
| fi | ||
|
|
||
| SSH_CMD="sshpass -p $password ssh -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p22" | ||
| SCP_CMD="sshpass -p $password scp -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P22" | ||
| HOST="$user@localhost" | ||
|
|
||
| # Parse commands | ||
| case $1 in | ||
|
|
||
| backup) | ||
| backup | ||
| ;; | ||
|
|
||
| restore) | ||
| restore | ||
| ;; | ||
|
|
||
| *) | ||
| usage | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| usage() { | ||
| echo "Usage: $(basename $0) [-u USERNAME] [-p PASSWORD] COMMAND" | ||
| echo "Options:" | ||
| echo " -u USERNAME VM SSH username (default: clab)" | ||
| echo " -p PASSWORD VM SSH password (default: clab@123)" | ||
| echo | ||
| echo "Commands:" | ||
| echo " backup Backup VM /etc directory to $BACKUP_PATH" | ||
| echo " restore Restore VM /etc directory from $BACKUP_PATH" | ||
| exit 0; | ||
| } | ||
|
|
||
| backup() { | ||
| echo "Backing up..." | ||
| $SSH_CMD $HOST "sudo tar zcf $REMOTE_BACKUP_PATH /etc > & /dev/null" | ||
| $SCP_CMD $HOST:$REMOTE_BACKUP_PATH $BACKUP_PATH | ||
| } | ||
|
|
||
| restore() { | ||
| if [ -f "$BACKUP_PATH" ]; then | ||
| echo "Restoring from backup..." | ||
| # Put backup file to VM, untar, and reboot. | ||
| $SCP_CMD $BACKUP_PATH $HOST:$REMOTE_BACKUP_PATH && $SSH_CMD $HOST "sudo tar xzf $REMOTE_BACKUP_PATH -C /" && $SSH_CMD $HOST "sudo shutdown -r now || true" | ||
| else | ||
| echo "$BACKUP_PATH not found. Nothing to restore." | ||
| fi | ||
| } | ||
|
|
||
| handle_args "$@" |
This file contains hidden or 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,89 @@ | ||
| #!/bin/bash | ||
|
|
||
| DEFAULT_USER="admin" | ||
| DEFAULT_PASSWORD="admin" | ||
| DOCKER_ETC_PATH=/config/etc | ||
| REMOTE_TMP_PATH=/tmp/etc | ||
| # location of startup script in the docker container | ||
| STARTUPSCRIPT=/config/startup.sh | ||
|
|
||
| handle_args() { | ||
| # Parse options | ||
| while getopts 'u:p:' OPTION; do | ||
| case "$OPTION" in | ||
| u) | ||
| user="$OPTARG" | ||
| ;; | ||
| p) | ||
| password="$OPTARG" | ||
| ;; | ||
| ?) | ||
| usage | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
| shift "$(($OPTIND -1))" | ||
|
|
||
| # Assign defaults if options weren't provided | ||
| if [ -z "$user" ] ; then | ||
| user=$DEFAULT_USER | ||
| fi | ||
| if [ -z "$password" ] ; then | ||
| password=$DEFAULT_PASSWORD | ||
| fi | ||
|
|
||
| SSH_CMD="sshpass -p $password ssh -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p22" | ||
| SCP_CMD="sshpass -p $password scp -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P22" | ||
| HOST="$user@localhost" | ||
|
|
||
| # Parse commands | ||
| case $1 in | ||
|
|
||
| startupconfig) | ||
| startupconfig | ||
| ;; | ||
|
|
||
| copyetc) | ||
| copyetc | ||
| ;; | ||
|
|
||
| *) | ||
| usage | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| usage() { | ||
| echo "Usage: $(basename $0) [-u USERNAME] [-p PASSWORD] COMMAND" | ||
| echo "Options:" | ||
| echo " -u USERNAME VM SSH username (default: admin)" | ||
| echo " -p PASSWORD VM SSH password (default: admin)" | ||
| echo | ||
| echo "Commands:" | ||
| echo " startupconfig copy $STARTUPSCRIPT to vm and run it" | ||
| echo " copyetc copy $DOCKER_ETC_PATH to /etc on the vm" | ||
| exit 0; | ||
| } | ||
|
|
||
| startupconfig() { | ||
| if [ -f "$STARTUPSCRIPT" ]; then | ||
| echo "copy_etc_and_run_startupscript.sh startupconfig(): Copying $STARTUPSCRIPT to vm..." | ||
| # Put startupfile file to VM under ~/ (/home/clab for the debian image). | ||
| $SCP_CMD $STARTUPSCRIPT $HOST:startup.sh && $SSH_CMD $HOST "sudo chmod +x startup.sh && sudo ./startup.sh || true" | ||
| else | ||
| echo "copy_etc_and_run_startupscript.sh startupconfig(): $STARTUPSCRIPT not found. No startupscript to upload." | ||
| fi | ||
| } | ||
|
|
||
| copyetc() { | ||
| if [ -d "$DOCKER_ETC_PATH" ]; then | ||
| echo "copy_etc_and_run_startupscript.sh copyetc(): Copying $DOCKER_ETC_PATH to vm..." | ||
| # Copy /config/etc to /etc in the VM. | ||
| $SCP_CMD -r $DOCKER_ETC_PATH $HOST:$REMOTE_TMP_PATH && $SSH_CMD $HOST "sudo cp -r $REMOTE_TMP_PATH/* /etc" && $SSH_CMD $HOST "sudo shutdown -r now || true" | ||
| else | ||
| echo "copy_etc_and_run_startupscript.sh copyetc(): $DOCKER_ETC_PATH not found. Nothing to upload." | ||
| fi | ||
| } | ||
|
|
||
| handle_args "$@" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mind checking if you can substitute this Dockerfile with the new version we started to use:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to replace the whole Dockerfile? Will it be possible to resize the disk within the clab yaml?
I assume that "4" after "COPY *.py /" is a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replaced the Dockerfile with yours and got:
Do I need a new launch.py as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to add another RUN command that installs cloud-utils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I only change the FROM statement to ghcr.io/srl-labs/vrnetlab-base:0.2.1, then it works. If you're happy with that, then I'll amend the pull request. Then the Dockerfile would look like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to keep everything. I think this should be fine: