From ca8dde54f1eb553029323a14d1478e5f962bab8a Mon Sep 17 00:00:00 2001 From: fsociety Date: Sat, 7 Sep 2024 15:57:21 +0200 Subject: [PATCH 1/6] feat: update Dockerfile, docker-compose and README for better Docker usage This commit updates the Dockerfile to use a more docker-friendly approach. Instead of cloning the repository inside the Dockerfile, it now copies the files from the host. It also sets some fixed environment variables and uses a .env file for the rest. The docker-compose.yml file now uses an .env file for more convenient environment variable management. It also maps volumes to the host, allowing you to change the paths of the `db` folder and `templates` folder. The README.md has been updated with new instructions reflecting these changes. It now includes instructions for running the Docker container in the foreground or background, and for updating the relay. --- .env.example | 3 ++- Dockerfile | 58 +++++++++++++++++++++++++--------------------- README.md | 34 ++++++++++++++++++--------- docker-compose.yml | 28 +++++++++++----------- 4 files changed, 70 insertions(+), 53 deletions(-) diff --git a/.env.example b/.env.example index 23fd632..6eeee36 100644 --- a/.env.example +++ b/.env.example @@ -3,4 +3,5 @@ RELAY_PUBKEY="e2ccf7cf20403f3f2a4a55b328f0de3be38558a7d5f33632fdaaefc726c1c8eb" RELAY_DESCRIPTION="Only notes in utxo WoT" RELAY_URL="wss://wot.utxo.one" DB_PATH="db" -INDEX_PATH="templates/index.html" \ No newline at end of file +INDEX_PATH="templates/index.html" +STATIC_PATH="templates/static" diff --git a/Dockerfile b/Dockerfile index 810ee65..4c7e391 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,31 @@ -# Use Golang image based on Debian Bookworm -FROM golang:bookworm - -# Set the working directory within the container -WORKDIR /app - -# Clone the repository -RUN git clone https://github.com/bitvora/wot-relay . - -# Download Go module dependencies -RUN go mod download - -# Write the .env file -RUN touch .env && \ - echo "RELAY_NAME=${RELAY_NAME}" >> .env && \ - echo "RELAY_PUBKEY=${RELAY_PUBKEY}" >> .env && \ - echo "RELAY_DESCRIPTION=${RELAY_DESCRIPTION}" >> .env && \ - echo "DB_PATH=${DB_PATH}" >> .env - -# Build the Go application -RUN go build -o main . - -# Expose the port that the application will run on -EXPOSE 3334 - -# Set the command to run the executable -CMD ["./main"] +# Use Golang image based on Debian Bookworm +FROM golang:bookworm + +# Set the working directory within the container +WORKDIR /app + +# Copy go.mod and go.sum files +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy the rest of the application source code +COPY . . + +# Set fixed environment variables +ENV DB_PATH="db" +ENV INDEX_PATH="templates/index.html" +ENV STATIC_PATH="templates/static" + +# touch a .env (https://github.com/bitvora/wot-relay/pull/4) +RUN touch .env + +# Build the Go application +RUN go build -o main . + +# Expose the port that the application will run on +EXPOSE 3334 + +# Set the command to run the executable +CMD ["./main"] diff --git a/README.md b/README.md index 79c13ff..26359fa 100644 --- a/README.md +++ b/README.md @@ -97,25 +97,37 @@ To start the project using Docker Compose, follow these steps: 1. Ensure Docker and Docker Compose are installed on your system. 2. Navigate to the project directory. -3. Edit the `docker-compose.yml` file to update the environment variables as needed: +3. Ensure the `.env` file is present in the project directory and has the necessary environment variables set. +4. You can also change the paths of the `db` folder and `templates` folder in the `docker-compose.yml` file. - ```yaml - environment: - RELAY_NAME: "utxo WoT relay" - RELAY_PUBKEY: "YOURPUBKEY" - RELAY_DESCRIPTION: "Only notes in utxo WoT" - DB_PATH: "./db" - ``` + ```yaml + volumes: + - "./db:/app/db" # only change the left side before the colon + - "./templates/index.html:/app/templates/index.html" # only change the left side before the colon + - "./templates/static:/app/templates/static" # only change the left side before the colon + ``` -4. Run the following command: +5. Run the following command: ```sh - docker-compose up --build + # in foreground + docker compose up --build + # in background + docker compose up --build -d + ``` +6. For updating the relay, run the following command: + + ```sh + git pull + docker compose build --no-cache + # in foreground + docker compose up + # in background + docker compose up -d ``` This will build the Docker image and start the `wot-relay` service as defined in the `docker-compose.yml` file. The application will be accessible on port 3334. - ### 7. Access the relay Once everything is set up, the relay will be running on `localhost:3334`. diff --git a/docker-compose.yml b/docker-compose.yml index 5cf78f7..5b03ad6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,14 @@ -services: - wot-relay: - build: - context: . - dockerfile: Dockerfile - environment: - RELAY_NAME: "utxo WoT relay" - RELAY_PUBKEY: "e2ccf7cf20403f3f2a4a55b328f0de3be38558a7d5f33632fdaaefc726c1c8eb" - RELAY_DESCRIPTION: "Only notes in utxo WoT" - DB_PATH: "./db" - volumes: - - "./db:/app/db" - ports: - - "3334:3334" \ No newline at end of file +services: + wot-relay: + container_name: wot-relay + build: + context: . + dockerfile: Dockerfile + env_file: + - .env + volumes: + - "./db:/app/db" # only change the left side before the colon + - "./templates/index.html:/app/templates/index.html" # only change the left side before the colon + - "./templates/static:/app/templates/static" # only change the left side before the colon + ports: + - "3334:3334" From 8458b2a10fa9bde993911aaf95255a1abb95e9c1 Mon Sep 17 00:00:00 2001 From: fsociety Date: Sat, 7 Sep 2024 16:08:53 +0200 Subject: [PATCH 2/6] feat: add .dockerignore file to wot-relay repository --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..885eac2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +db +templates From 6372f55a7bce2ad2ce569efb3db5c14ad3b75e08 Mon Sep 17 00:00:00 2001 From: fsociety Date: Sat, 7 Sep 2024 16:37:58 +0200 Subject: [PATCH 3/6] feat: add Tor support for relay service Add Tor support for the relay service in the docker-compose file. Also, rename the service from `wot-relay` to `relay`. Add a new `torrc` configuration file and a `.gitignore` file in the `tor/data` directory to prevent sensitive data from being tracked. Also, create a new `docker-compose.tor.yml` file for Tor-specific configurations. --- docker-compose.tor.yml | 26 ++++++++++++++++++++++++++ docker-compose.yml | 2 +- tor/data/.gitignore | 2 ++ tor/torrc | 2 ++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 docker-compose.tor.yml create mode 100644 tor/data/.gitignore create mode 100644 tor/torrc diff --git a/docker-compose.tor.yml b/docker-compose.tor.yml new file mode 100644 index 0000000..15d5760 --- /dev/null +++ b/docker-compose.tor.yml @@ -0,0 +1,26 @@ +services: + relay: + container_name: wot-relay + build: + context: . + dockerfile: Dockerfile + env_file: + - .env + volumes: + - "./db:/app/db" + - "./templates/index.html:/app/templates/index.html" + - "./templates/static:/app/templates/static" + ports: + - "3334" # disable clearnet access + #- "3334:3334" # enable clearnet access + + tor: + image: lncm/tor:0.4.7.9@sha256:86c2fe9d9099e6376798979110b8b9a3ee5d8adec27289ac4a5ee892514ffe92 + container_name: wot-relay-tor + depends_on: + - relay + volumes: + - ./tor/torrc:/etc/tor/torrc + - ./tor/data:/var/lib/tor + restart: on-failure + stop_grace_period: 10m30s diff --git a/docker-compose.yml b/docker-compose.yml index 5b03ad6..13ca973 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ services: - wot-relay: + relay: container_name: wot-relay build: context: . diff --git a/tor/data/.gitignore b/tor/data/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/tor/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tor/torrc b/tor/torrc new file mode 100644 index 0000000..e8e0702 --- /dev/null +++ b/tor/torrc @@ -0,0 +1,2 @@ +HiddenServiceDir /var/lib/tor/relay +HiddenServicePort 80 relay:3334 From 4dc6cab61880595f0f8d3a4ad6bdd572e4f740c0 Mon Sep 17 00:00:00 2001 From: fsociety Date: Sat, 7 Sep 2024 16:53:07 +0200 Subject: [PATCH 4/6] feat: add optional Tor support with clearnet toggle Added support for optionally running the wot-relay service as a Tor hidden service. Updated the docker-compose.tor.yml file to conditionally enable clearnet access, based on the `ENABLE_CLEARNET` environment variable. Updated the README.md file with instructions on how to use this feature. --- .env.example | 1 + README.md | 17 ++++++++++++++++- docker-compose.tor.yml | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 6eeee36..cb2991b 100644 --- a/.env.example +++ b/.env.example @@ -5,3 +5,4 @@ RELAY_URL="wss://wot.utxo.one" DB_PATH="db" INDEX_PATH="templates/index.html" STATIC_PATH="templates/static" +ENABLE_CLEARNET=false diff --git a/README.md b/README.md index 26359fa..772e122 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,22 @@ To start the project using Docker Compose, follow these steps: This will build the Docker image and start the `wot-relay` service as defined in the `docker-compose.yml` file. The application will be accessible on port 3334. -### 7. Access the relay +### 7. Hidden Service with Tor (optional) + +Same as the step 6, but with the following command: + +```sh +# in foreground +docker compose -f docker-compose.tor.yml up --build +# in background +docker compose -f docker-compose.tor.yml up --build -d +``` + +You can disable or enable clearnet access by changing `ENABLE_CLEARNET=false` or `ENABLE_CLEARNET=true` in the `.env` file. + +You can find the onion address here: `tor/data/relay/hostname` + +### 8. Access the relay Once everything is set up, the relay will be running on `localhost:3334`. diff --git a/docker-compose.tor.yml b/docker-compose.tor.yml index 15d5760..6bb6b4d 100644 --- a/docker-compose.tor.yml +++ b/docker-compose.tor.yml @@ -11,8 +11,8 @@ services: - "./templates/index.html:/app/templates/index.html" - "./templates/static:/app/templates/static" ports: - - "3334" # disable clearnet access - #- "3334:3334" # enable clearnet access + - "3334" # default port + - ${ENABLE_CLEARNET:+3334:3334} tor: image: lncm/tor:0.4.7.9@sha256:86c2fe9d9099e6376798979110b8b9a3ee5d8adec27289ac4a5ee892514ffe92 From 3698089a8f77e9d71fe527aabd46c965dce2f36d Mon Sep 17 00:00:00 2001 From: fsociety Date: Sat, 7 Sep 2024 17:05:30 +0200 Subject: [PATCH 5/6] feat: remove clearnet option from application configuration This commit removes the ENABLE_CLEARNET option from the .env.example file and the docker-compose.tor.yml file. The application will now only use the default port 3334. --- .env.example | 1 - docker-compose.tor.yml | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.env.example b/.env.example index cb2991b..6eeee36 100644 --- a/.env.example +++ b/.env.example @@ -5,4 +5,3 @@ RELAY_URL="wss://wot.utxo.one" DB_PATH="db" INDEX_PATH="templates/index.html" STATIC_PATH="templates/static" -ENABLE_CLEARNET=false diff --git a/docker-compose.tor.yml b/docker-compose.tor.yml index 6bb6b4d..9f03092 100644 --- a/docker-compose.tor.yml +++ b/docker-compose.tor.yml @@ -11,8 +11,7 @@ services: - "./templates/index.html:/app/templates/index.html" - "./templates/static:/app/templates/static" ports: - - "3334" # default port - - ${ENABLE_CLEARNET:+3334:3334} + - "3334" tor: image: lncm/tor:0.4.7.9@sha256:86c2fe9d9099e6376798979110b8b9a3ee5d8adec27289ac4a5ee892514ffe92 From 3f38d91de6aacd5bdb16b47b0f8a768f343a3b60 Mon Sep 17 00:00:00 2001 From: fsociety Date: Sat, 7 Sep 2024 17:14:06 +0200 Subject: [PATCH 6/6] docs: remove ENABLE_CLEARNET option from README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 772e122..91244c6 100644 --- a/README.md +++ b/README.md @@ -139,8 +139,6 @@ docker compose -f docker-compose.tor.yml up --build docker compose -f docker-compose.tor.yml up --build -d ``` -You can disable or enable clearnet access by changing `ENABLE_CLEARNET=false` or `ENABLE_CLEARNET=true` in the `.env` file. - You can find the onion address here: `tor/data/relay/hostname` ### 8. Access the relay