1
0
Fork 0
modbusmqtt/Dockerfile

48 lines
1.7 KiB
Docker
Raw Normal View History

2022-09-11 18:31:50 +10:00
# -*- mode: dockerfile -*-
2022-09-11 18:43:55 +10:00
FROM rust:1.63 AS builder
2022-09-11 18:31:50 +10:00
2022-09-11 18:43:55 +10:00
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && apt-get --no-install-recommends install -y \
libudev-dev
2022-09-11 18:31:50 +10:00
# Build a cacheable layer with project dependencies
RUN USER=rust cargo new /home/rust/sungrow-winets
RUN USER=rust cargo new /home/rust/tokio_modbus-winets
RUN USER=rust cargo new /home/rust/modbus-mqtt
WORKDIR /home/rust/modbus-mqtt
ADD --chown=rust:rust Cargo.lock modbus-mqtt/Cargo.toml ./
2022-09-12 09:42:14 +10:00
RUN mkdir -p /home/rust/modbus-mqtt/target/release
RUN --mount=type=cache,target=/home/rust/modbus-mqtt/target,sharing=locked \
2022-09-12 10:08:36 +10:00
--mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
2022-09-12 09:42:14 +10:00
cargo build --release
2022-09-11 18:31:50 +10:00
# # Delete files & directories which shouldn't exist for the workspace
# RUN rm -rf src
# Add our source code.
ADD --chown=rust:rust . ./
# Build our application.
2022-09-12 09:42:14 +10:00
RUN --mount=type=cache,target=/home/rust/modbus-mqtt/target,sharing=locked \
2022-09-12 10:08:36 +10:00
--mount=type=cache,target=/usr/local/cargo/registry,sharing=locked \
2022-09-12 10:39:53 +10:00
cargo build --release && mv target/release/modbus-mqtt ./bin
2022-09-11 18:31:50 +10:00
# Now, we need to build our _real_ Docker container, copying in `bump-api`.
2022-09-11 18:43:55 +10:00
FROM debian:bullseye-slim
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && apt-get --no-install-recommends install -y \
libudev1
2022-09-11 18:31:50 +10:00
COPY --from=builder \
2022-09-12 09:42:14 +10:00
/home/rust/modbus-mqtt/bin \
/usr/local/bin/modbus-mqtt
2022-09-11 18:31:50 +10:00
ENV RUST_LOG=warn,modbus_mqtt=info
ENTRYPOINT ["/usr/local/bin/modbus-mqtt"]