Skip to content

Commit

Permalink
fix(docker): add missing dependency (#374)
Browse files Browse the repository at this point in the history
also improve final image size and security
  • Loading branch information
jgmontoya authored Oct 19, 2024
1 parent a607d61 commit 96c3c3d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
8 changes: 6 additions & 2 deletions docker/DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ The `compose.yml` file is configured as follows:
```yaml
services:
mostro:
build: .
build:
context: ..
dockerfile: docker/Dockerfile
volumes:
- ~/mostro:/config # settings.toml and mostro.db
- ./config:/config # settings.toml and mostro.db
- ~/.polar/networks/1/volumes/lnd:/lnd # LND data
platform: linux/amd64

```

## Building and Running the Docker Container
Expand Down
35 changes: 20 additions & 15 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
# Build stage
FROM rust:latest as builder

# Install dependencies
RUN apt-get update && \
apt-get install -y cmake build-essential libsqlite3-dev pkg-config libssl-dev

# Clone repository
RUN git clone https://github.com/MostroP2P/mostro.git /mostro
FROM rust:1.81 AS builder

# Set working directory
WORKDIR /mostro

# Copy source code
COPY . .

# Install build dependencies
RUN apt-get update && \
apt-get install -y cmake build-essential libsqlite3-dev pkg-config libssl-dev protobuf-compiler

# Build the project in release mode
RUN cargo build --release

# Production stage
FROM rust:slim-bookworm
FROM debian:bookworm-slim

# Copy builded binary from build stage
# Copy built binary from build stage
COPY --from=builder /mostro/target/release/mostrod /usr/local/bin/mostrod

WORKDIR /mostro

# Copy settings and empty database
COPY ./settings.docker.toml /mostro/settings.docker.toml
COPY ./empty.mostro.db /mostro/empty.mostro.db
COPY --chown=mostrouser:mostrouser ./docker/settings.docker.toml ./docker/empty.mostro.db ./

# Copy start script
COPY start.sh /mostro/start.sh
RUN chmod +x /mostro/start.sh
COPY --chown=mostrouser:mostrouser ./docker/start.sh ./start.sh
RUN chmod +x ./start.sh

# Add a non-root user and switch to it
RUN useradd -m mostrouser
USER mostrouser

# Start mostro (copy settings and database if it's not created yet)
CMD ["/mostro/start.sh"]
ENTRYPOINT ["./start.sh"]
4 changes: 3 additions & 1 deletion docker/compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
services:
mostro:
build: .
build:
context: ..
dockerfile: docker/Dockerfile
volumes:
- ./config:/config # settings.toml and mostro.db
- ~/.polar/networks/1/volumes/lnd:/lnd # LND data
Expand Down
2 changes: 1 addition & 1 deletion docker/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ if [ ! -f /config/mostro.db ]; then
fi

# Run application
/usr/local/bin/mostrod -d /config
/usr/local/bin/mostrod -d /config

0 comments on commit 96c3c3d

Please sign in to comment.