diff --git a/bash b/bash new file mode 100644 index 0000000..ac42d5b --- /dev/null +++ b/bash @@ -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. \ No newline at end of file diff --git a/docker/.dockerignore b/docker/.dockerignore new file mode 100644 index 0000000..6b47c80 --- /dev/null +++ b/docker/.dockerignore @@ -0,0 +1,8 @@ +.git +.gitignore +*.md +example_output/ +node_modules/ +__pycache__/ +*.pyc +.DS_Store \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..9bb3ec1 --- /dev/null +++ b/docker/Dockerfile @@ -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"] \ No newline at end of file diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..7e3682d --- /dev/null +++ b/docker/README.md @@ -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 diff --git a/docker/compile.sh b/docker/compile.sh new file mode 100644 index 0000000..6017082 --- /dev/null +++ b/docker/compile.sh @@ -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 [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 \ No newline at end of file diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..85cb494 --- /dev/null +++ b/docker/docker-compose.yml @@ -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"] \ No newline at end of file diff --git a/docker/example_input/platformio.ini b/docker/example_input/platformio.ini new file mode 100644 index 0000000..57ef617 --- /dev/null +++ b/docker/example_input/platformio.ini @@ -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 \ No newline at end of file diff --git a/docker/example_input/src/sketch.ino b/docker/example_input/src/sketch.ino new file mode 100644 index 0000000..4497ee7 --- /dev/null +++ b/docker/example_input/src/sketch.ino @@ -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); +} \ No newline at end of file diff --git a/ini b/ini new file mode 100644 index 0000000..31a34a2 --- /dev/null +++ b/ini @@ -0,0 +1,4 @@ +[env:photon] +platform = particle +board = photon +framework = particle \ No newline at end of file