Skip to content

Commit

Permalink
doc: [#351] fix single-command to run demo env with docker
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Aug 7, 2023
1 parent 3f367c6 commit 9a88846
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 32 deletions.
27 changes: 27 additions & 0 deletions bin/install-demo.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions bin/install.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
60 changes: 44 additions & 16 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/3.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.
Expand All @@ -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

Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions docker/bin/run-public-image.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 2 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down

0 comments on commit 9a88846

Please sign in to comment.