Compare commits

..

9 Commits

3 changed files with 62 additions and 33 deletions

View File

@ -1,6 +1,6 @@
# Change this to podman if you are on RHEL8+ # Change this to podman if you are on RHEL8+
DOCKER ?= docker DOCKER ?= docker
SINGULARITY ?= singularity APPTAINER ?= apptainer
SHARED_DIR ?= ./shared SHARED_DIR ?= ./shared
OVERLAY_DIR ?= ./overlay OVERLAY_DIR ?= ./overlay
MAX_THREADS ?= 16 MAX_THREADS ?= 16
@ -17,17 +17,26 @@ GID := $(shell id -g)
p4iab.tar.gz: .docker_build p4iab.tar.gz: .docker_build
"$(DOCKER)" save p4iab:latest | gzip > "$@" "$(DOCKER)" save p4iab:latest | gzip > "$@"
p4iab.sif: p4iab.def p4iab.tar.gz p4iab.sif: p4iab.def .docker_build
sudo "$(SINGULARITY)" build "$@" "$<" sudo "$(APPTAINER)" build "$@" "$<"
sudo chown $(UID):$(GID) "$@" sudo chown $(UID):$(GID) "$@"
run: .docker_build run:
mkdir -p "$(SHARED_DIR)" @mkdir -p "$(SHARED_DIR)"
"$(DOCKER)" run --rm -it --privileged -v "$(SHARED_DIR):/home/p4/shared" -e TERM -u p4 --entrypoint p4iab_docker_entry.sh p4iab:latest @test -n "$(shell docker image ls -q p4iab)" \
|| (echo Cannot find image p4iab:latest, has it been built yet? 1>&2 \
&& false)
@"$(DOCKER)" run --rm -it --privileged -v "$(SHARED_DIR):/home/p4/shared" \
-e TERM -u p4 --entrypoint p4iab_docker_entry.sh p4iab:latest
sc-run: p4iab.sif app-run:
mkdir -p "$(SHARED_DIR)" "$(OVERLAY_DIR)" @mkdir -p "$(SHARED_DIR)" "$(OVERLAY_DIR)"
sudo singularity run --allow-setuid --overlay "$(OVERLAY_DIR)" -B "$(SHARED_DIR):/home/p4/shared" "$<" @test -e p4iab.sif \
|| (echo Cannot find p4iab.sif, has it been built yet? 1>&2 \
&& false)
@lsmod | grep overlay > /dev/null || sudo modprobe overlay
@sudo $(APPTAINER) run --allow-setuid --overlay "$(OVERLAY_DIR)" \
-B "$(SHARED_DIR):/home/p4/shared" p4iab.sif
clean: clean:
"$(DOCKER)" container prune "$(DOCKER)" container prune

View File

@ -24,46 +24,63 @@ this container also has a few other advantages:
2. It can run with a variety of setups: Docker, Podman, K8S, OpenShift, etc... 2. It can run with a variety of setups: Docker, Podman, K8S, OpenShift, etc...
3. It can be used as a basis for other P4 runtime testing suites. 3. It can be used as a basis for other P4 runtime testing suites.
4. It's much smaller than a VM image. 4. It's much smaller than a VM image.
5. When converted into a singularity container, it can be launched as a single 5. When converted into a Apptainer SIF, it can be launched as a single binary
binary executable. executable.
User Tools
----------
The containers are built with several additional user tools already in place,
including but not limited to:
1. `vim`/`emacs`: text editing.
2. `git`: version control.
3. `tmux`: terminal multiplexing.
3. `tshark`/`termshark`/`tcpdump`: packets inspection.
4. `htop`: visual overview of processes.
5. `man`/`less`: documentation support.
How to Use How to Use
---------- ----------
There are two ways of launching P4-in-a-Bottle: There are two ways of launching P4-in-a-Bottle:
### Singularity ### Apptainer
Singularity is a container runtime by Sylabs developed specificly for software Apptainer is a new container runtime developed specificly for software that
that require low-level access to hardware (i.e. NVIDIA drivers, network require low-level access to hardware (i.e. NVIDIA drivers, network devices,
devices). This is great for P4-in-a-Bottle, since Mininet requires access to etc). This is great for P4-in-a-Bottle, since Mininet requires access to
networking kernel components to work. networking kernel components to work.
Unfortunately, Singularity only works natively on Linux, so if you're on Mac or Unfortunately, Apptainer only works natively on Linux, so if you're on Mac or
Windows (without WSL), you're out-of-luck here and should proceed to the docker Windows (without WSL), you're out-of-luck here and should proceed to the docker
instructions below. instructions below.
To use P4-in-a-Bottle with Singularity: To use P4-in-a-Bottle with Apptainer:
1. Install singularity from [GitHub](https://github.com/sylabs/singularity/releases). 1. Install Apptainer from [GitHub](https://github.com/apptainer/apptainer/releases).
2. Download a pre-built image `p4iab.sif` and place it in the same directory 2. Clone and cd into this repository.
as this README. If you skip this step YOU WILL BUILD BOTH THE DOCKER 3. Download a pre-built image
CONTAINER AND THE SINGULARITY CONTAINER FROM SOURCE. (Trust me, you do NOT [p4iab.sif](https://git.inkweaver.net/inkweaver/P4-in-a-Bottle/releases)
want to build this yourself). and place it in the same directory alongside `README.md`.
3. Run `make sc-run`. A shared directory `shared/` will be created to allow 4. Run `make app-run`. A shared directory `shared/` will be created to allow
you to move files between the container and your system. you to move files between the container and your system.
### Docker ### Docker
If you are stuck with docker, don't panic! The instructions are longer but If you are stuck with docker, don't panic! The instructions are slightly more
everything should still work. complicated but everything should still work.
1. Install docker on your system. This should be pretty self-explanatory. 1. Install docker on your system. This should be pretty self-explanatory.
2. Download a pre-built image `p4iab.tar.gz` and place it in the same directory 2. Clone and cd into this repository.
as this README. Then run `docker load -i p4iab.tar.gz && touch .docker_build`. 3. Download a pre-built image
If you skip this step YOU WILL BUILD THE DOCKER CONTAINER FROM SOURCE. Do [p4iab.tar.gz](https://git.inkweaver.net/inkweaver/P4-in-a-Bottle/releases)
so only if you know what you are doing. and place it in the same directory alongside `README.md`.
3. Run `make run`. A shared directory `shared/` will be created to allow 4. Run `docker load -i p4iab.tar.gz` to import the container into docker.
5. Run `make run`. A shared directory `shared/` will be created to allow
you to move files between the container and your system. you to move files between the container and your system.
Regardless of which method you run the container, you will be dropped into a
shell with the user P4. The password for the P4 user account is simply `p4`.
Building from Source Building from Source
-------------------- --------------------
@ -80,10 +97,13 @@ $ make .docker_build
# Building a docker image that can be imported on other machines # Building a docker image that can be imported on other machines
$ make p4iab.tar.gz $ make p4iab.tar.gz
# Building a singularity image (This depends on the docker image) # Building a Apptainer image (This depends on the docker image)
$ make p4iab.sif $ make p4iab.sif
# Cleanup any cached artifacts # Cleanup any cached artifacts
$ make clean $ make clean
``` ```
Once you have either `p4iab.tar.gz` or `p4iab.sif`, proceed to follow the
instructions in the "How to Use" section from step 4.

View File

@ -1,5 +1,5 @@
BootStrap: docker-archive BootStrap: docker-daemon
From: p4iab.tar.gz From: p4iab:latest
%files %files
scripts/p4iab_singularity_entry.sh /usr/bin/p4iab_singularity_entry.sh scripts/p4iab_singularity_entry.sh /usr/bin/p4iab_singularity_entry.sh