From ac5f032cd903420baee2ac289083d0bdef6cdbd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Mich=C3=A1lek?= Date: Fri, 13 Aug 2021 06:46:05 +0200 Subject: [PATCH] docker: split images to idf-rust and idf-rust-examples (#22) * docker: split images to idf-rust and idf-rust-examples * docker: acquire rust binary from GitHub Releases --- .../publish-idf-rust-examples-image.yml | 22 ++++++++++ ...t-image.yml => publish-idf-rust-image.yml} | 4 +- .gitignore | 2 + Dockerfile | 42 +++++-------------- support/idf-rust-examples/entrypoint.sh | 7 ++++ support/idf-rust-examples/motd | 19 +++++++++ support/idf-rust/Dockerfile | 33 +++++++++++++++ 7 files changed, 96 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/publish-idf-rust-examples-image.yml rename .github/workflows/{publish-esp-idf-rust-image.yml => publish-idf-rust-image.yml} (87%) create mode 100755 support/idf-rust-examples/entrypoint.sh create mode 100644 support/idf-rust-examples/motd create mode 100644 support/idf-rust/Dockerfile diff --git a/.github/workflows/publish-idf-rust-examples-image.yml b/.github/workflows/publish-idf-rust-examples-image.yml new file mode 100644 index 0000000..881641f --- /dev/null +++ b/.github/workflows/publish-idf-rust-examples-image.yml @@ -0,0 +1,22 @@ +name: Publish idf-rust image on DockerHub + +on: workflow_dispatch + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v2 + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + - name: Push to Docker Hub + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: espressif/idf-rust-examples:latest diff --git a/.github/workflows/publish-esp-idf-rust-image.yml b/.github/workflows/publish-idf-rust-image.yml similarity index 87% rename from .github/workflows/publish-esp-idf-rust-image.yml rename to .github/workflows/publish-idf-rust-image.yml index a626555..8b3fa9f 100644 --- a/.github/workflows/publish-esp-idf-rust-image.yml +++ b/.github/workflows/publish-idf-rust-image.yml @@ -1,4 +1,4 @@ -name: Publish esp-idf-rust image on DockerHub +name: Publish idf-rust image on DockerHub on: workflow_dispatch @@ -17,6 +17,6 @@ jobs: - name: Push to Docker Hub uses: docker/build-push-action@v2 with: - context: . + context: support/idf-rust push: true tags: espressif/idf-rust:latest diff --git a/.gitignore b/.gitignore index 2324e4e..7ec534c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ target/ Cargo.lock **/*.rs.bk *.pdb +.idea/ +cmake-build-debug/ diff --git a/Dockerfile b/Dockerfile index a4270ae..380a73c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,37 +1,17 @@ -FROM espressif/idf -#RUN apt update \ -# && apt install -y build-essential curl -ENV LC_ALL=C.UTF-8 -ENV LANG=C.UTF-8 -ENV RUSTUP_HOME=/opt/rust -ENV CARGO_HOME=/opt/cargo -ENV PATH=/opt/cargo/bin:/opt/rust/bin:/opt/xtensa-esp32-elf-clang/bin:$PATH +FROM espressif/idf-rust -ARG VERSION="1.54.0-dev" -ARG ARCH="x86_64-unknown-linux-gnu" -ARG RUST_DIST="rust-${VERSION}-${ARCH}" -ARG RUST_SRC_DIST="rust-src-${VERSION}" -ARG TOOLCHAIN_DESTINATION_DIR="/opt/esp" +# Some tools to make life with examples easier +RUN apt update \ + && apt install -y vim nano -RUN curl https://sh.rustup.rs -sSf | bash -s -- --profile minimal --default-toolchain nightly -y -WORKDIR /opt +# Dependency for Cargo first example +RUN cargo install cargo-pio -RUN wget -q https://dl.espressif.com/dl/idf-rust/dist/${ARCH}/${RUST_DIST}.tar.xz \ - && tar xvf ${RUST_DIST}.tar.xz \ - && ./${RUST_DIST}/install.sh --destdir=${TOOLCHAIN_DESTINATION_DIR} --prefix="" --without=rust-docs \ - && rm -rf ${RUST_DIST} ${RUST_DIST}.tar.xz +COPY support/idf-rust-examples/entrypoint.sh /opt/esp/entrypoint.sh +COPY support/idf-rust-examples/motd /etc/motd -RUN wget -q https://dl.espressif.com/dl/idf-rust/dist/noarch/${RUST_SRC_DIST}.tar.xz \ - && tar xvf ${RUST_SRC_DIST}.tar.xz \ - && ./${RUST_SRC_DIST}/install.sh --destdir=${TOOLCHAIN_DESTINATION_DIR} --prefix="" --without=rust-docs \ - && rm -rf ${RUST_SRC_DIST} ${RUST_SRC_DIST}.tar.xz \ - && rustup toolchain link esp /opt/esp \ - && rustup default esp +RUN if [ ! -e /opt/rust-esp32-example ]; then git clone https://github.com/espressif/rust-esp32-example.git /opt/rust-esp32-example; fi \ + && git clone https://github.com/ivmarkov/rust-esp32-std-hello.git /opt/rust-esp32-std-hello -RUN wget -q https://dl.espressif.com/dl/idf-rust/dist/${ARCH}/xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21249-g36dbc8b-linux-amd64.tar.xz \ - && tar xf xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21249-g36dbc8b-linux-amd64.tar.xz \ - && rm xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21249-g36dbc8b-linux-amd64.tar.xz +WORKDIR /opt/ -RUN git clone https://github.com/espressif/rust-esp32-example.git - -WORKDIR /opt/rust-esp32-example diff --git a/support/idf-rust-examples/entrypoint.sh b/support/idf-rust-examples/entrypoint.sh new file mode 100755 index 0000000..025ec90 --- /dev/null +++ b/support/idf-rust-examples/entrypoint.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +set -e + +. $IDF_PATH/export.sh +cat /etc/motd + +exec "$@" diff --git a/support/idf-rust-examples/motd b/support/idf-rust-examples/motd new file mode 100644 index 0000000..a59626f --- /dev/null +++ b/support/idf-rust-examples/motd @@ -0,0 +1,19 @@ +============================================================================== += Docker image with ESP-IDF, Rust compiler and examples = += https://github.com/espressif/rust-esp32-example = +============================================================================== + +Available examples: + +* "idf.py-first" approach - integration via CMake files + ```sh + cd /opt/rust-esp32-example + idf.py build + ``` + +* "cargo-first" approach + ```sh + cd /opt/rust-esp32-std-hello + cargo build --release + ``` + diff --git a/support/idf-rust/Dockerfile b/support/idf-rust/Dockerfile new file mode 100644 index 0000000..3486fd1 --- /dev/null +++ b/support/idf-rust/Dockerfile @@ -0,0 +1,33 @@ +FROM espressif/idf +ENV LC_ALL=C.UTF-8 +ENV LANG=C.UTF-8 +ENV RUSTUP_HOME=/opt/rust +ENV CARGO_HOME=/opt/cargo +ENV PATH=/opt/cargo/bin:/opt/rust/bin:/opt/xtensa-esp32-elf-clang/bin:$PATH + +ARG VERSION="1.54.0-dev" +ARG ARCH="x86_64-unknown-linux-gnu" +ARG RUST_DIST="rust-${VERSION}-${ARCH}" +ARG RUST_SRC_DIST="rust-src-${VERSION}" +ARG TOOLCHAIN_DESTINATION_DIR="/opt/esp" + +RUN curl https://sh.rustup.rs -sSf | bash -s -- --profile minimal --default-toolchain nightly -y +WORKDIR /opt + +#RUN wget -q https://dl.espressif.com/dl/idf-rust/dist/${ARCH}/${RUST_DIST}.tar.xz \ +RUN wget -q https://github.com/georgik/idf-rust-build/releases/download/v${VERSION}/${RUST_DIST}.tar.xz \ + && tar xvf ${RUST_DIST}.tar.xz \ + && ./${RUST_DIST}/install.sh --destdir=${TOOLCHAIN_DESTINATION_DIR} --prefix="" --without=rust-docs \ + && rm -rf ${RUST_DIST} ${RUST_DIST}.tar.xz + +RUN wget -q https://dl.espressif.com/dl/idf-rust/dist/noarch/${RUST_SRC_DIST}.tar.xz \ + && tar xvf ${RUST_SRC_DIST}.tar.xz \ + && ./${RUST_SRC_DIST}/install.sh --destdir=${TOOLCHAIN_DESTINATION_DIR} --prefix="" --without=rust-docs \ + && rm -rf ${RUST_SRC_DIST} ${RUST_SRC_DIST}.tar.xz \ + && rustup toolchain link esp /opt/esp \ + && rustup default esp + +RUN wget -q https://dl.espressif.com/dl/idf-rust/dist/${ARCH}/xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21249-g36dbc8b-linux-amd64.tar.xz \ + && tar xf xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21249-g36dbc8b-linux-amd64.tar.xz \ + && rm xtensa-esp32-elf-llvm11_0_0-llvmorg-11-init-21249-g36dbc8b-linux-amd64.tar.xz +