Skip to content

Commit b09e95a

Browse files
committed
Merge #365: Fix single-command to run demo env with docker
8defabd doc: [#351] fix single-command to run demo env with docker (Jose Celano) Pull request description: The single command provided by the documentation to run a demo with docker did not work. See #351 This PR only fixes that command and improves a little bit the documentation. In the short term, we need to make some improvements described [here](#361). In the long term, we need to make UX better. See the issue #351 for some ideas about how we can make it. Top commit has no ACKs. Tree-SHA512: d1a665bb9bda511fe866118d343e0cd4422f8ca69ee23cd1430df755411a3f9a847904f539e140a6b1616aadceec20b0b0652236b4b433ba9f5cdb26257a84d1
2 parents 3f367c6 + 8defabd commit b09e95a

File tree

6 files changed

+88
-32
lines changed

6 files changed

+88
-32
lines changed

bin/install-demo.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Single command to setup and run the tracker using the pre-built image.
4+
5+
# Check if 'storage' directory exists
6+
if [ -d "./storage" ]; then
7+
echo "Warning: 'storage' directory already exists. Please remove or rename it before proceeding."
8+
exit 1
9+
fi
10+
11+
# Check if 'config.toml' file exists in the current directory
12+
if [ -f "./config.toml" ]; then
13+
echo "Warning: 'config.toml' file already exists in the root directory. Please remove or rename it before proceeding."
14+
exit 1
15+
fi
16+
17+
# Check if SQLite3 is installed
18+
if ! command -v sqlite3 &> /dev/null; then
19+
echo "Warning: SQLite3 is not installed on your system. Please install it and retry."
20+
exit 1
21+
fi
22+
23+
wget https://raw.githubusercontent.com/torrust/torrust-tracker/v3.0.0-alpha.3/config.toml.local -O config.toml \
24+
&& mkdir -p ./storage/database \
25+
&& mkdir -p ./storage/ssl_certificates \
26+
&& touch ./storage/database/data.db \
27+
&& echo ";" | sqlite3 ./storage/database/data.db

bin/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
# This script is only intended to be used for local development or testing environments.
4+
35
# Generate the default settings file if it does not exist
46
if ! [ -f "./config.toml" ]; then
57
cp ./config.toml.local ./config.toml

docker/README.md

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ storage/
1717

1818
> NOTE: you only need the `ssl_certificates` directory and certificates in case you have enabled SSL for the one HTTP tracker or the API.
1919
20+
## Demo environment
21+
22+
You can run a single command to setup the tracker with the default
23+
configuration and run it using the pre-built public docker image:
24+
25+
```s
26+
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/torrust/torrust-tracker/v3.0.0-alpha.3/bin/install-demo.sh | bash
27+
export TORRUST_TRACKER_USER_UID=1000 \
28+
&& docker run -it \
29+
--user="$TORRUST_TRACKER_USER_UID" \
30+
--publish 6969:6969/udp \
31+
--publish 7070:7070/tcp \
32+
--publish 1212:1212/tcp \
33+
--volume "$(pwd)/storage":"/app/storage" \
34+
--volume "$(pwd)/config.toml":"/app/config.toml":ro \
35+
torrust/tracker:3.0.0-alpha.3
36+
```
37+
38+
This is intended to be used to run a quick demo of the application.
39+
2040
## Dev environment
2141

2242
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:
2848
bind_address = "0.0.0.0:1212"
2949
```
3050

31-
Otherwise the API will be only accessible from inside the container.
51+
Otherwise, the API will be only accessible from inside the container.
3252

3353
### With docker
3454

35-
Build and run locally:
55+
Build and run locally. You can build the docker image locally:
3656

3757
```s
3858
docker context use default
3959
export TORRUST_TRACKER_USER_UID=1000
4060
./docker/bin/build.sh $TORRUST_TRACKER_USER_UID
4161
./bin/install.sh
42-
./docker/bin/run.sh $TORRUST_TRACKER_USER_UID
62+
./docker/bin/run-local-image.sh $TORRUST_TRACKER_USER_UID
4363
```
4464

45-
Run using the pre-built public docker image:
65+
Or you can run locally using the pre-built docker image:
4666

4767
```s
68+
docker context use default
4869
export TORRUST_TRACKER_USER_UID=1000
49-
docker run -it \
50-
--user="$TORRUST_TRACKER_USER_UID" \
51-
--publish 6969:6969/udp \
52-
--publish 7070:7070/tcp \
53-
--publish 1212:1212/tcp \
54-
--volume "$(pwd)/storage":"/app/storage" \
55-
torrust/tracker
70+
./bin/install.sh
71+
./docker/bin/run-public-image.sh $TORRUST_TRACKER_USER_UID
5672
```
5773

58-
> NOTES:
59-
>
60-
> - You have to create the SQLite DB (`data.db`) and configuration (`config.toml`) before running the tracker. See `bin/install.sh`.
61-
> - You have to replace the user UID (`1000`) with yours.
62-
> - Remember to switch to your default docker context `docker context use default`.
74+
In both cases, you will need to:
75+
76+
- Create the SQLite DB (`data.db`) if you are going to use SQLite.
77+
- Create the configuration file (`config.toml`) before running the tracker.
78+
- Replace the user UID (`1000`) with yours.
79+
80+
> NOTICE: that the `./bin/install.sh` can setup the application for you. But it
81+
uses a predefined configuration.
82+
83+
Remember to switch to your default docker context `docker context use default`
84+
and to change the API default configuration in `config.toml` to make it
85+
available from the host machine:
86+
87+
```toml
88+
[http_api]
89+
bind_address = "0.0.0.0:1212"
90+
```
6391

6492
### With docker-compose
6593

File renamed without changes.

docker/bin/run-public-image.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
TORRUST_TRACKER_USER_UID=${TORRUST_TRACKER_USER_UID:-1000}
4+
TORRUST_TRACKER_CONFIG=$(cat config.toml)
5+
6+
docker run -it \
7+
--user="$TORRUST_TRACKER_USER_UID" \
8+
--publish 6969:6969/udp \
9+
--publish 7070:7070/tcp \
10+
--publish 1212:1212/tcp \
11+
--env TORRUST_TRACKER_CONFIG="$TORRUST_TRACKER_CONFIG" \
12+
--volume "$(pwd)/storage":"/app/storage" \
13+
torrust/tracker

src/lib.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,8 @@
136136
//!
137137
//! ## Run with docker
138138
//!
139-
//! You can run the tracker with a pre-built docker image:
140-
//!
141-
//! ```text
142-
//! mkdir -p ./storage/database \
143-
//! && mkdir -p ./storage/ssl_certificates \
144-
//! && export TORRUST_TRACKER_USER_UID=1000 \
145-
//! && docker run -it \
146-
//! --user="$TORRUST_TRACKER_USER_UID" \
147-
//! --publish 6969:6969/udp \
148-
//! --publish 7070:7070/tcp \
149-
//! --publish 1212:1212/tcp \
150-
//! --volume "$(pwd)/storage":"/app/storage" \
151-
//! torrust/tracker:3.0.0-alpha.3
152-
//! ```
153-
//!
154-
//! For more information about using docker visit the [tracker docker documentation](https://github.com/torrust/torrust-tracker/tree/develop/docker).
139+
//! You can run the tracker with a pre-built docker image. Please refer to the
140+
//! [tracker docker documentation](https://github.com/torrust/torrust-tracker/tree/develop/docker).
155141
//!
156142
//! # Configuration
157143
//!

0 commit comments

Comments
 (0)