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"