Skip to content

Commit 71b9170

Browse files
committed
Add Dockerfile
1 parent 7ba743a commit 71b9170

File tree

11 files changed

+291
-3
lines changed

11 files changed

+291
-3
lines changed

Firmware/Dockerfile

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
FROM ubuntu:latest AS upstream
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
ENV FILENAME_PREFIX=RTK_Firmware
6+
ENV FIRMWARE_VERSION_MAJOR=99
7+
ENV FIRMWARE_VERSION_MINOR=99
8+
ENV CORE_VERSION=2.0.2
9+
10+
# ESP32 Core Debug Level
11+
# We use "none" for releases and "error" for release_candidate
12+
# You may find "verbose" useful while you are debugging your changes
13+
ENV DEBUG_LEVEL=error
14+
15+
# Developer Mode
16+
# You may find "true" useful while you are making changes
17+
# Set to false for releases
18+
ENV ENABLE_DEVELOPER=true
19+
20+
# If you have your own u-blox PointPerfect token, define it here
21+
# or pass it in as an arg when building the Dockerfile
22+
ARG POINTPERFECT_TOKEN=0xAA,0xBB,0xCC,0xDD,0x00,0x11,0x22,0x33,0x0A,0x0B,0x0C,0x0D,0x00,0x01,0x02,0x03
23+
24+
# Get curl and python3
25+
RUN apt-get update \
26+
&& apt-get install -y curl python3 python3-pip python3-venv python-is-python3 \
27+
&& apt-get clean \
28+
&& rm -rf /var/lib/apt/lists/*
29+
30+
# Avoid the externally managed environment constraint
31+
RUN PYTHON_VER=$(ls /usr/lib | grep python3.) \
32+
&& echo "Python version: ${PYTHON_VER}" \
33+
&& rm /usr/lib/${PYTHON_VER}/EXTERNALLY-MANAGED
34+
35+
# Install Python dependencies - esptool needs pyserial
36+
#RUN python3 -m pip install --upgrade pip && \
37+
RUN pip install pyserial
38+
39+
# Setup Arduino CLI
40+
#RUN curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
41+
RUN curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
42+
43+
# Start config file
44+
RUN arduino-cli config init --additional-urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json
45+
46+
# Update core index
47+
RUN arduino-cli core update-index
48+
49+
# Update library index
50+
RUN arduino-cli lib update-index
51+
52+
# Install platform
53+
RUN arduino-cli core install "esp32:esp32@${CORE_VERSION}"
54+
55+
# Get Known Libraries
56+
RUN arduino-cli lib install ArduinoJson@6.19.4
57+
RUN arduino-cli lib install ESP32Time@2.0.0
58+
RUN arduino-cli lib install ESP32_BleSerial@1.0.5
59+
RUN arduino-cli lib install "ESP32-OTA-Pull"@1.0.0
60+
RUN arduino-cli lib install Ethernet@2.0.2
61+
RUN arduino-cli lib install JC_Button@2.1.2
62+
RUN arduino-cli lib install PubSubClient@2.8.0
63+
RUN arduino-cli lib install "SdFat"@2.1.1
64+
RUN arduino-cli lib install "SparkFun LIS2DH12 Arduino Library"@1.0.3
65+
RUN arduino-cli lib install "SparkFun MAX1704x Fuel Gauge Arduino Library"@1.0.4
66+
RUN arduino-cli lib install "SparkFun u-blox GNSS v3"@3.0.14
67+
RUN arduino-cli lib install "SparkFun_WebServer_ESP32_W5500"@1.5.5
68+
RUN arduino-cli lib install "SparkFun Qwiic OLED Arduino Library"@1.0.13
69+
RUN arduino-cli lib install SSLClientESP32@2.0.0
70+
71+
# Enable external libs
72+
RUN arduino-cli config set library.enable_unsafe_install true
73+
74+
# Get external libs
75+
RUN arduino-cli lib install --git-url https://github.com/me-no-dev/ESPAsyncWebServer.git
76+
RUN arduino-cli lib install --git-url https://github.com/me-no-dev/AsyncTCP.git
77+
78+
# Copy RTK_Everywhere into /work and build deployment image
79+
FROM upstream AS deployment
80+
81+
# Create work directory
82+
WORKDIR /work
83+
ADD . .
84+
85+
# Get current date
86+
#RUN echo "$(date +'%b_%d_%Y')" > date_scores.txt
87+
#RUN DATE_SCORES=$(cat date_scores.txt) && echo "Date: ${DATE_SCORES}"
88+
#RUN echo "$(date +'%b %d %Y')" > date_no_scores.txt
89+
#RUN DATE_NO_SCORES=$(cat date_no_scores.txt) && echo "Date: ${DATE_NO_SCORES}"
90+
91+
# Patch Server.h to avoid https://github.com/arduino-libraries/Ethernet/issues/88#issuecomment-455498941
92+
WORKDIR /work/RTK_Surveyor/Patch
93+
RUN cp Server.h "/root/.arduino15/packages/esp32/hardware/esp32/${CORE_VERSION}/cores/esp32/Server.h"
94+
95+
# Update form.h with index_html and main_js
96+
WORKDIR /work/Tools
97+
RUN python index_html_zipper.py ../RTK_Surveyor/AP-Config/index.html ../RTK_Surveyor/form.h
98+
RUN python main_js_zipper.py ../RTK_Surveyor/AP-Config/src/main.js ../RTK_Surveyor/form.h
99+
100+
# Copy custom app3M_fat9M_16MB.csv
101+
WORKDIR /work
102+
RUN cp app3M_fat9M_16MB.csv "/root/.arduino15/packages/esp32/hardware/esp32/${CORE_VERSION}/tools/partitions/app3M_fat9M_16MB.csv"
103+
104+
# Compile Sketch
105+
WORKDIR /work/RTK_Surveyor
106+
RUN arduino-cli compile --fqbn "esp32:esp32:esp32":DebugLevel=${DEBUG_LEVEL} \
107+
./RTK_Surveyor.ino \
108+
--build-property build.partitions=app3M_fat9M_16MB \
109+
--build-property upload.maximum_size=3145728 \
110+
--build-property "compiler.cpp.extra_flags=\"-DPOINTPERFECTTOKEN=${POINTPERFECT_TOKEN}\" \
111+
\"-DFIRMWARE_VERSION_MAJOR=${FIRMWARE_VERSION_MAJOR}\" \
112+
\"-DFIRMWARE_VERSION_MINOR=${FIRMWARE_VERSION_MINOR}\" \
113+
\"-DENABLE_DEVELOPER=${ENABLE_DEVELOPER}\"" \
114+
--export-binaries
115+
116+
# Copy the compile output. List the files
117+
FROM deployment AS output
118+
COPY --from=deployment /work/RTK_Surveyor/build/esp32.esp32.esp32 /
119+
CMD echo $(ls /*.*)

docs/firmware_update.md

Lines changed: 172 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,178 @@ As of writing, no additional releases of the NEO-D9S firmware have been made.
273273

274274
## Compiling Source
275275

276-
### Windows
276+
This is information about how to compile the RTK Firmware from source. This is for advanced users who would like to modify the functionality of the RTK products.
277+
278+
* [How SparkFun does it](#how-sparkfun-does-it)
279+
* [Using Docker](#using-docker)
280+
* [Compiling on Windows (Deprecated)](#compiling-on-windows-deprecated)
281+
* [Compiling on Ubuntu 20.04 (Deprecated)](#compiling-on-ubuntu-2004-deprecated)
282+
283+
## How SparkFun does it
284+
285+
At SparkFun, we use GitHub Actions and a Workflow to compile each release of RTK Firmware. We run the [compilation workflow](https://github.com/sparkfun/SparkFun_RTK_Firmware/blob/main/.github/workflows/compile-rtk-firmware.yml) directly on GitHub. A virtual ubuntu machine installs the [Arduino CLI](https://github.com/arduino/arduino-cli/releases), installs the correct ESP32 Arduino core, patches the core in a couple of places, installs all the required libraries at the required version, converts the embedded HTML and Bootstrap JavaScript to binary zip format, and generates the firmware binary for the ESP32. That binary is either uploaded as an Artifact (by [non-release-build](https://github.com/sparkfun/SparkFun_RTK_Firmware/blob/main/.github/workflows/non-release-build.yml)) or pushed to the [SparkFun RTK Firmware Binaries](https://github.com/sparkfun/SparkFun_RTK_Firmware_Binaries) repo (by the [compilation workflow](https://github.com/sparkfun/SparkFun_RTK_Firmware/blob/main/.github/workflows/compile-rtk-firmware.yml)).
286+
287+
You are welcome to clone or fork this repo and do the exact same thing yourself. But you may need a paid GitHub Pro account to run the GitHub Actions, especially if you keep your clone / fork private.
288+
289+
If you run the [compilation workflow](https://github.com/sparkfun/SparkFun_RTK_Firmware/blob/main/.github/workflows/compile-rtk-firmware.yml), it will compile the firmware and attempt to push the binary to the Binaries repo. This will fail as your account won't have the right permissions. The [non-release-build](https://github.com/sparkfun/SparkFun_RTK_Firmware/blob/main/.github/workflows/non-release-build.yml) is the one for you. The firmware binary will be attached as an Artifact to the workflow run. Navigate to Actions \ Non-Release Build, select the latest run of Non-Release Build, the binary is in the Artifacts.
290+
291+
You can then use the [SparkFun RTK Firmware Uploader](https://github.com/sparkfun/SparkFun_RTK_Firmware_Uploader) to upload the binary onto the ESP32.
292+
293+
## Using Docker
294+
295+
Installing the correct version of the ESP32 core and of each required Arduino library, is tedious and error-prone. Especially on Windows. We've lost count of the number of times code compilation fails on our local machines, because we had the wrong ESP32 core installed, or forgot to patch Server.h... It is much easier to sandbox the firmware compilation using an environment like [Docker](https://www.docker.com/).
296+
297+
Here is a step-by-step guide for how to install Docker and compile the firmware from scratch:
298+
299+
### Clone, fork or download the RTK Firmware repo
300+
301+
To build the RTK Firmware, you obviously need a copy of the source code.
302+
303+
If you are familiar with Git and GitHub Desktop, you can clone the RTK Firmware repo directly into GitHub Desktop:
304+
305+
<figure markdown>
306+
![Clone RTK Firmware with GitHub Desktop](./img/CompileSource/Clone_Repo_To_GitHub_Desktop.png)
307+
<figcaption markdown>
308+
Clone RTK Firmware with GitHub Desktop
309+
</figcaption>
310+
</figure>
311+
312+
If you want to _contribute_ to the RTK Firmware, and already have a GitHub account, you can Fork the repo:
313+
314+
<figure markdown>
315+
![Fork RTK Firmware](./img/CompileSource/Fork_Repo.png)
316+
<figcaption markdown>
317+
Fork a copy of RTK Firmware
318+
</figcaption>
319+
</figure>
320+
321+
Clone your fork to your local machine, make changes, and send us a Pull Request. This is exactly what the SparkFun Team do when developing the code. Please use the `release_candidate` branch for any such changes. We are very unlikely to merge anything directly into `main`, unless it is (e.g.) docs corrections or improvements.
322+
323+
If you don't want to do either of those, you can simply Download a Zip copy of the repo instead. You will receive a complete copy as a Zip file. You can do this from the green **Code** button, or click on the icon below to download a copy of the main (released) branch:
324+
325+
[![Download ZIP](./img/CompileSource/Download_Zip.png)](https://github.com/sparkfun/SparkFun_RTK_Firmware/archive/refs/heads/main.zip "Download ZIP (main branch)")
326+
327+
For the real Wild West experience, you can also download a copy of the `release_candidate` code branch. This is where the team is actively changing and testing the code, before it becomes a full release. The code there will _usually_ compile and will _usually_ work, but we don't guarantee it! We may be part way through implementing some breaking changes at the time of your download...
328+
329+
[![Download ZIP - release candidate](./img/CompileSource/Download_Zip.png)](https://github.com/sparkfun/SparkFun_RTK_Firmware/archive/refs/heads/release_candidate.zip "Download ZIP (release_candidate branch)")
330+
331+
### Install Docker Desktop
332+
333+
* Head to [Docker](https://www.docker.com/) and create an account. A free "Personal" account will cover occasional compilations of the firmware
334+
* Download and install [Docker Desktop](https://docs.docker.com/get-started/get-docker/) - there are versions for Mac, Windows and Linux. You may need to restart to complete the installation.
335+
* Run the Desktop and sign in
336+
* On Windows, you may see an error saying "**WSL needs updating** Your version of Windows Subsystem for Linux (WSL) is too old". If you do:
337+
* Open a command prompt
338+
* Type `wsl --update` to update WSL. At the time of writing, this installs Windows Subsystem for Linux 2.6.1
339+
* Restart the Docker Desktop
340+
* If you are using Docker for the first time, the "What is a container?" and "How do I run a container?" demos are useful
341+
* On Windows, you may want to give Docker Desktop permission to access to your Network, so it can access (e.g.) HTML ports
342+
* You can Stop the container and Delete it when you are done
343+
* You may want to prevent Docker from running when your machine starts up
344+
* Uncheck "Start Docker Desktop when you sign in to your computer" in the Desktop settings
345+
346+
### Running the Dockerfile to create an Image
347+
348+
* **Make sure you have Docker Desktop running.** You don't need to be logged in, but it needs to be running.
349+
* Open a Command Prompt and `cd` into the SparkFun_RTK_Firmware folder
350+
* Check you are in the right place. Type `dir` and hit enter. You should see the following files and folders:
351+
352+
```
353+
.gitattributes
354+
.github
355+
.gitignore
356+
docs
357+
Firmware
358+
Graphics
359+
Issue_Template.md
360+
License.md
361+
README.md
362+
```
363+
364+
* `cd Firmware` and then `dir` again. You should see:
365+
366+
```
367+
app3M_fat9M_16MB.csv
368+
Dockerfile
369+
readme.md
370+
RTKFirmware.csv
371+
RTK_Surveyor
372+
```
373+
374+
* The file we will be using is the `Dockerfile`.
375+
* Type:
376+
377+
```
378+
docker build -t rtk_firmware .
379+
```
380+
381+
![Dockerfile starting](./img/CompileSource/Dockerfile_starting.png)
382+
383+
![Dockerfile complete](./img/CompileSource/Dockerfile_complete.png)
384+
385+
* If you want to see the full build progress including the output of echo or ls, use:
386+
387+
```
388+
docker build -t rtk_firmware --progress=plain .
389+
```
390+
391+
* If you want to rebuild the image completely from scratch, without using the cache, use:
392+
393+
```
394+
docker build -t rtk_firmware --progress=plain --no-cache .
395+
```
396+
397+
Building the full Image from scratch is slow, taking several minutes. You should only need to do it once - unless you make any changes to the Dockerfile.
398+
399+
* When you make changes to the source code and want to recompile, use:
400+
401+
```
402+
docker build -t rtk_firmware --no-cache-filter deployment .
403+
```
404+
405+
This uses the cache for the `upstream` stage and avoids recreating the full ubuntu machine. But it ignores the cache for the `deployment` stage, ensuring the code is recompiled.
406+
407+
### Access the firmware by running the Image
408+
409+
In Docker Desktop, in the Images tab, you should now be able to see an Image named `rtk_firmware`. We now need to Run that Image to access the firmware binary. Click the triangular Run icon under Actions:
410+
411+
![Docker image ready to run](./img/CompileSource/Docker_Image.png)
412+
413+
Running the Image will create a Container, through which we can access the output of the arduino-cli code compilation.
414+
415+
By default, the Container name is random. To avoid this, we define one in the **Optional settings** :
416+
417+
![Docker Container - named rtk_container](./img/CompileSource/Docker_Container.png)
418+
419+
Run the Container and you should see:
420+
421+
![Container is complete](./img/CompileSource/Container_complete.png)
422+
423+
In the Command Prompt, type the following :
424+
425+
```
426+
docker cp rtk_container:/RTK_Surveyor.ino.bin .
427+
```
428+
429+
Hey presto! A file called `RTK_Surveyor.ino.bin` appears in the current directory. That's the firmware binary we are going to upload to the ESP32.
430+
431+
![Firmware binary](./img/CompileSource/Firmware_binary.png)
432+
433+
If you need the `.elf` file so you can debug code crashes with me-no-dev's [ESP ExceptionDecoder](https://github.com/me-no-dev/EspExceptionDecoder):
434+
435+
```
436+
docker cp rtk_container:/RTK_Surveyor.ino.elf .
437+
```
438+
439+
If you want the files to appear in a more convenient directory, replace the single `.` with a folder path.
440+
441+
Delete the `rtk_container` container afterwards, to save disk space and so you can reuse the same container name next time. If you forget, you will see an error:
442+
443+
```Conflict. The container name "/rtk_container" is already in use by container. You have to remove (or rename) that container to be able to reuse that name.```
444+
445+
### Compiling on Windows (Deprecated)
277446

278-
The SparkFun RTK firmware is compiled using Arduino (currently v1.8.15). To compile:
447+
The SparkFun RTK Firmware is compiled using Arduino (currently v1.8.15). To compile:
279448

280449
1. Install [Arduino](https://www.arduino.cc/en/software).
281450

@@ -353,7 +522,7 @@ The following libraries are only available via GitHub:
353522

354523
* [SparkFun Micro OLED Breakout](https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library)
355524

356-
### Ubuntu 20.04
525+
### Compiling on Ubuntu 20.04 (Deprecated)
357526

358527
#### Virtual Machine
359528

55.3 KB
Loading
101 KB
Loading
98.6 KB
Loading
98.7 KB
Loading
136 KB
Loading
115 KB
Loading
1.24 KB
Loading
76.3 KB
Loading

0 commit comments

Comments
 (0)