2024-08-08 14:11:30 -03:00
|
|
|
# Use an official Rust image as the base
|
|
|
|
FROM rust:latest
|
|
|
|
|
2024-08-16 18:07:17 -03:00
|
|
|
# Install necessary packages
|
2024-08-08 14:11:30 -03:00
|
|
|
RUN apt-get update && apt-get install -y \
|
|
|
|
libudev-dev \
|
|
|
|
iproute2 \
|
|
|
|
iputils-ping \
|
2024-08-16 13:14:54 -03:00
|
|
|
net-tools \
|
|
|
|
bridge-utils \
|
|
|
|
iptables \
|
|
|
|
supervisor \
|
2024-08-16 18:07:17 -03:00
|
|
|
traceroute \
|
2024-08-08 14:11:30 -03:00
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
# Clone the xbnet repository
|
2024-08-16 18:07:17 -03:00
|
|
|
# The xbnet repository contains the source code needed to set up and manage the XBee network
|
2024-08-08 14:11:30 -03:00
|
|
|
RUN git clone https://github.com/jgoerzen/xbnet.git /usr/src/xbnet
|
|
|
|
|
|
|
|
# Build xbnet
|
2024-08-16 18:07:17 -03:00
|
|
|
# We build the xbnet project from source using Cargo, Rust's package manager and build system
|
2024-08-08 14:11:30 -03:00
|
|
|
WORKDIR /usr/src/xbnet
|
2024-08-16 13:14:54 -03:00
|
|
|
RUN cargo build --release
|
2024-08-08 14:11:30 -03:00
|
|
|
|
2024-08-16 13:37:05 -03:00
|
|
|
# Copy the built binary to /usr/local/bin
|
2024-08-16 18:07:17 -03:00
|
|
|
# The xbnet binary will be placed in /usr/local/bin to be accessible system-wide
|
2024-08-08 14:11:30 -03:00
|
|
|
RUN cp target/release/xbnet /usr/local/bin/xbnet
|
|
|
|
|
2024-08-16 13:14:54 -03:00
|
|
|
# Copy the entrypoint script
|
2024-08-16 18:07:17 -03:00
|
|
|
# The entrypoint script handles the setup and monitoring of the XBee network
|
2024-08-16 13:37:05 -03:00
|
|
|
COPY ./scripts/entrypoint.sh /entrypoint.sh
|
2024-08-09 16:21:47 -03:00
|
|
|
RUN chmod +x /entrypoint.sh
|
2024-08-08 14:11:30 -03:00
|
|
|
|
2024-08-16 13:14:54 -03:00
|
|
|
# Copy the supervisor config file
|
2024-08-16 18:07:17 -03:00
|
|
|
# Supervisor configuration ensures that the XBee network service is managed and stays running
|
2024-08-16 13:14:54 -03:00
|
|
|
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
|
|
|
|
2024-08-16 13:37:05 -03:00
|
|
|
# Copy the health check script
|
2024-08-16 18:07:17 -03:00
|
|
|
# The health check script will be used by Docker to monitor the health of the container
|
2024-08-16 13:14:54 -03:00
|
|
|
COPY ./scripts/health_check.sh /health_check.sh
|
|
|
|
RUN chmod +x /health_check.sh
|
|
|
|
|
|
|
|
# Start supervisord as the main command
|
2024-08-16 18:07:17 -03:00
|
|
|
# Supervisord will manage and monitor the services, including the XBee network
|
2024-08-16 13:14:54 -03:00
|
|
|
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
2024-08-16 13:37:05 -03:00
|
|
|
|
|
|
|
# Add healthcheck
|
2024-08-16 18:07:17 -03:00
|
|
|
# The health check command periodically checks the health of the container using a custom script
|
2024-08-16 13:37:05 -03:00
|
|
|
HEALTHCHECK CMD /health_check.sh || exit 1
|