Skip to content

Commit

Permalink
šŸš€ refactor(docker): use pre-built image and update volume configuratiā€¦
Browse files Browse the repository at this point in the history
ā€¦ons in docker-compose files
  • Loading branch information
fsociety committed Oct 31, 2024
1 parent 01b8a42 commit 9e970e6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 43 deletions.
5 changes: 0 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ RELAY_URL="relay.utxo.one"
RELAY_PORT=3355
RELAY_BIND_ADDRESS="0.0.0.0" # Can be set to a specific IP4 or IP6 address ("" for all interfaces)
DB_ENGINE="badger" # badger, lmdb (lmdb works best with an nvme, otherwise you might have stability issues)
BLOSSOM_PATH="blossom/"

## Private Relay Settings
PRIVATE_RELAY_NAME="utxo's private relay"
Expand Down Expand Up @@ -77,7 +76,6 @@ INBOX_RELAY_CONNECTION_RATE_LIMITER_MAX_TOKENS=9
## Import Settings
IMPORT_START_DATE="2023-01-20"
IMPORT_QUERY_INTERVAL_SECONDS=600
IMPORT_SEED_RELAYS_FILE="relays_import.json"

## Backup Settings
BACKUP_PROVIDER="none" # aws, gcp, none (or leave blank to disable)
Expand All @@ -91,6 +89,3 @@ AWS_BUCKET_NAME="backups"

## GCP Backup Settings - REQUIRED IF BACKUP_PROVIDER="gcp"
GCP_BUCKET_NAME="backups"

## Blastr Settings
BLASTR_RELAYS_FILE="relays_blastr.json"
47 changes: 21 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
# Use Golang image based on Debian Bookworm
FROM golang:bookworm
# Use Debian-based Golang image for building
FROM golang:bookworm AS builder

# Install git and set working directory
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*

# Set the working directory within the container
WORKDIR /app

# Setup cache directories
RUN go env -w GOCACHE=/go-cache
RUN go env -w GOMODCACHE=/gomod-cache

# Clone the repository and build app
ARG REPO_URL=https://github.com/bitvora/haven.git
ARG VERSION
RUN git clone --branch ${VERSION} --single-branch ${REPO_URL} .
RUN --mount=type=cache,target=/gomod-cache --mount=type=cache,target=/go-cache \
go build -ldflags="-w -s" -o main .

# Clone the repository
RUN git clone --branch ${VERSION} ${REPO_URL} .

# Download dependencies
ENV GOPROXY=https://proxy.golang.org
RUN go mod download

# Build the Go application
RUN go build -o main .
# Final Distroless image
FROM gcr.io/distroless/base

# Add environment variables for UID and GID
ARG DOCKER_UID=1000
ARG DOCKER_GID=1000
# Add non-root user specification
USER nonroot

# 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
WORKDIR /app

# Switch to the new user
USER appuser
# Copy Go application
COPY --from=builder /app/main .

# Expose the port that the application will run on
# Expose port and set command
EXPOSE 3355

# Set the command to run the executable
CMD ["./main"]
2 changes: 2 additions & 0 deletions blossom/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
9 changes: 3 additions & 6 deletions docker-compose.tor.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
services:
relay:
container_name: haven-relay
build:
context: .
dockerfile: Dockerfile
args:
VERSION: v1.0.0
image: holgerhatgarkeinenode/haven-docker:v1.0.0
env_file:
- .env
volumes:
- "./db:/app/db"
- "./templates:/app/templates"
- "./blossom:/app/blossom"
- "./relays_import.json:/app/relays_import.json"
- "./relays_blastr.json:/app/relays_blastr.json"
ports:
- "3355:3355"
- "3355:${RELAY_PORT:-3355}"
user: "${DOCKER_UID:-1000}:${DOCKER_GID:-1000}"
restart: unless-stopped

Expand Down
9 changes: 3 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
services:
relay:
container_name: haven-relay
build:
context: .
dockerfile: Dockerfile
args:
VERSION: v1.0.0
image: holgerhatgarkeinenode/haven-docker:v1.0.0
env_file:
- .env
volumes:
- "./db:/app/db"
- "./templates:/app/templates"
- "./blossom:/app/blossom"
- "./relays_import.json:/app/relays_import.json"
- "./relays_blastr.json:/app/relays_blastr.json"
ports:
- "3355:3355"
- "3355:${RELAY_PORT:-3355}"
user: "${DOCKER_UID:-1000}:${DOCKER_GID:-1000}"
restart: unless-stopped

0 comments on commit 9e970e6

Please sign in to comment.