Difference between revisions of "Containers 2026"
m (Add to notes on container config) |
m (Docker Maintenance Commands : add some commands to show things) |
||
| (19 intermediate revisions by the same user not shown) | |||
| Line 12: | Line 12: | ||
(3) https://embedded-house.ghost.io/zephyr-with-dev-containers/ | (3) https://embedded-house.ghost.io/zephyr-with-dev-containers/ | ||
| + | |||
| + | Goliath company post on devcontainers: | ||
| + | |||
| + | (4) https://blog.golioth.io/build-before-installing-zephyr-dev-environment-using-codespaces/ | ||
| + | |||
| + | An example .devcontainer file here but article is Java specific an talks a lot about a Java project. | ||
| + | |||
| + | (5) https://medium.com/versent-tech-blog/introduction-to-dev-containers-4c01cb1752a0 | ||
| + | |||
| + | Best article yet, more general but good explanation: | ||
| + | |||
| + | (6) https://containers.dev/guide/dockerfile | ||
| + | |||
| + | A github project with example `devcontainer.json` and `docker-compose.yml`: | ||
| + | |||
| + | (7) https://forge.hefr.ch/serge.ayer/zephyr-dev-devcontainer/-/blob/main/.devcontainer/docker-compose.yml?ref_type=heads | ||
| + | |||
| + | ZephyrRTOS-Project docker image repo: | ||
| + | |||
| + | (8) https://github.com/zephyrproject-rtos/docker-image | ||
| + | |||
| + | |||
| + | |||
| + | Post commands support: | ||
| + | |||
| + | * https://github.com/orgs/community/discussions/73403#discussioncomment-7475535 | ||
| + | |||
| + | |||
| + | |||
| + | First Docker compose based container set up: | ||
| + | <!-- | ||
| + | <pre> | ||
| + | ted@locahost:~/projects/container-based/kionix-driver-demo$ docker compose -f .devcontainer/docker-compose.yml up -d | ||
| + | [+] Running 3/5 | ||
| + | ⠹ zephyr [⣿⣿⣿⣿] 6.494GB / 6.494GB Pulling 2784.1s ✔ b6c3685423e2 Pull complete 50.2s | ||
| + | ✔ ea8c0f427f08 Pull complete 2425.1s ⠙ 228aca692183 Extracting [==================================================>] 3.803GB/3.803GB 2783.1s | ||
| + | ✔ 0eefaa52e6bb Download complete 152.0s failed to register layer: archive/tar: invalid tar header | ||
| + | ted@locahost:~/projects/container-based/kionix-driver-demo$ docker compose -f .devcontainer/docker-compose.yml up -d | ||
| + | [+] Running 5/5 | ||
| + | ✔ zephyr Pulled 2821.4s ✔ b6c3685423e2 Already exists 0.0s | ||
| + | ✔ ea8c0f427f08 Pull complete 2051.7s | ||
| + | ✔ 228aca692183 Pull complete 2819.4s | ||
| + | ✔ 0eefaa52e6bb Pull complete 2820.4s | ||
| + | [+] Running 2/2 | ||
| + | ✔ Network devcontainer_default Created 0.0s | ||
| + | ✔ Container devcontainer-zephyr-1 Started | ||
| + | </pre> | ||
| + | --> | ||
| + | |||
| + | Notes about devcontainer start up script elements | ||
| + | |||
| + | To build on localhost using the Docker composed container, a start up script cam be written in the Zephyr or other local copy of a project, to check for and to invoke `devcontainer` with necessary arguments. | ||
| + | |||
| + | Such a script will likely first assure that it is running from the same directory as where the `.devcontainer` folder lives, if it is not already there. The scripts may then: | ||
| + | |||
| + | [ ] check that `devcontainer` is installed by trying to call it (shell built-in `command` may be helpful with this test) | ||
| + | [ ] assure that a `docker_cache` directory exists in the project root dir | ||
| + | (create `./docker_cache` if not found) | ||
| + | [ ] check whether the container is running and if not start it (see note 1) | ||
| + | [ ] check whether any project specific container config is complete | ||
| + | |||
| + | Notes: | ||
| + | (1) The checks for "container running" and "config complete" can be combined into a single function. This reflects the fact that we likely only want to run the container and have our container start helper script report success when the container is fully configured for the given project. | ||
| + | |||
| + | Other functions in the helper script call `devcontainer` with tokens which start with its `exec` option. In a shell script, this `exec` option is usually followed by a double quoted string to express the commands we would issue at a command shell. For example, commands to build the app, to build menuconfig, to execute tests, and related things. | ||
| + | |||
| + | == devcontainer exec uses == | ||
| + | |||
| + | Stuart Leeks help document on devcontainer exec use: | ||
| + | |||
| + | * https://github.com/stuartleeks/devcontainer-cli/blob/main/docs/exec.md | ||
| + | |||
| + | == @devcontainers/cli == | ||
| + | |||
| + | Important to install the following Python scripts mentioned here: | ||
| + | |||
| + | * https://github.com/devcontainers/cli | ||
| + | |||
| + | Command is: | ||
| + | |||
| + | $ npm install -g @devcontainers/cli | ||
| + | |||
| + | WorkspaceMount and workspaceFolder options: | ||
| + | |||
| + | * https://stackoverflow.com/questions/77293917/how-to-mount-source-code-in-a-devcontainer-at-build-time | ||
| + | |||
| + | == Docker Introspective Commands == | ||
| + | |||
| + | To format the output of `docker ps -a` which truncates some output by default: | ||
| + | |||
| + | * https://www.baeldung.com/ops/docker-container-view-complete-commands | ||
| + | |||
| + | == Docker Maintenance Commands == | ||
| + | |||
| + | A comprehensive list of Docker commands to remove Docker file artifacts, including Docker containers, images, volumes and networks: | ||
| + | |||
| + | * https://shisho.dev/blog/posts/docker-remove-cheatsheet/ | ||
| + | |||
| + | Showing stuff: | ||
| + | |||
| + | $ docker ps -a | ||
| + | |||
| + | $ docker image ls -a | ||
| + | |||
| + | Removing a lot of stuff, use with care!: | ||
| + | |||
| + | $ docker system prune | ||
| + | |||
| + | == devcontainer CLI examples == | ||
| + | |||
| + | Can we get the following to work? . . . | ||
| + | |||
| + | * https://github.com/devcontainers/cli/blob/main/example-usage/ci-app-build-script/build-application.sh | ||
| + | |||
| + | An example layout of devcontainer config files and scripts is here: | ||
| + | |||
| + | * https://github.com/devcontainers/cli/tree/main/example-usage/workspace | ||
| + | |||
| + | |||
| + | <!-- | ||
| + | ========= ========= ========= ========= ========= ========= ========= ========= ========= ========= ========= | ||
| + | |||
| + | # Dockerfile based on zephyrprojectrtos/ci image | ||
| + | # ref: https://github.com/zephyrproject-rtos/docker-image/blob/main/Dockerfile.ci | ||
| + | |||
| + | FROM ubuntu:24.04 | ||
| + | |||
| + | # Avoid interactive prompts | ||
| + | ENV DEBIAN_FRONTEND=noninteractive | ||
| + | |||
| + | ARG USERNAME=user | ||
| + | ARG UID=1000 | ||
| + | ARG GID=1000 | ||
| + | ENV PYTHON_VENV_PATH=/opt/python/venv | ||
| + | |||
| + | # Set default shell during Docker image build to bash | ||
| + | SHELL ["/bin/bash", "-eo", "pipefail", "-c"] | ||
| + | |||
| + | # Install system dependencies (minimal set from zephyr base) | ||
| + | RUN apt-get update && \ | ||
| + | apt-get install -y --no-install-recommends \ | ||
| + | git \ | ||
| + | cmake \ | ||
| + | ninja-build \ | ||
| + | gperf \ | ||
| + | ccache \ | ||
| + | dfu-util \ | ||
| + | device-tree-compiler \ | ||
| + | openssh-client \ | ||
| + | wget \ | ||
| + | patch \ | ||
| + | python3-dev \ | ||
| + | python3-pip \ | ||
| + | python3-setuptools \ | ||
| + | python3-tk \ | ||
| + | python3-venv \ | ||
| + | python-is-python3 \ | ||
| + | xz-utils \ | ||
| + | file \ | ||
| + | make gcc \ | ||
| + | gcc-multilib \ | ||
| + | g++-multilib \ | ||
| + | libsdl2-dev \ | ||
| + | libmagic1 \ | ||
| + | unzip \ | ||
| + | sudo \ | ||
| + | wget \ | ||
| + | && rm -rf /var/lib/apt/lists/* \ | ||
| + | && apt-get clean | ||
| + | |||
| + | # Set up Python virtual environment | ||
| + | RUN <<EOF | ||
| + | # Initialize virtual environment | ||
| + | mkdir -p ${PYTHON_VENV_PATH} | ||
| + | python3 -m venv ${PYTHON_VENV_PATH} | ||
| + | |||
| + | # Activate virtual environment and install Python packages | ||
| + | source ${PYTHON_VENV_PATH}/bin/activate | ||
| + | |||
| + | # Install pip package manager | ||
| + | pip install --no-cache-dir --upgrade pip setuptools wheel | ||
| + | pip install --no-cache-dir \ | ||
| + | -r https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/v4.3.0/scripts/requirements-base.txt \ | ||
| + | -r https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/v4.3.0/scripts/requirements-build-test.txt \ | ||
| + | -r https://raw.githubusercontent.com/zephyrproject-rtos/zephyr/v4.3.0/scripts/requirements-run-test.txt \ | ||
| + | grpcio-tools | ||
| + | EOF | ||
| + | |||
| + | # Make Zephyr Python virtual environment available system-wide | ||
| + | ENV PATH="${PYTHON_VENV_PATH}/bin:${PATH}" | ||
| + | |||
| + | # Install Zephyr SDK 0.17.4 | ||
| + | ENV ZEPHYR_SDK_VERSION=0.17.4 | ||
| + | ENV ZEPHYR_SDK_INSTALL_DIR=/opt/toolchains/zephyr-sdk-${ZEPHYR_SDK_VERSION} | ||
| + | RUN <<EOF | ||
| + | mkdir -p /opt/toolchains | ||
| + | cd /opt/toolchains | ||
| + | wget -q https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${ZEPHYR_SDK_VERSION}/zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64_minimal.tar.xz | ||
| + | tar -xf zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64_minimal.tar.xz -C /opt/toolchains | ||
| + | rm zephyr-sdk-${ZEPHYR_SDK_VERSION}_linux-x86_64_minimal.tar.xz | ||
| + | cd ${ZEPHYR_SDK_INSTALL_DIR} | ||
| + | ./setup.sh -t arm-zephyr-eabi -h -c | ||
| + | EOF | ||
| + | |||
| + | # Set environment variables | ||
| + | ENV ZEPHYR_TOOLCHAIN_VARIANT=zephyr | ||
| + | |||
| + | # Create user and add it to plugdev and dialout | ||
| + | # to have proper access to usb devices | ||
| + | RUN userdel -r ubuntu && \ | ||
| + | groupadd -g $UID $USERNAME && \ | ||
| + | useradd -u $UID -g $GID -s /bin/bash -m $USERNAME && \ | ||
| + | usermod -a -G dialout $USERNAME && \ | ||
| + | usermod -a -G plugdev $USERNAME && \ | ||
| + | echo $USERNAME ' ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers | ||
| + | |||
| + | USER $USERNAME | ||
| + | RUN cd ${ZEPHYR_SDK_INSTALL_DIR} && ./setup.sh -c | ||
| + | |||
| + | # Set working directory | ||
| + | WORKDIR /workdir | ||
| + | CMD ["/bin/bash"] | ||
| + | |||
| + | ========= ========= ========= ========= ========= ========= ========= ========= ========= ========= ========= | ||
| + | --> | ||
| + | |||
| + | <!-- | ||
| + | #!/bin/bash | ||
| + | |||
| + | set -e | ||
| + | |||
| + | complete_setup() { | ||
| + | touch /workdir/setup_complete | ||
| + | } | ||
| + | |||
| + | is_setup_complete() { | ||
| + | [ -f /workdir/setup_complete ] | ||
| + | } | ||
| + | |||
| + | setup() { | ||
| + | if [ ! -d /workdir/.west ]; then | ||
| + | west init -l | ||
| + | else | ||
| + | echo "West already initialized." | ||
| + | fi | ||
| + | |||
| + | echo "Adding extra modules and calling \`west\` to update SDK..." | ||
| + | west update | ||
| + | west zephyr-export | ||
| + | # ./scripts/spi-nor-patch/apply-spi-nor-patch.sh | ||
| + | complete_setup | ||
| + | } | ||
| + | |||
| + | # Skip if already initialized | ||
| + | if is_setup_complete; then | ||
| + | echo "Setup already completed." | ||
| + | else | ||
| + | setup | ||
| + | fi | ||
| + | --> | ||
| + | |||
| + | <!-- | ||
| + | https://godbolt.org/z/n5hdMedaz | ||
| + | --> | ||
Latest revision as of 21:11, 27 January 2026
Note on Devcontainers
Found this first:
Followed only the install step of these steps . . . this article seems to be talking about some software called "Zephyr" which is unrelated to Zephyr RTOS Project:
(2) https://docs.docker.com/engine/install/ubuntu/s
Mention here of `compose.yml`:
(3) https://embedded-house.ghost.io/zephyr-with-dev-containers/
Goliath company post on devcontainers:
(4) https://blog.golioth.io/build-before-installing-zephyr-dev-environment-using-codespaces/
An example .devcontainer file here but article is Java specific an talks a lot about a Java project.
(5) https://medium.com/versent-tech-blog/introduction-to-dev-containers-4c01cb1752a0
Best article yet, more general but good explanation:
(6) https://containers.dev/guide/dockerfile
A github project with example `devcontainer.json` and `docker-compose.yml`:
ZephyrRTOS-Project docker image repo:
(8) https://github.com/zephyrproject-rtos/docker-image
Post commands support:
First Docker compose based container set up:
Notes about devcontainer start up script elements
To build on localhost using the Docker composed container, a start up script cam be written in the Zephyr or other local copy of a project, to check for and to invoke `devcontainer` with necessary arguments.
Such a script will likely first assure that it is running from the same directory as where the `.devcontainer` folder lives, if it is not already there. The scripts may then:
[ ] check that `devcontainer` is installed by trying to call it (shell built-in `command` may be helpful with this test) [ ] assure that a `docker_cache` directory exists in the project root dir
(create `./docker_cache` if not found)
[ ] check whether the container is running and if not start it (see note 1) [ ] check whether any project specific container config is complete
Notes: (1) The checks for "container running" and "config complete" can be combined into a single function. This reflects the fact that we likely only want to run the container and have our container start helper script report success when the container is fully configured for the given project.
Other functions in the helper script call `devcontainer` with tokens which start with its `exec` option. In a shell script, this `exec` option is usually followed by a double quoted string to express the commands we would issue at a command shell. For example, commands to build the app, to build menuconfig, to execute tests, and related things.
devcontainer exec uses
Stuart Leeks help document on devcontainer exec use:
@devcontainers/cli
Important to install the following Python scripts mentioned here:
Command is:
$ npm install -g @devcontainers/cli
WorkspaceMount and workspaceFolder options:
Docker Introspective Commands
To format the output of `docker ps -a` which truncates some output by default:
Docker Maintenance Commands
A comprehensive list of Docker commands to remove Docker file artifacts, including Docker containers, images, volumes and networks:
Showing stuff:
$ docker ps -a
$ docker image ls -a
Removing a lot of stuff, use with care!:
$ docker system prune
devcontainer CLI examples
Can we get the following to work? . . .
An example layout of devcontainer config files and scripts is here: