Skip to content

Commit

Permalink
feat: add docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Dec 7, 2022
1 parent b1150d5 commit 1d6a59a
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.github
.vscode
config.toml
data.db
docker/commands/
target/
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM clux/muslrust:stable AS chef
WORKDIR /app
RUN cargo install cargo-chef


FROM chef AS planner
WORKDIR /app
COPY . .
RUN cargo chef prepare --recipe-path recipe.json


FROM chef AS builder
WORKDIR /app
ARG UID=1000
# Create the app user
ENV USER=appuser
ENV UID=$UID
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"
# Build dependencies
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
# Build the application
# todo: it seems the previous cache layer is not working. The dependencies are compiled always.
COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl --bin torrust-tracker


FROM alpine:latest
WORKDIR /app
RUN apk --no-cache add ca-certificates
ENV TZ=Etc/UTC APP_USER=appuser
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder --chown=$APP_USER \
/app/target/x86_64-unknown-linux-musl/release/torrust-tracker \
/app/torrust-tracker
RUN chown -R $APP_USER:$APP_USER /app
USER $APP_USER:$APP_USER
EXPOSE 6969
EXPOSE 1212
ENTRYPOINT ["/app/torrust-tracker"]
14 changes: 14 additions & 0 deletions bin/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Generate the default settings file if it does not exist
if ! [ -f "./config.toml" ]; then
cp ./config.toml.local ./config.toml
fi

# Generate the sqlite database if it does not exist
if ! [ -f "./data.db" ]; then
# todo: it should get the path from config.toml and only do it when we use sqlite
touch ./data.db
echo ";" | sqlite3 ./data.db
fi

31 changes: 31 additions & 0 deletions config.toml.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
log_level = "info"
mode = "public"
db_driver = "Sqlite3"
db_path = "data.db"
announce_interval = 120
min_announce_interval = 120
max_peer_timeout = 900
on_reverse_proxy = false
external_ip = "0.0.0.0"
tracker_usage_statistics = true
persistent_torrent_completed_stat = false
inactive_peer_cleanup_interval = 600
remove_peerless_torrents = true

[[udp_trackers]]
enabled = false
bind_address = "0.0.0.0:6969"

[[http_trackers]]
enabled = false
bind_address = "0.0.0.0:6969"
ssl_enabled = false
ssl_cert_path = ""
ssl_key_path = ""

[http_api]
enabled = true
bind_address = "127.0.0.1:1212"

[http_api.access_tokens]
admin = "MyAccessToken"
33 changes: 33 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Docker

## Requirements

- Docker version 20.10.21

## Dev environment

Build and run locally:

```s
export TORRUST_TRACKER_USER_UID=1000
./docker/bin/build.sh $TORRUST_TRACKER_USER_UID
./bin/install.sh
./docker/bin/run.sh $TORRUST_TRACKER_USER_UID
```

Run using the pre-built public docker image:

```s
export TORRUST_TRACKER_USER_UID=1000
docker run -it \
--user="$TORRUST_TRACKER_USER_UID" \
-p 6969:6969 -p 1212:1212 \
--mount type=bind,source="$(pwd)/data.db",target=/app/data.db \
--mount type=bind,source="$(pwd)/config.toml",target=/app/config.toml \
josecelano/torrust-tracker
```

> NOTES:
>
> - You have to create the SQLite DB (`data.db`) and configuration (`config.toml`) before running the tracker. See `bin/install.sh`.
> - You have to replace the user UID (`1000`) with yours.
10 changes: 10 additions & 0 deletions docker/bin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

TORRUST_TRACKER_USER_UID=${TORRUST_TRACKER_USER_UID:-1000}

echo "Building docker image ..."
echo "TORRUST_TRACKER_USER_UID: $TORRUST_TRACKER_USER_UID"

docker build \
--build-arg UID="$TORRUST_TRACKER_USER_UID" \
-t torrust-tracker .
4 changes: 4 additions & 0 deletions docker/bin/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

./docker/bin/build.sh
./bin/install.sh
10 changes: 10 additions & 0 deletions docker/bin/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

TORRUST_TRACKER_USER_UID=${TORRUST_TRACKER_USER_UID:-1000}

docker run -it \
--user="$TORRUST_TRACKER_USER_UID" \
-p 6969:6969 -p 1212:1212 \
--mount type=bind,source="$(pwd)/data.db",target=/app/data.db \
--mount type=bind,source="$(pwd)/config.toml",target=/app/config.toml \
torrust-tracker

0 comments on commit 1d6a59a

Please sign in to comment.