diff --git a/bin/install-demo.sh b/bin/install-demo.sh new file mode 100755 index 00000000..1b829ca1 --- /dev/null +++ b/bin/install-demo.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Single command to setup and run the tracker using the pre-built image. + +# Check if 'storage' directory exists +if [ -d "./storage" ]; then + echo "Warning: 'storage' directory already exists. Please remove or rename it before proceeding." + 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." + exit 1 +fi + +# Check if SQLite3 is installed +if ! command -v sqlite3 &> /dev/null; then + echo "Warning: SQLite3 is not installed on your system. Please install it and retry." + exit 1 +fi + +wget https://raw.githubusercontent.com/torrust/torrust-tracker/v3.0.0-alpha.3/config.toml.local -O config.toml \ + && mkdir -p ./storage/database \ + && mkdir -p ./storage/ssl_certificates \ + && touch ./storage/database/data.db \ + && echo ";" | sqlite3 ./storage/database/data.db diff --git a/bin/install.sh b/bin/install.sh index ef469a93..82ea940d 100755 --- a/bin/install.sh +++ b/bin/install.sh @@ -1,5 +1,7 @@ #!/bin/bash +# 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 diff --git a/docker/README.md b/docker/README.md index e0fee61e..207dadbb 100644 --- a/docker/README.md +++ b/docker/README.md @@ -17,6 +17,26 @@ storage/ > NOTE: you only need the `ssl_certificates` directory and certificates in case you have enabled SSL for the one HTTP tracker or the API. +## Demo environment + +You can run a single command to setup the tracker with the default +configuration and run it using the pre-built public docker image: + +```s +curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/torrust/torrust-tracker/v3.0.0-alpha.3/bin/install-demo.sh | bash +export TORRUST_TRACKER_USER_UID=1000 \ + && docker run -it \ + --user="$TORRUST_TRACKER_USER_UID" \ + --publish 6969:6969/udp \ + --publish 7070:7070/tcp \ + --publish 1212:1212/tcp \ + --volume "$(pwd)/storage":"/app/storage" \ + --volume "$(pwd)/config.toml":"/app/config.toml":ro \ + torrust/tracker:3.0.0-alpha.3 +``` + +This is intended to be used to run a quick demo of the application. + ## Dev environment When using docker you have to bind the exposed ports to the wildcard address `0.0.0.0`, so you can access the application from the host machine. @@ -28,38 +48,46 @@ The default API configuration uses `127.0.0.1`, so you have to change it to: bind_address = "0.0.0.0:1212" ``` -Otherwise the API will be only accessible from inside the container. +Otherwise, the API will be only accessible from inside the container. ### With docker -Build and run locally: +Build and run locally. You can build the docker image locally: ```s docker context use default 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 +./docker/bin/run-local-image.sh $TORRUST_TRACKER_USER_UID ``` -Run using the pre-built public docker image: +Or you can run locally using the pre-built docker image: ```s +docker context use default export TORRUST_TRACKER_USER_UID=1000 -docker run -it \ - --user="$TORRUST_TRACKER_USER_UID" \ - --publish 6969:6969/udp \ - --publish 7070:7070/tcp \ - --publish 1212:1212/tcp \ - --volume "$(pwd)/storage":"/app/storage" \ - torrust/tracker +./bin/install.sh +./docker/bin/run-public-image.sh $TORRUST_TRACKER_USER_UID ``` -> 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. -> - Remember to switch to your default docker context `docker context use default`. +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. +- 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 +available from the host machine: + +```toml +[http_api] +bind_address = "0.0.0.0:1212" +``` ### With docker-compose diff --git a/docker/bin/run.sh b/docker/bin/run-local-image.sh similarity index 100% rename from docker/bin/run.sh rename to docker/bin/run-local-image.sh diff --git a/docker/bin/run-public-image.sh b/docker/bin/run-public-image.sh new file mode 100755 index 00000000..50407f91 --- /dev/null +++ b/docker/bin/run-public-image.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +TORRUST_TRACKER_USER_UID=${TORRUST_TRACKER_USER_UID:-1000} +TORRUST_TRACKER_CONFIG=$(cat config.toml) + +docker run -it \ + --user="$TORRUST_TRACKER_USER_UID" \ + --publish 6969:6969/udp \ + --publish 7070:7070/tcp \ + --publish 1212:1212/tcp \ + --env TORRUST_TRACKER_CONFIG="$TORRUST_TRACKER_CONFIG" \ + --volume "$(pwd)/storage":"/app/storage" \ + torrust/tracker \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d14a3ada..28bac924 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,22 +136,8 @@ //! //! ## Run with docker //! -//! You can run the tracker with a pre-built docker image: -//! -//! ```text -//! mkdir -p ./storage/database \ -//! && mkdir -p ./storage/ssl_certificates \ -//! && export TORRUST_TRACKER_USER_UID=1000 \ -//! && docker run -it \ -//! --user="$TORRUST_TRACKER_USER_UID" \ -//! --publish 6969:6969/udp \ -//! --publish 7070:7070/tcp \ -//! --publish 1212:1212/tcp \ -//! --volume "$(pwd)/storage":"/app/storage" \ -//! torrust/tracker:3.0.0-alpha.3 -//! ``` -//! -//! For more information about using docker visit the [tracker docker documentation](https://github.com/torrust/torrust-tracker/tree/develop/docker). +//! You can run the tracker with a pre-built docker image. Please refer to the +//! [tracker docker documentation](https://github.com/torrust/torrust-tracker/tree/develop/docker). //! //! # Configuration //!