Skip to content
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

Fix CI pipeline & devcontainer setup #70

Merged
merged 6 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
FROM debian:bullseye
# There are a few Dockerfile restrictions when using Github Actions
# See: https://docs.github.com/en/actions/creating-actions/dockerfile-support-for-github-actions

FROM debian:bullseye-slim
ENV DEBIAN_FRONTEND=noninteractive
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ARG CONTAINER_USER=esp
ARG CONTAINER_GROUP=esp
ARG NIGHTLY_VERSION=nightly-2022-03-10
ARG ESP_IDF_VERSION=release/v4.4
ARG ESP_BOARD=esp32c3

RUN apt-get update \
&& apt-get install -y vim nano git curl gcc ninja-build cmake libudev-dev \
python3 python3-pip libusb-1.0-0 libssl-dev pkg-config libtinfo5 clang \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
RUN adduser --disabled-password --gecos "" ${CONTAINER_USER}
USER ${CONTAINER_USER}
WORKDIR /home/${CONTAINER_USER}
&& apt-get install -y git curl ninja-build clang libudev-dev \
python3 python3-pip libusb-1.0-0 libssl-dev pkg-config libtinfo5 \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* /tmp/library-scripts

ENV PATH=${PATH}:$HOME/.cargo/bin

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
--default-toolchain ${NIGHTLY_VERSION} -y \
--default-toolchain ${NIGHTLY_VERSION} -y --profile minimal \
&& $HOME/.cargo/bin/rustup component add rust-src --toolchain ${NIGHTLY_VERSION} \
&& $HOME/.cargo/bin/rustup target add riscv32i-unknown-none-elf \
&& $HOME/.cargo/bin/cargo install cargo-generate cargo-espflash espmonitor bindgen ldproxy
ENV ESP_BOARD=esp32c3
ENV ESP_IDF_VERSION=release/v4.4
&& $HOME/.cargo/bin/rustup target add riscv32i-unknown-none-elf

RUN $HOME/.cargo/bin/cargo install cargo-espflash espmonitor ldproxy

RUN mkdir -p .espressif/frameworks/ \
&& git clone --branch ${ESP_IDF_VERSION} -q --depth 1 --shallow-submodules \
--recursive https://github.com/espressif/esp-idf.git \
.espressif/frameworks/esp-idf-v4.4 \
&& python3 .espressif/frameworks/esp-idf-v4.4/tools/idf_tools.py install cmake \
&& .espressif/frameworks/esp-idf-v4.4/install.sh ${ESP_BOARD} \
&& rm -rf .espressif/dist \
&& rm -rf .espressif/frameworks/esp-idf-v4.4/docs
CMD "/bin/bash"
&& rm -rf .espressif/frameworks/esp-idf-v4.4/docs \
&& rm -rf .espressif/frameworks/esp-idf-v4.4/examples \
&& rm -rf .espressif/frameworks/esp-idf-v4.4/tools/esp_app_trace \
&& rm -rf .espressif/frameworks/esp-idf-v4.4/tools/test_idf_size

ENV IDF_TOOLS_PATH=/root/.espressif
RUN echo "source /root/.espressif/frameworks/esp-idf-v4.4/export.sh > /dev/null 2>&1" >> ~/.bashrc

CMD "/bin/bash"
16 changes: 8 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"build": {
"dockerfile": "Dockerfile",
"args": {
"NIGHTLY_VERSION": "nightly-2022-03-10",
"CONTAINER_USER": "esp"
"NIGHTLY_VERSION": "nightly-2022-03-10"
}
},
"settings": {
Expand All @@ -18,17 +17,18 @@
},
"rust-analyzer.checkOnSave.command": "clippy",
"[rust]": {
"editor.defaultFormatter": "matklad.rust-analyzer"
},
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
},
"extensions": [
"matklad.rust-analyzer",
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"vadimcn.vscode-lldb",
"serayuzgur.crates",
"mutantdino.resourcemonitor",
"yzhang.markdown-all-in-one",
"yzhang.markdown-all-in-one"
],
"workspaceMount": "source=${localWorkspaceFolder},target=/home/esp/workspace,type=bind,consistency=cached",
"workspaceFolder": "/home/esp/workspace/"
"remoteUser": "root",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
"workspaceFolder": "/workspace"
}
2 changes: 1 addition & 1 deletion .devcontainer/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -ef

WORK_DIR=$HOME/workspace
WORK_DIR=/workspace

echo "Compiling all exercises & library crates"
for file in $(find ${WORK_DIR} -name "Cargo.toml")
Expand Down
21 changes: 9 additions & 12 deletions .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
---
name: Build Docker Image
name: Docker Image

on:
pull_request:
paths:
- '!book/**'
branches:
- main
push:
paths:
- '!book/**'
branches:
- main
branches: [main]
pull_request:
branches: [main]
paths-ignore:
- "book/"

jobs:
# To avoid uploading the Docker image to a registry yet
# the image is built here & immediately used to test all exercises in.
# TODO at a later point split that into separate jobs
build_image_and_test:
name: Build & test image
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
Expand All @@ -28,5 +25,5 @@ jobs:

- name: Test code examples in Docker image
run: |
docker run --user esp --mount type=bind,source="$(pwd)",target=/home/esp/workspace,consistency=cached \
--rm -it esp:latest /bin/bash /home/esp/workspace/.devcontainer/test.sh
docker run --mount type=bind,source="$(pwd)",target=/workspace,consistency=cached \
--rm esp:latest /bin/bash /workspace/.devcontainer/test.sh
4 changes: 2 additions & 2 deletions book/src/02_2_software.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ Building the image takes a while depending on the OS & hardware (20-30 minutes).
To start the new Docker container run:

```console
$ docker run --user esp --mount type=bind,source="$(pwd)",target=/home/esp/workspace,consistency=cached -it esp /bin/bash
$ docker run --mount type=bind,source="$(pwd)",target=/workspace,consistency=cached -it esp /bin/bash
```

This starts an interactive shell in the Docker container. It also mounts the local repository to a folder
named `/home/esp/workspace` inside the container. Changes to the project on the host system are reflected inside the container & vice versa.
named `/workspace` inside the container. Changes to the project on the host system are reflected inside the container & vice versa.

Using this Docker setup requires certain commands to run inside the container, while other have to be executed on the host system.
It's recommended to keep two terminals open, one connected to the Docker container, one on the host system.
Expand Down