Skip to content

Commit 6bddedb

Browse files
committed
Add Dockerfile
1 parent 928f1e8 commit 6bddedb

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Builder stage
2+
FROM golang:1.23-alpine AS builder
3+
4+
# Install build dependencies
5+
RUN apk add --no-cache git gcc musl-dev
6+
7+
# Set working directory for the build
8+
WORKDIR /build
9+
10+
# Copy go.mod and go.sum files first for better caching
11+
COPY go.mod go.sum ./
12+
RUN go mod download
13+
14+
# Copy the source code
15+
COPY . .
16+
17+
# Build the application
18+
# Using CGO_ENABLED=0 for static linking and setting GOARCH=amd64 for compatibility
19+
RUN CGO_ENABLED=1 \
20+
go build -ldflags="-s -w" -o hashup .
21+
22+
# Final stage
23+
FROM alpine:latest
24+
25+
# Install runtime dependencies
26+
RUN apk add --no-cache ca-certificates tzdata sqlite
27+
28+
# Create necessary directories
29+
RUN mkdir -p /etc/hashup /data/hashup
30+
31+
# Add non-root user for running the service
32+
RUN adduser -D -h /home/hashup hashup
33+
RUN chown -R hashup:hashup /data/hashup
34+
35+
# Set working directory
36+
WORKDIR /app
37+
38+
# Copy the compiled binary from the builder stage
39+
COPY --from=builder /build/hashup /app/hashup
40+
RUN chmod +x /app/hashup
41+
42+
# Copy default configurations
43+
COPY configs/nats.conf /etc/hashup/nats.conf
44+
COPY configs/hashup.toml /etc/hashup/config.toml
45+
46+
# Expose NATS ports
47+
EXPOSE 4222 8222
48+
49+
# Volume for configuration and data
50+
VOLUME ["/etc/hashup", "/data/hashup"]
51+
52+
# Switch to non-root user
53+
USER hashup
54+
55+
ENTRYPOINT ["/app/hashup"]
56+
# Run hashup nats server
57+
CMD ["nats", "--config", "/etc/hashup/nats.conf", "--data-dir", "/data/hashup"]

configs/nats.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ USER_SECRET: secret
55

66
# js.conf
77
jetstream {
8+
store_dir /data/hashup/storage
89
# 1GB
910
max_memory_store: 1073741824
1011
# 100GB
@@ -31,7 +32,6 @@ jetstream {
3132
#}
3233

3334
http_port: 8222
34-
host: 127.0.0.1
3535
port: 4222
3636

3737
accounts: {

script/docker-build

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# docker buildx create --name buildx-container --driver=docker-container --use
5+
docker buildx build \
6+
--tag ghcr.io/rubiojr/hashup:latest \
7+
--platform linux/arm64/v8,linux/amd64 \
8+
--builder buildx-container \
9+
"$@" .
10+

0 commit comments

Comments
 (0)