From 8313157de16d8a1e32f03d458c4bb7675cf74cd1 Mon Sep 17 00:00:00 2001 From: Daniel Cadenas Date: Tue, 23 Jul 2024 08:54:02 -0300 Subject: [PATCH] Move config.toml to container --- Dockerfile | 49 +++++++++++++++++++++++++--------------------- docker-compose.yml | 3 +-- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index 28448dd3..e4788254 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,25 @@ FROM docker.io/library/rust:1-bookworm as builder -RUN apt-get update \ - && apt-get install -y cmake protobuf-compiler \ - && rm -rf /var/lib/apt/lists/* -RUN USER=root cargo install cargo-auditable -RUN USER=root cargo new --bin nostr-rs-relay -WORKDIR ./nostr-rs-relay + +RUN apt-get update && \ + apt-get install -y cmake protobuf-compiler && \ + rm -rf /var/lib/apt/lists/* + +RUN cargo install cargo-auditable + +RUN cargo new --bin nostr-rs-relay +WORKDIR /nostr-rs-relay + COPY ./Cargo.toml ./Cargo.toml COPY ./Cargo.lock ./Cargo.lock -# build dependencies only (caching) RUN cargo auditable build --release --locked -# get rid of starter project code + RUN rm src/*.rs -# copy project source code COPY ./src ./src COPY ./proto ./proto COPY ./build.rs ./build.rs +COPY config.toml /usr/src/app/config.toml -# build auditable release using locked deps RUN rm ./target/release/deps/nostr*relay* RUN cargo auditable build --release --locked @@ -25,28 +27,31 @@ FROM docker.io/library/debian:bookworm-slim ARG APP=/usr/src/app ARG APP_DATA=/usr/src/app/db -RUN apt-get update \ - && apt-get install -y ca-certificates tzdata sqlite3 libc6 \ - && rm -rf /var/lib/apt/lists/* + +RUN apt-get update && \ + apt-get install -y ca-certificates tzdata sqlite3 libc6 && \ + rm -rf /var/lib/apt/lists/* EXPOSE 7777 ENV TZ=Etc/UTC \ - APP_USER=appuser + APP_USER=appuser \ + RUST_LOG=info,nostr_rs_relay=info \ + APP_DATA=${APP_DATA} -RUN groupadd $APP_USER \ - && useradd -g $APP_USER $APP_USER \ - && mkdir -p ${APP} \ - && mkdir -p ${APP_DATA} +RUN groupadd $APP_USER && \ + useradd -g $APP_USER $APP_USER && \ + mkdir -p ${APP} && \ + mkdir -p ${APP_DATA} && \ + chown -R $APP_USER:$APP_USER ${APP} COPY --from=builder /nostr-rs-relay/target/release/nostr-rs-relay ${APP}/nostr-rs-relay +COPY --from=builder /usr/src/app/config.toml ${APP}/config.toml -RUN chown -R $APP_USER:$APP_USER ${APP} +RUN chown $APP_USER:$APP_USER ${APP}/config.toml USER $APP_USER WORKDIR ${APP} -ENV RUST_LOG=info,nostr_rs_relay=info -ENV APP_DATA=${APP_DATA} - CMD ./nostr-rs-relay --db ${APP_DATA} + diff --git a/docker-compose.yml b/docker-compose.yml index eadd9d6b..6017de1c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,13 +3,12 @@ services: build: . container_name: nostr-relay ports: - - "7000:8080" + - "7000:7777" user: "100:100" environment: - RUST_LOG=debug volumes: - ./data:/usr/src/app/db:Z - - ./config.toml:/usr/src/app/config.toml:ro,Z stdin_open: true tty: true restart: unless-stopped