Skip to content

Commit

Permalink
dev: more docker work
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Aug 26, 2023
1 parent 971b26e commit 7d4178f
Show file tree
Hide file tree
Showing 18 changed files with 217 additions and 115 deletions.
30 changes: 15 additions & 15 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.git
.git-blame-ignore
.github
.gitignore
.vscode
bin/
config.toml
config.toml.local
cSpell.json
data.db
/.git
/.git-blame-ignore
/.github
/.gitignore
/.vscode
/bin/
/tracker.*
/cSpell.json
/data.db
/docker/bin/
NOTICE
README.md
rustfmt.toml
storage/
target/
/NOTICE
/README.md
/rustfmt.toml
/storage/
/target/
/etc/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
/.coverage/
/.idea/
/.vscode/launch.json
/config.toml
/tracker.toml
/data.db
/database.db
/database.json.bz2
/storage/
/target
/tracker.*
37 changes: 22 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ WORKDIR /tmp
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
RUN cargo binstall --no-confirm cargo-chef cargo-nextest


## Tester Image
FROM rust:slim as tester
WORKDIR /tmp
### (fixme) https://github.com/cargo-bins/cargo-binstall/issues/1252
RUN apt-get update; apt-get install -y curl; apt-get autoclean

RUN apt-get update; apt-get install -y curl sqlite3; apt-get autoclean
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
RUN cargo binstall --no-confirm cargo-nextest

COPY ./share/ /app/share/torrust
RUN mkdir -p /app/share/torrust/default/database/; \
touch /app/share/torrust/default/database/tracker.sqlite3.db; \
echo ";" | sqlite3 /app/share/torrust/default/database/tracker.sqlite3.db


## Chef Prepare (look at project and see wat we need)
FROM chef AS recipe
Expand Down Expand Up @@ -56,20 +60,16 @@ RUN cargo nextest archive --tests --benches --examples --workspace --all-targets
# Extract and Test (debug)
FROM tester as test_debug
WORKDIR /test
COPY . /test/src
COPY . /test/src/
COPY --from=build_debug \
/build/torrust-tracker-debug.tar.zst \
/test/torrust-tracker-debug.tar.zst
RUN mkdir -p /test/test
RUN cargo nextest run --workspace-remap /test/src/ --extract-to /test/src/ --no-run --archive-file /test/torrust-tracker-debug.tar.zst
RUN cargo nextest run --workspace-remap /test/src/ --target-dir-remap /test/src/target/ --cargo-metadata /test/src/target/nextest/cargo-metadata.json --binaries-metadata /test/src/target/nextest/binaries-metadata.json

RUN mkdir -p /app/bin/; cp -l /test/src/target/debug/torrust-tracker /app/bin/torrust-tracker
RUN mkdir /app/lib/; cp -l $(realpath $(ldd /app/bin/torrust-tracker | grep "libz\.so\.1" | awk '{print $3}')) /app/lib/libz.so.1

RUN chown -R root:root /app
RUN chmod -R u=rw,go=r,a+X /app
RUN chmod -R a+x /app/bin
RUN chown -R root:root /app; chmod -R u=rw,go=r,a+X /app; chmod -R a+x /app/bin

# Extract and Test (release)
FROM tester as test
Expand All @@ -83,21 +83,20 @@ RUN cargo nextest run --workspace-remap /test/src/ --target-dir-remap /test/src/

RUN mkdir -p /app/bin/; cp -l /test/src/target/release/torrust-tracker /app/bin/torrust-tracker
RUN mkdir -p /app/lib/; cp -l $(realpath $(ldd /app/bin/torrust-tracker | grep "libz\.so\.1" | awk '{print $3}')) /app/lib/libz.so.1

RUN chown -R root:root /app
RUN chmod -R u=rw,go=r,a+X /app
RUN chmod -R a+x /app/bin
RUN chown -R root:root /app; chmod -R u=rw,go=r,a+X /app; chmod -R a+x /app/bin


## Runtime
FROM gcr.io/distroless/cc:debug as Runtime
FROM gcr.io/distroless/cc:debug as runtime
RUN ["/busybox/cp", "-sp", "/busybox/sh", "/bin/sh"]

ARG TORRUST_TRACKER_PATH_CONFIG="/etc/torrust/tracker/config.toml"
ARG USER_ID=1000
ARG UDP_PORT=6969
ARG HTTP_PORT=7070
ARG API_PORT=1212

ENV TORRUST_TRACKER_PATH_CONFIG=${TORRUST_TRACKER_PATH_CONFIG}
ENV USER_ID=${USER_ID}
ENV UDP_PORT=${UDP_PORT}
ENV HTTP_PORT=${HTTP_PORT}
Expand All @@ -110,13 +109,21 @@ EXPOSE ${API_PORT}/tcp

WORKDIR /home/torrust
RUN adduser --disabled-password --uid "${USER_ID}" "torrust"
RUN mkdir -p /var/lib/torrust; chown -R "${USER_ID}":"${USER_ID}" /var/lib/torrust; chmod -R 2775 /var/lib/torrust
RUN mkdir -p /var/lib/torrust/tracker; chown -R "${USER_ID}":"${USER_ID}" /var/lib/torrust; chmod -R 2770 /var/lib/torrust
RUN mkdir -p /etc/torrust/tracker; chown -R "${USER_ID}":"${USER_ID}" /etc/torrust; chmod -R 2770 /etc/torrust

ENV ENV=/etc/profile
COPY ./docker/motd.debug /etc/motd

RUN echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/motd' >> /etc/profile
RUN src="/usr/share/torrust/default/database/tracker.sqlite3.db" && dest="/var/lib/torrust/tracker/database/sqlite3.db" \
&& echo "[ -e \"$src\" ] && [ ! -e \"$dest\" ] && install -D -m 0640 \"$src\" \"$dest\"" >> /etc/profile
RUN src="/usr/share/torrust/default/config/tracker.sqlite3.distribution.toml" && dest="/etc/torrust/tracker/config.toml" \
&& echo "[ -e \"$src\" ] && [ ! -e \"$dest\" ] && install -D -m 0640 \"$src\" \"$dest\"" >> /etc/profile

USER "torrust":"torrust"
VOLUME /var/lib/torrust/tracker
VOLUME /etc/torrust/tracker


## Torrust-Tracker (debug)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ git clone https://github.com/torrust/torrust-tracker.git \
&& mkdir -p ./storage/ssl_certificates
```

And then run `cargo run` twice. The first time to generate the `config.toml` file and the second time to run the tracker with the default configuration.
And then run `cargo run` twice. The first time to generate the `tracker.toml` file and the second time to run the tracker with the default configuration.

After running the tracker these services will be available:

Expand Down Expand Up @@ -78,3 +78,5 @@ The project is licensed under a dual license. See [COPYRIGHT](./COPYRIGHT).
## Acknowledgments

This project was a joint effort by [Nautilus Cyberneering GmbH](https://nautilus-cyberneering.de/) and [Dutch Bits](https://dutchbits.nl). Also thanks to [Naim A.](https://github.com/naim94a/udpt) and [greatest-ape](https://github.com/greatest-ape/aquatic) for some parts of the code. Further added features and functions thanks to [Power2All](https://github.com/power2all).


8 changes: 4 additions & 4 deletions bin/install-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ if [ -d "./storage" ]; then
exit 1
fi

# Check if 'config.toml' file exists in the current directory
if [ -f "./config.toml" ]; then
echo "Warning: 'config.toml' file already exists in the root directory. Please remove or rename it before proceeding."
# Check if 'tracker.toml' file exists in the current directory
if [ -f "./tracker.toml" ]; then
echo "Warning: 'tracker.toml' file already exists in the root directory. Please remove or rename it before proceeding."
exit 1
fi

Expand All @@ -20,7 +20,7 @@ if ! command -v sqlite3 &> /dev/null; then
exit 1
fi

wget https://raw.githubusercontent.com/torrust/torrust-tracker/v3.0.0-alpha.3/config.toml.local -O config.toml \
wget https://raw.githubusercontent.com/torrust/torrust-tracker/v3.0.0-alpha.3/tracker.toml.local -O tracker.toml \
&& mkdir -p ./storage/database \
&& mkdir -p ./storage/ssl_certificates \
&& touch ./storage/database/data.db \
Expand Down
6 changes: 3 additions & 3 deletions bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# This script is only intended to be used for local development or testing environments.

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

# Generate storage directory if it does not exist
mkdir -p "./storage/database"

# 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
# todo: it should get the path from tracker.toml and only do it when we use sqlite
touch ./storage/database/data.db
echo ";" | sqlite3 ./storage/database/data.db
fi
3 changes: 3 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"codegen",
"completei",
"connectionless",
"Cyberneering",
"distroless",
"dockerhub",
"downloadedi",
Expand All @@ -49,6 +50,7 @@
"infoschema",
"Intermodal",
"intervali",
"keyout",
"lcov",
"leecher",
"leechers",
Expand All @@ -63,6 +65,7 @@
"myacicontext",
"Naim",
"nanos",
"newkey",
"nextest",
"nocapture",
"nologin",
Expand Down
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
tty: true
environment:
- TORRUST_TRACKER_CONFIG=${TORRUST_TRACKER_CONFIG}
- TORRUST_TRACKER_API_TOKEN=${TORRUST_TRACKER_API_TOKEN:-MyAccessToken}
- TORRUST_TRACKER_API_ADMIN_TOKEN=${TORRUST_TRACKER_API_ADMIN_TOKEN:-MyAccessToken}
networks:
- server_side
ports:
Expand Down
12 changes: 6 additions & 6 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export TORRUST_TRACKER_USER_UID=1000 \
--publish 7070:7070/tcp \
--publish 1212:1212/tcp \
--volume "$(pwd)/storage":"/app/storage" \
--volume "$(pwd)/config.toml":"/app/config.toml":ro \
--volume "$(pwd)/tracker.toml":"/app/tracker.toml":ro \
torrust/tracker:3.0.0-alpha.3
```

Expand Down Expand Up @@ -74,14 +74,14 @@ export TORRUST_TRACKER_USER_UID=1000
In both cases, you will need to:

- Create the SQLite DB (`data.db`) if you are going to use SQLite.
- Create the configuration file (`config.toml`) before running the tracker.
- Create the configuration file (`tracker.toml`) before running the tracker.
- Replace the user UID (`1000`) with yours.

> NOTICE: that the `./bin/install.sh` can setup the application for you. But it
uses a predefined configuration.

Remember to switch to your default docker context `docker context use default`
and to change the API default configuration in `config.toml` to make it
and to change the API default configuration in `tracker.toml` to make it
available from the host machine:

```toml
Expand All @@ -91,7 +91,7 @@ bind_address = "0.0.0.0:1212"

### With docker-compose

The docker-compose configuration includes the MySQL service configuration. If you want to use MySQL instead of SQLite you have to change your `config.toml` configuration:
The docker-compose configuration includes the MySQL service configuration. If you want to use MySQL instead of SQLite you have to change your `tracker.toml` configuration:

```toml
db_driver = "MySQL"
Expand Down Expand Up @@ -170,7 +170,7 @@ If the database, user or permissions are not created the reason could be the MyS

### SSL Certificates

You can use a certificate for localhost. You can create your [localhost certificate](https://letsencrypt.org/docs/certificates-for-localhost/#making-and-trusting-your-own-certificates) and use it in the `storage` folder and the configuration file (`config.toml`). For example:
You can use a certificate for localhost. You can create your [localhost certificate](https://letsencrypt.org/docs/certificates-for-localhost/#making-and-trusting-your-own-certificates) and use it in the `storage` folder and the configuration file (`tracker.toml`). For example:

The storage folder must contain your certificates:

Expand All @@ -184,7 +184,7 @@ storage/
└── localhost.key
```

You have not enabled it in your `config.toml` file:
You have not enabled it in your `tracker.toml` file:

```toml
...
Expand Down
2 changes: 1 addition & 1 deletion docker/bin/run-local-image.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

TORRUST_TRACKER_CONFIG=$(cat config.toml)
TORRUST_TRACKER_CONFIG=$(cat tracker.toml)

docker run -it \
--user="$(whoami)" \
Expand Down
2 changes: 1 addition & 1 deletion docker/bin/run-public-image.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

TORRUST_TRACKER_CONFIG=$(cat config.toml)
TORRUST_TRACKER_CONFIG=$(cat tracker.toml)

docker run -it \
--user="$(whoami)" \
Expand Down
Loading

0 comments on commit 7d4178f

Please sign in to comment.