diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..2c5d9d837 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.github +bin/docker/ +data.db +storage/ +target/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 99a07430b..3220fd3f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -/target **/*.rs.bk -/database.json.bz2 -/database.db /.idea/ /config.toml -/data.db +/database.db +/database.json.bz2 +/storage/data.db +/target diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a0b73a442 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +FROM lukemathwalker/cargo-chef:latest-rust-1.62.0 AS chef +WORKDIR /app + + +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +COPY . . +RUN cargo build --release --bin torrust-tracker + + +FROM debian:bullseye-slim AS runtime +WORKDIR /app + +ENV TZ=Etc/UTC \ + APP_USER=appuser + +RUN groupadd $APP_USER \ + && useradd -g $APP_USER $APP_USER \ + && mkdir -p /app + +RUN chown -R $APP_USER:$APP_USER /app + +RUN apt-get -y update \ + && apt-get -y upgrade \ + && apt-get install -y sqlite3 libssl1.1 + +EXPOSE 6969 +EXPOSE 1212 + +COPY --from=builder /app/target/release/torrust-tracker /app + +USER $APP_USER + +ENTRYPOINT ["/app/torrust-tracker"] diff --git a/bin/docker/build.sh b/bin/docker/build.sh new file mode 100755 index 000000000..d082b74fa --- /dev/null +++ b/bin/docker/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build -t torrust-tracker . \ No newline at end of file diff --git a/bin/docker/run.sh b/bin/docker/run.sh new file mode 100755 index 000000000..41c93009b --- /dev/null +++ b/bin/docker/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker run --rm -it \ + -p 6969:6969 -p 1212:1212 \ + --volume "$(pwd)/storage":"/app/storage" \ + --mount type=bind,source="$(pwd)/config.toml",target=/app/config.toml \ + torrust-tracker