Skip to content

Commit

Permalink
Add devcontainer integration for vscode
Browse files Browse the repository at this point in the history
This will auto setup the whole build environment based on zephyr's docker containers. Prerequisites are:
- docker is accessable by the user without using sudo
- vscode with remote container extension is installed

Signed-off-by: Andreas Kurz <[email protected]>
  • Loading branch information
andreas-kurz committed Sep 18, 2023
1 parent 77a4290 commit a0dd349
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
ARG ZEPHYR_TAG=latest
FROM zephyrprojectrtos/ci:${ZEPHYR_TAG}

# Set default to bash instead sh
ENV SHELL /bin/bash

RUN add-apt-repository ppa:tiac-systems/doxygen

# Install packages
RUN apt-get -y update && \
apt-get -y upgrade && \
apt-get install --no-install-recommends -y \
doxygen \
graphviz \
mscgen \
latexmk \
librsvg2-bin \
texlive-latex-base \
texlive-latex-extra \
texlive-fonts-recommended \
usbutils \
vim

# Clean up stale packages
RUN apt-get clean -y && \
apt-get autoremove --purge -y && \
rm -rf /var/lib/apt/lists/*

# Add bash completion script
ADD ./bash_completion /home/user/.bash_completion
RUN mkdir -p /home/user/.bash_completion.d

# Switch to 'user' context
USER user

RUN mkdir -p /home/user/.vscode-server/extensions

# Set working directory
WORKDIR /workdir
VOLUME ["/workdir"]

# Adjust 'user' home directory permissions
USER root
RUN chown -R user:user /home/user

# Make 'user' default on launch
USER user

# Launch bash shell by default
CMD ["/bin/bash"]
3 changes: 3 additions & 0 deletions .devcontainer/bash_completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for bcfile in ~/.bash_completion.d/* ; do
. $bcfile
done
35 changes: 35 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

{
"name": "Bridle",
"build": {
"dockerfile": "Dockerfile",
// Specify version for Zephyr Container
// See https://github.com/zephyrproject-rtos/docker-image/releases
"args": { "ZEPHYR_TAG": "v0.26.4" }
},
// Needed for USB devices in container
"privileged": true,
"postCreateCommand": "bash .devcontainer/post-create.sh /workspace ${localWorkspaceFolderBasename}",
"postStartCommand": "bash .devcontainer/post-start.sh /workspace",
// Mount and set workspace folder
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspace,type=bind",
"workspaceFolder": "/workspace/${localWorkspaceFolderBasename}",
// Username in container - align with Dockerfil
"remoteUser": "user",
"mounts": [
// Persist installed extensions in container
"source=bridle-devcontainer-extensions,target=/home/user/.vscode-server/extensions,type=volume",
// Allow attaching USB devices to running container
"source=/dev/bus/usb,target=/dev/bus/usb,type=bind"
],"customizations": {
"vscode": {
"settings": {
"editor.trimAutoWhitespace": true,
"editor.insertFinalNewline": true
},
"extensions": [
"marus25.cortex-debug"
]
}
}
}
17 changes: 17 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

WORKSPACE_DIR=$1
REPO_NAME=$2

cd $WORKSPACE_DIR

if [ ! -d ".west" ]; then
west init -l $REPO_NAME
fi

west update
west bridle-export


pip3 install --upgrade --requirement zephyr/scripts/requirements.txt
pip3 install --upgrade --requirement bridle/scripts/requirements.txt
7 changes: 7 additions & 0 deletions .devcontainer/post-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

WORKSPACE_DIR=$1

cd $WORKSPACE_DIR

west update
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@

# Get all docs reviewed
*.rst @rexut

# Devcontainer setup for vscode
/.devcontainer/ @rexut

0 comments on commit a0dd349

Please sign in to comment.