mirror of
https://gitlab.eurecom.fr/oai/openairinterface5g.git
synced 2026-07-13 04:30:28 +00:00
Dockerized development environment
This commit introduces a fully dockerized dev env you can start on any machine that has docker without installing any direct OAI dependencies on host. This allows to migrate development environments between machines easily. Several complementary scripts were added to enable smooth transition between your docker environment and host environment. Your user and sudo should work inside the environment.
This commit is contained in:
committed by
Robert Schmidt
parent
e0549de9ea
commit
8ca0a80d17
41
tools/docker-dev-env/Dockerfile
Normal file
41
tools/docker-dev-env/Dockerfile
Normal file
@@ -0,0 +1,41 @@
|
||||
FROM ran-base:latest
|
||||
ARG USERNAME=root
|
||||
ARG USER_UID=1000
|
||||
ARG USER_GID=1000
|
||||
|
||||
# More developer tools can be added here
|
||||
RUN apt update && apt install -y vim sudo wget meson ninja-build libnuma-dev ccache
|
||||
|
||||
# Create the user
|
||||
RUN groupadd --gid $USER_GID $USERNAME \
|
||||
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
|
||||
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
|
||||
&& chmod 0440 /etc/sudoers.d/$USERNAME
|
||||
|
||||
## Download and build DPDK
|
||||
RUN cd /oai-ran && \
|
||||
wget http://fast.dpdk.org/rel/dpdk-20.11.9.tar.xz && \
|
||||
tar -xvf dpdk-20.11.9.tar.xz && \
|
||||
cd dpdk-stable-20.11.9 && \
|
||||
meson build && \
|
||||
ninja -C build && \
|
||||
ninja install -C build
|
||||
|
||||
## Build Fronthaul library
|
||||
COPY cmake_targets/tools/oran_fhi_integration_patches/F/oaioran_F.patch /oaioran_F.patch
|
||||
RUN git clone https://gerrit.o-ran-sc.org/r/o-du/phy.git /opt/phy && \
|
||||
cd /opt/phy && \
|
||||
git checkout oran_f_release_v1.0 &&\
|
||||
git apply /oaioran_F.patch && \
|
||||
cd /opt/phy/fhi_lib/lib && \
|
||||
WIRELESS_SDK_TOOLCHAIN=gcc RTE_SDK=/oai-ran/dpdk-stable-20.11.9/ XRAN_DIR=/opt/phy/fhi_lib make XRAN_LIB_SO=1
|
||||
ENV xran_LOCATION=/opt/phy/fhi_lib/lib/
|
||||
|
||||
# This is a temporary solution to issue with apt: one of the installed packages creates a group that may
|
||||
# not be present in the host: remove the group entry to allow apt usage in container
|
||||
RUN dpkg-statoverride --remove /usr/bin/uml_net
|
||||
|
||||
# Override ccache directory to avoid permission issues
|
||||
ENV CCACHE_DIR=/home/$USERNAME/.cache/ccache-oai-dev-env
|
||||
|
||||
USER $USERNAME
|
||||
48
tools/docker-dev-env/README.md
Normal file
48
tools/docker-dev-env/README.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# Containerized development environment for OAI
|
||||
|
||||
## Description
|
||||
|
||||
This contains bash scripts for managing a ubuntu22 dockerized development enviroment for OAI. No need to install any
|
||||
tools on host machines except for docker
|
||||
|
||||
- `bootstrap.sh` - build development environment image and install the following bash aliases in `~/.bash_aliases`:
|
||||
* `oai_start_dev_env` - start the development environment container and detach
|
||||
* `oai_stop_dev_env` - stop the development environment container
|
||||
* `oai_destroy_dev_env` - remove the container, deleting all data that is not on mapped volumes. All packages installed
|
||||
using `apt` or other methods in system folders (e.g. `/usr/`) will be removed.
|
||||
* `oai_enter_dev_env` - enter development environment
|
||||
|
||||
## Installing
|
||||
|
||||
Run `./bootstrap.sh`. This will build the `ran-base:latest` image if its not present on the system and
|
||||
build the `openair-dev:$USER` image and install the aliases above.
|
||||
|
||||
If not present, please add `source ~/.bash_aliases` into your `~/.bashrc`.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- The `bootstrap.sh` script will read the current environment to generate the docker image, running
|
||||
it with sudo is not recommended.
|
||||
- Your home directory is shared with the home directory inside the docker container.
|
||||
- You can use the `oai_enter_dev_env` alias to enter the container from any directory within
|
||||
your home directory - your home directory is mapped directly in the container. If you
|
||||
need other directories to be mapped, add extra volumes to the `docker-compose.yml`
|
||||
|
||||
## Using sudo in container
|
||||
|
||||
`sudo` is not necessary in the container as it should already have the linux capabilities that running
|
||||
OAI requires. However it is still possible to run `sudo` in the container.
|
||||
|
||||
## Updating and preserving your image
|
||||
|
||||
Each image is personally tagged with username. You can update your image (e.g. install ubuntu system packages)
|
||||
either through modifying the Dockerfile (not recommended) or installing packages manually through `apt` and
|
||||
saving the docker container snapshot. If the environment is running just type
|
||||
|
||||
```
|
||||
docker commit openair-dev-$USER openair-dev:$USER
|
||||
```
|
||||
|
||||
This will update the image that is used in the aliases and preserve the modifications when you start the environment again.
|
||||
|
||||
If you ever want to reset your image to the base prepared here just rerun the `bootstrap.sh` script
|
||||
39
tools/docker-dev-env/bootstrap.sh
Executable file
39
tools/docker-dev-env/bootstrap.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
CONTAINER_NAME=openair-dev-$USER
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
read -p "You are running this script as root. This might not work as expected. Do you want to continue? (Y/N): " response
|
||||
if [[ ! "$response" =~ ^[Yy]$ ]]; then
|
||||
echo "Exiting script."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! docker images | grep -q "ran-base"; then
|
||||
echo "ran-base:latest image not found. Building the image..."
|
||||
docker build -f ../../docker/Dockerfile.base.ubuntu22 -t ran-base:latest ../../
|
||||
else
|
||||
echo "ran-base:latest image found."
|
||||
fi
|
||||
|
||||
echo "Starting the build process for the Docker container..."
|
||||
docker build -f Dockerfile -t openair-dev:$USER --build-arg USERNAME=$USER --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -u) ../../
|
||||
|
||||
echo -e "\e[93mInstalling aliases to ~/.bash_aliases. Make sure to add 'source ~/.bash_aliases' in ~/.bashrc \e[0m"
|
||||
mkdir -p ~/oai-dev-env
|
||||
cp docker-compose.yml ~/oai-dev-env
|
||||
|
||||
touch ~/.bash_aliases
|
||||
|
||||
function add_alias() {
|
||||
local alias=${1} cmd=${2}
|
||||
if grep -q "${alias}" ~/.bash_aliases; then echo "cannot add alias ${alias}: already exists in ~/.bash_aliases"; return 1; fi
|
||||
echo "alias ${alias}='${cmd}'" >> ~/.bash_aliases
|
||||
}
|
||||
|
||||
add_alias oai_start_dev_env 'docker compose -f ~/oai-dev-env/docker-compose.yml up -d' || true
|
||||
add_alias oai_stop_dev_env 'docker compose -f ~/oai-dev-env/docker-compose.yml down' || true
|
||||
add_alias oai_enter_dev_env "docker exec -it -w \$(pwd) $CONTAINER_NAME /bin/bash" || true
|
||||
add_alias oai_destroy_dev_env "docker container rm -f ${CONTAINER_NAME}" || true
|
||||
|
||||
source ~/.bash_aliases
|
||||
21
tools/docker-dev-env/docker-compose.yml
Normal file
21
tools/docker-dev-env/docker-compose.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
services:
|
||||
openair-dev-env:
|
||||
container_name: "openair-dev-${USER}"
|
||||
image: openair-dev:${USER}
|
||||
command: "sleep infinity"
|
||||
privileged: false
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
- SYS_ADMIN
|
||||
- NET_RAW
|
||||
- SYS_NICE
|
||||
# CAPS for sudo to work
|
||||
- CAP_SETUID
|
||||
- CAP_SETGID
|
||||
- CAP_SETFCAP
|
||||
- CAP_AUDIT_WRITE
|
||||
- CAP_MKNOD
|
||||
volumes:
|
||||
- /home/${USER}:/home/${USER}
|
||||
working_dir: /home/${USER}
|
||||
hostname: oai-dev-env
|
||||
Reference in New Issue
Block a user