-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
š refactor(docker): use pre-built image and update volume configuratiā¦
ā¦ons in docker-compose files
- Loading branch information
fsociety
committed
Oct 31, 2024
1 parent
01b8a42
commit 9e970e6
Showing
5 changed files
with
29 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |