Skip to content
Open
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
26 changes: 26 additions & 0 deletions bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
docker build -t particle-cloud-compiler .
```

2. Run the compiler with the example input:
```bash
docker run --rm \
-v $(pwd)/example_input:/workspace/input:ro \
-v $(pwd)/example_output:/workspace/output \
particle-cloud-compiler
```

3. Check the output:
```bash
ls -la example_output/
```

## Troubleshooting

### Build fails with "platform not found"
Run `pio platform install particle` inside the container or rebuild the image.

### Permission denied errors
Ensure the output directory is writable by the Docker user.

### No firmware.bin generated
Check the build.log for compilation errors. Common issues include missing libraries or syntax errors in the sketch.
8 changes: 8 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
.gitignore
*.md
example_output/
node_modules/
__pycache__/
*.pyc
.DS_Store
33 changes: 33 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu:20.04

# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install required system packages
RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
git \
wget \
curl \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Install PlatformIO
RUN pip3 install platformio

# Pre-install Particle platform for faster builds
RUN pio platform install "particle"

# Create working directories
RUN mkdir -p /workspace/input /workspace/output

# Copy the build script
COPY compile.sh /usr/local/bin/compile.sh
RUN chmod +x /usr/local/bin/compile.sh

# Set the working directory
WORKDIR /workspace

# Default command
ENTRYPOINT ["/usr/local/bin/compile.sh"]
10 changes: 10 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Particle Cloud Compiler Docker Image

This Docker image provides a cloud-based compilation environment for Particle firmware sketches. It uses PlatformIO to compile sketches for Particle devices (Photon, Core, etc.) and outputs the compiled binary and build log.

## Prerequisites

- Docker installed on your system
- Basic familiarity with Docker commands

## Building the Image
80 changes: 80 additions & 0 deletions docker/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
#
# Particle Cloud Compiler Script
#
# This script compiles a Particle firmware sketch using PlatformIO.
# It takes an input directory containing the sketch and libraries,
# and outputs a .bin file and build log to the output directory.
#
# Usage: compile.sh <input_dir> <output_dir> [platform]
#
# Arguments:
# input_dir - Directory containing the sketch (must contain platformio.ini and src/)
# output_dir - Directory where output files will be written
# platform - Target platform (photon, core, etc.) - optional, defaults to photon
#
# Outputs:
# output_dir/firmware.bin - Compiled firmware binary
# output_dir/build.log - Build log
#

set -e

# Parse arguments
INPUT_DIR="${1:-/workspace/input}"
OUTPUT_DIR="${2:-/workspace/output}"
PLATFORM="${3:-photon}"

# Validate input directory
if [ ! -d "$INPUT_DIR" ]; then
echo "ERROR: Input directory does not exist: $INPUT_DIR"
exit 1
fi

# Validate platformio.ini exists
if [ ! -f "$INPUT_DIR/platformio.ini" ]; then
echo "ERROR: platformio.ini not found in input directory"
exit 1
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

# Copy input to workspace
rm -rf /workspace/build
cp -r "$INPUT_DIR" /workspace/build
cd /workspace/build

# Initialize PlatformIO project if needed
if [ ! -d ".pio" ]; then
pio init --board "$PLATFORM" 2>&1 | tee -a "$OUTPUT_DIR/build.log"
fi

# Run the build
echo "Starting build for platform: $PLATFORM"
echo "Input directory: $INPUT_DIR"
echo "Output directory: $OUTPUT_DIR"
echo "========================================"

# Build the firmware
pio run 2>&1 | tee "$OUTPUT_DIR/build.log"

# Check if build was successful
if [ ${PIPESTATUS[0]} -eq 0 ]; then
echo "Build successful!"

# Find and copy the .bin file
BIN_FILE=$(find .pio/build -name "firmware.bin" 2>/dev/null | head -1)
if [ -n "$BIN_FILE" ]; then
cp "$BIN_FILE" "$OUTPUT_DIR/firmware.bin"
echo "Firmware binary copied to $OUTPUT_DIR/firmware.bin"
else
echo "WARNING: firmware.bin not found in build output"
echo "WARNING: firmware.bin not found in build output" >> "$OUTPUT_DIR/build.log"
fi

exit 0
else
echo "Build failed. Check build.log for details."
exit 1
fi
12 changes: 12 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.8'

services:
particle-compiler:
build: .
image: particle-cloud-compiler:latest
volumes:
# Mount input and output directories
- ./example_input:/workspace/input:ro
- ./example_output:/workspace/output
# Override default command with specific input/output/platform
command: ["/workspace/input", "/workspace/output", "photon"]
7 changes: 7 additions & 0 deletions docker/example_input/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[env:photon]
platform = particle
board = photon
framework = particle
lib_deps =
; Add any library dependencies here
; Example: SparkFun_Photon_Weather_Shield@1.0.0
17 changes: 17 additions & 0 deletions docker/example_input/src/sketch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Particle Photon Blink Example
// This is a simple example sketch for testing the cloud compiler

int led = D7; // Built-in LED on Photon

void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
Serial.println("Particle Cloud Compiler Test");
}

void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
4 changes: 4 additions & 0 deletions ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[env:photon]
platform = particle
board = photon
framework = particle