|
| 1 | +# Stage 1: build the Rust simulator TCP server |
| 2 | +FROM rust:1.85-bookworm AS sim-builder |
| 3 | + |
| 4 | +WORKDIR /app |
| 5 | +COPY atecc608-sim/ /app/atecc608-sim/ |
| 6 | +RUN cd /app/atecc608-sim && cargo build --release --bin tcp_server 2>&1 |
| 7 | + |
| 8 | +# ============================================================================= |
| 9 | +# Stage 2: build cryptoauthlib + test binary |
| 10 | +# ============================================================================= |
| 11 | +FROM debian:bookworm |
| 12 | + |
| 13 | +RUN apt-get update && apt-get install -y \ |
| 14 | + build-essential cmake git pkg-config \ |
| 15 | + libssl-dev \ |
| 16 | + && rm -rf /var/lib/apt/lists/* |
| 17 | + |
| 18 | +COPY --from=sim-builder /app/atecc608-sim/target/release/tcp_server /app/atecc608-sim-server |
| 19 | + |
| 20 | +# ---- Build cryptoauthlib ---- |
| 21 | +WORKDIR /app |
| 22 | +# Pin to a recent known-working tag. v3.7.8 is the latest as of early 2026. |
| 23 | +RUN git clone --branch v3.7.8 --depth 1 \ |
| 24 | + https://github.com/MicrochipTech/cryptoauthlib.git /app/cryptoauthlib |
| 25 | + |
| 26 | +# We register our HAL at runtime by populating ATCAIfaceCfg.atcacustom, so |
| 27 | +# cryptoauthlib just needs ATCA_HAL_CUSTOM=ON and the other HALs disabled |
| 28 | +# (they pull in libraries we don't have in the container). |
| 29 | +RUN mkdir -p /app/cryptoauthlib/build && cd /app/cryptoauthlib/build && \ |
| 30 | + cmake .. \ |
| 31 | + -DCMAKE_BUILD_TYPE=Release \ |
| 32 | + -DCMAKE_C_FLAGS="-fPIC" \ |
| 33 | + -DATCA_HAL_CUSTOM=ON \ |
| 34 | + -DATCA_HAL_I2C=OFF \ |
| 35 | + -DATCA_HAL_SPI=OFF \ |
| 36 | + -DATCA_HAL_KIT_UART=OFF \ |
| 37 | + -DATCA_HAL_KIT_HID=OFF \ |
| 38 | + -DATCA_HAL_KIT_BRIDGE=OFF \ |
| 39 | + -DATCA_BUILD_SHARED_LIBS=OFF \ |
| 40 | + -DATCA_OPENSSL=OFF \ |
| 41 | + -DATCA_ATECC608_SUPPORT=ON \ |
| 42 | + -DATCA_PRINTF=ON \ |
| 43 | + 2>&1 && \ |
| 44 | + cmake --build . -j$(nproc) 2>&1 && \ |
| 45 | + cmake --install . 2>&1 |
| 46 | + |
| 47 | +# ---- Build test binary ---- |
| 48 | +COPY sdk-test/ /app/sdk-test/ |
| 49 | + |
| 50 | +# We link hal_tcp.c directly into the test binary (cryptoauthlib's CMake |
| 51 | +# compiles a stubbed `hal_custom.c` into the archive but doesn't link |
| 52 | +# user code, so we supply it here ourselves). |
| 53 | +RUN gcc -o /app/test_atecc608 \ |
| 54 | + /app/sdk-test/test_atecc608.c \ |
| 55 | + /app/sdk-test/hal_tcp.c \ |
| 56 | + -I/app/sdk-test \ |
| 57 | + -I/usr/include/cryptoauthlib \ |
| 58 | + -I/app/cryptoauthlib/build/lib \ |
| 59 | + -L/usr/lib \ |
| 60 | + -lcryptoauth -lssl -lcrypto -lpthread \ |
| 61 | + 2>&1 |
| 62 | + |
| 63 | +COPY sdk-test/run_test.sh /app/run_test.sh |
| 64 | +RUN chmod +x /app/run_test.sh |
| 65 | + |
| 66 | +CMD ["/app/run_test.sh"] |
0 commit comments