Skip to content

Commit 74cc0c7

Browse files
committed
feat: mqtt example devcontainers
1 parent 9c9613c commit 74cc0c7

File tree

6 files changed

+233
-1
lines changed

6 files changed

+233
-1
lines changed

mqtt_example/.cargo/config.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ target = "xtensa-esp32-espidf"
33

44
[target.xtensa-esp32-espidf]
55
linker = "ldproxy"
6-
runner = "espflash flash --monitor"
6+
# Use web-flash on mac instead
7+
runner = "web-flash --chip=esp32 "
8+
#runner = "espflash flash --monitor"
79
rustflags = ["--cfg", "espidf_time64"]
810

911
[unstable]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
ARG VARIANT=bookworm-slim
2+
FROM debian:${VARIANT}
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV LC_ALL=C.UTF-8
5+
ENV LANG=C.UTF-8
6+
7+
# Arguments
8+
ARG CONTAINER_USER=esp
9+
ARG CONTAINER_GROUP=esp
10+
ARG PROJECT_DIR
11+
ARG ESP_BOARD=all
12+
ARG GITHUB_TOKEN
13+
14+
# Install dependencies
15+
RUN apt-get update \
16+
&& apt-get install -y pkg-config curl gcc clang libudev-dev unzip xz-utils \
17+
git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 \
18+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
19+
20+
# Set users
21+
RUN adduser --disabled-password --gecos "" ${CONTAINER_USER}
22+
USER ${CONTAINER_USER}
23+
WORKDIR /home/${CONTAINER_USER}
24+
RUN mkdir -p ${PROJECT_DIR}/target ${PROJECT_DIR}/.embuild
25+
26+
# Install rustup
27+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
28+
--default-toolchain none -y --profile minimal
29+
30+
# Update envs
31+
ENV PATH=${PATH}:/home/${CONTAINER_USER}/.cargo/bin
32+
33+
# Install extra crates
34+
RUN ARCH=$($HOME/.cargo/bin/rustup show | grep "Default host" | sed -e 's/.* //') && \
35+
curl -L "https://github.com/esp-rs/espup/releases/latest/download/espup-${ARCH}" -o "${HOME}/.cargo/bin/espup" && \
36+
chmod u+x "${HOME}/.cargo/bin/espup" && \
37+
curl -L "https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip" -o "${HOME}/.cargo/bin/cargo-espflash.zip" && \
38+
unzip "${HOME}/.cargo/bin/cargo-espflash.zip" -d "${HOME}/.cargo/bin/" && \
39+
rm "${HOME}/.cargo/bin/cargo-espflash.zip" && \
40+
chmod u+x "${HOME}/.cargo/bin/cargo-espflash" && \
41+
curl -L "https://github.com/esp-rs/espflash/releases/latest/download/espflash-${ARCH}.zip" -o "${HOME}/.cargo/bin/espflash.zip" && \
42+
unzip "${HOME}/.cargo/bin/espflash.zip" -d "${HOME}/.cargo/bin/" && \
43+
rm "${HOME}/.cargo/bin/espflash.zip" && \
44+
chmod u+x "${HOME}/.cargo/bin/espflash" && \
45+
curl -L "https://github.com/esp-rs/embuild/releases/latest/download/ldproxy-${ARCH}.zip" -o "${HOME}/.cargo/bin/ldproxy.zip" && \
46+
unzip "${HOME}/.cargo/bin/ldproxy.zip" -d "${HOME}/.cargo/bin/" && \
47+
rm "${HOME}/.cargo/bin/ldproxy.zip" && \
48+
chmod u+x "${HOME}/.cargo/bin/ldproxy" && \
49+
curl -L "https://github.com/esp-rs/esp-web-flash-server/releases/latest/download/web-flash-${ARCH}.zip" -o "${HOME}/.cargo/bin/web-flash.zip" && \
50+
unzip "${HOME}/.cargo/bin/web-flash.zip" -d "${HOME}/.cargo/bin/" && \
51+
rm "${HOME}/.cargo/bin/web-flash.zip" && \
52+
chmod u+x "${HOME}/.cargo/bin/web-flash"
53+
54+
# Install Xtensa Rust
55+
RUN if [ -n "${GITHUB_TOKEN}" ]; then export GITHUB_TOKEN=${GITHUB_TOKEN}; fi \
56+
&& ${HOME}/.cargo/bin/espup install\
57+
--targets "${ESP_BOARD}" \
58+
--log-level debug \
59+
--export-file /home/${CONTAINER_USER}/export-esp.sh
60+
61+
# Set default toolchain
62+
RUN rustup default esp
63+
64+
# Activate ESP environment
65+
RUN echo "source /home/${CONTAINER_USER}/export-esp.sh" >> ~/.bashrc
66+
67+
CMD [ "/bin/bash" ]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "mqtt_example",
3+
"build": {
4+
"dockerfile": "../Dockerfile",
5+
"args": {
6+
"CONTAINER_USER": "esp",
7+
"CONTAINER_GROUP": "esp",
8+
"ESP_BOARD": "esp32",
9+
"PROJECT_DIR": "/home/esp/mqtt_example",
10+
}
11+
},
12+
// https://github.com/serialport/serialport-rs/issues/153
13+
"runArgs": [
14+
"--mount",
15+
"type=bind,source=/run/udev,target=/run/udev,readonly",
16+
],
17+
"customizations": {
18+
"vscode": {
19+
"settings": {
20+
"editor.formatOnPaste": true,
21+
"editor.formatOnSave": true,
22+
"editor.formatOnSaveMode": "file",
23+
"editor.formatOnType": true,
24+
"lldb.executable": "/usr/bin/lldb",
25+
"files.watcherExclude": {
26+
"**/target/**": true
27+
},
28+
"rust-analyzer.checkOnSave.command": "clippy",
29+
"rust-analyzer.checkOnSave.allTargets": false,
30+
"[rust]": {
31+
"editor.defaultFormatter": "rust-lang.rust-analyzer"
32+
}
33+
},
34+
"extensions": [
35+
"rust-lang.rust-analyzer",
36+
"tamasfe.even-better-toml",
37+
"serayuzgur.crates",
38+
"mutantdino.resourcemonitor",
39+
"yzhang.markdown-all-in-one",
40+
"ms-vscode.cpptools",
41+
"actboy168.tasks",
42+
"Wokwi.wokwi-vscode"
43+
]
44+
}
45+
},
46+
"forwardPorts": [
47+
3333,
48+
8000
49+
],
50+
"workspaceMount": "source=${localWorkspaceFolder},target=/home/esp/mqtt_example,type=bind,consistency=cached",
51+
"workspaceFolder": "/home/esp/mqtt_example",
52+
"mounts": [
53+
"target=/home/esp/mqtt_example/target,type=volume",
54+
"target=/home/esp/mqtt_example/.embuild,type=volume",
55+
],
56+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "mqtt_example",
3+
"build": {
4+
"dockerfile": "../Dockerfile",
5+
"args": {
6+
"CONTAINER_USER": "esp",
7+
"CONTAINER_GROUP": "esp",
8+
"ESP_BOARD": "esp32",
9+
"PROJECT_DIR": "/home/esp/mqtt_example",
10+
}
11+
},
12+
"customizations": {
13+
"vscode": {
14+
"settings": {
15+
"editor.formatOnPaste": true,
16+
"editor.formatOnSave": true,
17+
"editor.formatOnSaveMode": "file",
18+
"editor.formatOnType": true,
19+
"lldb.executable": "/usr/bin/lldb",
20+
"files.watcherExclude": {
21+
"**/target/**": true
22+
},
23+
"rust-analyzer.checkOnSave.command": "clippy",
24+
"rust-analyzer.checkOnSave.allTargets": false,
25+
"[rust]": {
26+
"editor.defaultFormatter": "rust-lang.rust-analyzer"
27+
}
28+
},
29+
"extensions": [
30+
"rust-lang.rust-analyzer",
31+
"tamasfe.even-better-toml",
32+
"serayuzgur.crates",
33+
"mutantdino.resourcemonitor",
34+
"yzhang.markdown-all-in-one",
35+
"ms-vscode.cpptools",
36+
"actboy168.tasks",
37+
"Wokwi.wokwi-vscode"
38+
]
39+
}
40+
},
41+
"forwardPorts": [
42+
3333,
43+
8000
44+
],
45+
"workspaceMount": "source=${localWorkspaceFolder},target=/home/esp/mqtt_example,type=bind,consistency=cached",
46+
"workspaceFolder": "/home/esp/mqtt_example",
47+
"mounts": [
48+
"target=/home/esp/mqtt_example/target,type=volume",
49+
"target=/home/esp/mqtt_example/.embuild,type=volume",
50+
],
51+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "mqtt_example",
3+
"build": {
4+
"dockerfile": "../Dockerfile",
5+
"args": {
6+
"CONTAINER_USER": "esp",
7+
"CONTAINER_GROUP": "esp",
8+
"ESP_BOARD": "esp32",
9+
"PROJECT_DIR": "/home/esp/mqtt_example",
10+
}
11+
},
12+
// https://github.com/serialport/serialport-rs/issues/153
13+
"runArgs": [
14+
"--mount",
15+
"type=bind,source=/dev/bus/usb,target=/dev/bus/usb,readonly",
16+
],
17+
"customizations": {
18+
"vscode": {
19+
"settings": {
20+
"editor.formatOnPaste": true,
21+
"editor.formatOnSave": true,
22+
"editor.formatOnSaveMode": "file",
23+
"editor.formatOnType": true,
24+
"lldb.executable": "/usr/bin/lldb",
25+
"files.watcherExclude": {
26+
"**/target/**": true
27+
},
28+
"rust-analyzer.checkOnSave.command": "clippy",
29+
"rust-analyzer.checkOnSave.allTargets": false,
30+
"[rust]": {
31+
"editor.defaultFormatter": "rust-lang.rust-analyzer"
32+
}
33+
},
34+
"extensions": [
35+
"rust-lang.rust-analyzer",
36+
"tamasfe.even-better-toml",
37+
"serayuzgur.crates",
38+
"mutantdino.resourcemonitor",
39+
"yzhang.markdown-all-in-one",
40+
"ms-vscode.cpptools",
41+
"actboy168.tasks",
42+
"Wokwi.wokwi-vscode"
43+
]
44+
}
45+
},
46+
"forwardPorts": [
47+
3333,
48+
8000
49+
],
50+
"workspaceMount": "source=${localWorkspaceFolder},target=/home/esp/mqtt_example,type=bind,consistency=cached",
51+
"workspaceFolder": "/home/esp/mqtt_example",
52+
"mounts": [
53+
"target=/home/esp/mqtt_example/target,type=volume",
54+
"target=/home/esp/mqtt_example/.embuild,type=volume",
55+
],
56+
}

0 commit comments

Comments
 (0)