Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.git
.git-blame-ignore
.github
.gitignore
.vscode
bin/
config.toml
config.toml.local
cSpell.json
data.db
docker/
NOTICE
README.md
rustfmt.toml
storage/
target/
1 change: 1 addition & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TORRUST_TRACKER_USER_UID=1000
72 changes: 72 additions & 0 deletions .github/workflows/publish_docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Publish docker image

on:
push:
branches:
- "main"
- "develop"
tags:
- "v*"

env:
# Azure file share volume mount requires the Linux container run as root
# https://learn.microsoft.com/en-us/azure/container-instances/container-instances-volume-azure-files#limitations
# TORRUST_TRACKER_RUN_AS_USER: root
TORRUST_TRACKER_RUN_AS_USER: appuser

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: llvm-tools-preview
- uses: Swatinem/rust-cache@v1
- name: Run Tests
run: cargo test

dockerhub:
needs: test
runs-on: ubuntu-latest
environment: dockerhub-torrust
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
# For example: torrust/tracker
"${{ secrets.DOCKER_HUB_USERNAME }}/${{secrets.DOCKER_HUB_REPOSITORY_NAME }}"
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
build-args: |
RUN_AS_USER=${{ env.TORRUST_TRACKER_RUN_AS_USER }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
26 changes: 26 additions & 0 deletions .github/workflows/test_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test docker build

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
push: false
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build docker-compose images
run: docker compose build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
/target
**/*.rs.bk
/database.json.bz2
Expand All @@ -6,4 +7,6 @@
/config.toml
/data.db
/.vscode/launch.json
/storage/


1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ lto = "thin"
debug = 1
opt-level = 3
lto = "fat"
strip = true

[dependencies]
tokio = { version = "1", features = [
Expand Down
80 changes: 80 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 development
WORKDIR /app
ARG UID=1000
ARG RUN_AS_USER=appuser
ARG TRACKER_UDP_PORT=6969
ARG TRACKER_HTTP_PORT=7070
ARG TRACKER_API_PORT=1212
# Add the app user for development
ENV USER=appuser
ENV UID=$UID
RUN adduser --uid "${UID}" "${USER}"
# Build dependencies
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --recipe-path recipe.json
# Build the application
COPY . .
RUN cargo build --bin torrust-tracker
USER $RUN_AS_USER:$RUN_AS_USER
EXPOSE $TRACKER_UDP_PORT/udp
EXPOSE $TRACKER_HTTP_PORT/tcp
EXPOSE $TRACKER_API_PORT/tcp
CMD ["cargo", "run"]


FROM chef AS builder
WORKDIR /app
ARG UID=1000
# Add the app user for production
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
COPY . .
RUN cargo build --release --target x86_64-unknown-linux-musl --bin torrust-tracker
# Strip the binary
# More info: https://github.com/LukeMathWalker/cargo-chef/issues/149
RUN strip /app/target/x86_64-unknown-linux-musl/release/torrust-tracker


FROM alpine:latest
WORKDIR /app
ARG RUN_AS_USER=appuser
ARG TRACKER_UDP_PORT=6969
ARG TRACKER_HTTP_PORT=7070
ARG TRACKER_API_PORT=1212
RUN apk --no-cache add ca-certificates
ENV TZ=Etc/UTC
ENV RUN_AS_USER=$RUN_AS_USER
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder --chown=$RUN_AS_USER \
/app/target/x86_64-unknown-linux-musl/release/torrust-tracker \
/app/torrust-tracker
RUN chown -R $RUN_AS_USER:$RUN_AS_USER /app
USER $RUN_AS_USER:$RUN_AS_USER
EXPOSE $TRACKER_UDP_PORT/udp
EXPOSE $TRACKER_HTTP_PORT/tcp
EXPOSE $TRACKER_API_PORT/tcp
ENTRYPOINT ["/app/torrust-tracker"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bind_address = "0.0.0.0:6969"

[[http_trackers]]
enabled = true
bind_address = "0.0.0.0:6969"
bind_address = "0.0.0.0:7070"
ssl_enabled = false
ssl_cert_path = ""
ssl_key_path = ""
Expand Down
13 changes: 13 additions & 0 deletions bin/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/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 "./storage/database/data.db" ]; then
# todo: it should get the path from config.toml and only do it when we use sqlite
touch ./storage/database/data.db
echo ";" | sqlite3 ./storage/database/data.db
fi
10 changes: 10 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"words": [
"appuser",
"AUTOINCREMENT",
"automock",
"Avicora",
Expand All @@ -9,31 +10,38 @@
"Bitflu",
"bools",
"bufs",
"Buildx",
"byteorder",
"canonicalize",
"canonicalized",
"chrono",
"clippy",
"completei",
"dockerhub",
"downloadedi",
"filesd",
"Freebox",
"hasher",
"hexlify",
"hlocalhost",
"Hydranode",
"incompletei",
"infoschema",
"intervali",
"leecher",
"leechers",
"libtorrent",
"Lphant",
"mockall",
"myacicontext",
"nanos",
"nextest",
"nocapture",
"oneshot",
"ostr",
"Pando",
"proot",
"Quickstart",
"Rasterbar",
"repr",
"reqwest",
Expand All @@ -50,9 +58,11 @@
"thiserror",
"Torrentstorm",
"torrust",
"torrustracker",
"typenum",
"Unamed",
"untuple",
"uroot",
"Vagaa",
"Xtorrent",
"Xunlei"
Expand Down
48 changes: 48 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: torrust
services:

tracker:
build:
context: .
target: development
user: ${TORRUST_TRACKER_USER_UID:-1000}:${TORRUST_TRACKER_USER_UID:-1000}
tty: true
networks:
- server_side
ports:
- 6969:6969/udp
- 7070:7070
- 1212:1212
volumes:
- ./:/app
- ~/.cargo:/home/appuser/.cargo
depends_on:
- mysql

mysql:
image: mysql:8.0
command: '--default-authentication-plugin=mysql_native_password'
restart: always
healthcheck:
test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 --password="$$(cat /run/secrets/db-password)" --silent']
interval: 3s
retries: 5
start_period: 30s
environment:
- MYSQL_ROOT_HOST=%
- MYSQL_ROOT_PASSWORD=root_secret_password
- MYSQL_DATABASE=torrust_tracker
- MYSQL_USER=db_user
- MYSQL_PASSWORD=db_user_secret_password
networks:
- server_side
ports:
- 3306:3306
volumes:
- mysql_data:/var/lib/mysql

networks:
server_side: {}

volumes:
mysql_data: {}
34 changes: 34 additions & 0 deletions config.toml.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
log_level = "info"
mode = "public"
db_driver = "Sqlite3"
db_path = "./storage/database/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:7070"
ssl_enabled = false
ssl_cert_path = ""
ssl_key_path = ""

[http_api]
enabled = true
bind_address = "127.0.0.1:1212"
ssl_enabled = false
ssl_cert_path = ""
ssl_key_path = ""

[http_api.access_tokens]
admin = "MyAccessToken"
Loading