diff --git a/.env.example b/.env.example index c3de8ac..cd5af6a 100644 --- a/.env.example +++ b/.env.example @@ -45,3 +45,7 @@ AWS_BUCKET_NAME="utxo-relay-backups" ## Blastr Settings BLASTR_RELAYS="relay.damus.io,nos.lol,relay.nostr.band,relay.snort.social,nostr.land,nostr.mom,relay.nos.social,relay.primal.net,relay.nostr.bg,no.str.cr,nostr21.com,nostrue.com,relay.siamstr.com,wot.utxo.one,nostrelites.org,wot.nostr.party,wot.sovbit.host,wot.girino.org,relay.lnau.net,wot.siamstr.com,wot.sudocarlos.com,relay.otherstuff.fyi,relay.lexingtonbitcoin.org,wot.azzamo.net,wot.swarmstr.com,zap.watch,satsage.xyz,wons.calva.dev" + +## OPTIONAL: Docker UID and GID - should be the same as the user running the docker container +DOCKER_UID=1000 +DOCKER_GID=1000 diff --git a/.gitignore b/.gitignore index e168dc8..4c49bd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ .env -db/ -haven \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..44de815 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +# 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 . . + +# Build the Go application +RUN go build -o main . + +# Add environment variables for UID and GID +ARG DOCKER_UID=1000 +ARG DOCKER_GID=1000 + +# Create a new group and user +RUN groupadd -g ${DOCKER_GID} appgroup && \ + useradd -u ${DOCKER_UID} -g appgroup -m appuser + +# Change ownership of the working directory +RUN chown -R appuser:appgroup /app + +# Switch to the new user +USER appuser + +# 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 c543bee..5602fe0 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,56 @@ Once everything is set up, the relay will be running on `localhost:3355` with th - `localhost:3355/chat` - `localhost:3355/inbox` +## Start the Project with Docker Compose + +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. 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 `haven` folder in the `docker-compose.yml` file. + + ```yaml + volumes: + - "./db:/app/db" # only change the left side before the colon + - "./haven:/app/haven" # only change the left side before the colon + ``` + +5. Run the following command: + + ```sh + # 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 `haven-relay` service as defined in the `docker-compose.yml` file. The application will be accessible on port 3335. + +### Hidden Service with Tor and Docker (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 find the onion address here: `tor/data/haven/hostname` + ## Cloud Backups The relay automatically backs up your database to a cloud provider of your choice. diff --git a/db/.gitignore b/db/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/db/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/docker-compose.tor.yml b/docker-compose.tor.yml new file mode 100644 index 0000000..b014df6 --- /dev/null +++ b/docker-compose.tor.yml @@ -0,0 +1,25 @@ +services: + relay: + container_name: haven-relay + build: + context: . + dockerfile: Dockerfile + env_file: + - .env + volumes: + - "./db:/app/db" + - "./haven:/app/haven" + ports: + - "3335" + user: "${DOCKER_UID:-1000}:${DOCKER_GID:-1000}" + + tor: + image: lncm/tor:0.4.7.9@sha256:86c2fe9d9099e6376798979110b8b9a3ee5d8adec27289ac4a5ee892514ffe92 + container_name: haven-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 new file mode 100644 index 0000000..0c2ea58 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +services: + relay: + container_name: haven-relay + build: + context: . + dockerfile: Dockerfile + env_file: + - .env + volumes: + - "./db:/app/db" + - "./haven:/app/haven" + ports: + - "3335:3335" + user: "${DOCKER_UID:-1000}:${DOCKER_GID:-1000}" diff --git a/haven/.gitignore b/haven/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/haven/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore 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..ce82803 --- /dev/null +++ b/tor/torrc @@ -0,0 +1,2 @@ +HiddenServiceDir /var/lib/tor/haven +HiddenServicePort 80 relay:3355