Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b13d229
feat: add docker image
josecelano Dec 6, 2022
0cb5423
feat: publish docker image on dockerhub
josecelano Dec 8, 2022
4312d5a
feat: move persistent state to storage folder
josecelano Dec 8, 2022
ff33e71
fix: publish docker images only for tags
josecelano Dec 8, 2022
6911c20
fix: run docker as root due to ACI limitations
josecelano Dec 8, 2022
a93d523
fix: pass missing build arg to docker build on CI
josecelano Dec 8, 2022
2853b44
docs: update README for docker
josecelano Dec 8, 2022
c10bed9
fix: expose udp port in dockerfile
josecelano Dec 8, 2022
59b4112
feat: expose port 6969/tcp pm Dokerfile
josecelano Dec 10, 2022
c57d4fc
feat: use long option names for docker commands
josecelano Dec 10, 2022
bdaa3b7
feat: change log level for UDP server stdoutput messages
josecelano Dec 10, 2022
db9b166
feat: new release v0.6.0
josecelano Dec 10, 2022
672dca7
feat: udpate .dockerignore
josecelano Dec 10, 2022
87b11a8
feat: expose HTTP tracker port
josecelano Dec 10, 2022
8333929
fix: docker cache for cargo dependencies
josecelano Dec 12, 2022
46971a2
feat: enable HTTPS for the API
josecelano Dec 12, 2022
b0243a5
docs: update docker README
josecelano Dec 12, 2022
a1e9b6a
feat: new release 0.7.0
josecelano Dec 12, 2022
0dd5b5c
fix: strip binary after build
josecelano Dec 12, 2022
54aa7ef
docs: update docker README
josecelano Dec 12, 2022
7b8762b
feat: change default HTTP tracker port to 7070
josecelano Dec 12, 2022
d8fc5c6
feat: use arguments for port in Dockerfile
josecelano Dec 12, 2022
f8ff415
feat: push also docker image for develop branch to docker registry
josecelano Dec 12, 2022
63ff9f7
docs: use latest docker image tag in the README
josecelano Dec 12, 2022
94ac063
feat: temporarily publish docker imamge for docker branch
josecelano Dec 12, 2022
cdb92d1
fix: test after changing default port
josecelano Dec 12, 2022
0184ac1
feat: build docker images only if tests pass
josecelano Dec 12, 2022
19a0839
feat: docker-compose support for development
josecelano Dec 13, 2022
25c1cc9
reafactor: rename workflow
josecelano Dec 13, 2022
ece2fd7
fix: workflow name
josecelano Dec 13, 2022
7885074
feat: use GH action for docker build
josecelano Dec 13, 2022
6ebbaf3
fix: import user from builder
josecelano Dec 13, 2022
a94b1ca
docs: update docker README
josecelano Dec 13, 2022
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
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.git
.git-blame-ignore
.github
.gitignore
.vscode
bin/
config.toml
config.toml.local
cSpell.json
data.db
docker/
docker/commands/
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
73 changes: 73 additions & 0 deletions .github/workflows/publish_docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Publish docker image

on:
push:
branches:
- 'develop'
# todo: only during development of issue 11
- 'docker'
tags:
- "v*"

env:
# todo: Replace with `torrust/torrust-tracker` in the final version
DOCKER_IMAGE: josecelano/torrust-tracker
# 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

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-josecelano
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.DOCKER_IMAGE }}
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
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/target
.env
**/*.rs.bk
/database.json.bz2
/database.db
/.idea/
/.vscode/launch.json
/config.toml
/data.db
/.vscode/launch.json

/database.db
/database.json.bz2
/storage
/target
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 "./storage/config/config.toml" ]; then
cp ./config.toml.local ./storage/config/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
9 changes: 9 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,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 +57,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