Compare commits

...

2 Commits

Author SHA1 Message Date
3f8a4024ce feat: .env file is optional 2025-06-01 12:55:05 +02:00
e8a74999c3 feat: dockerfile for image building 2025-06-01 12:54:44 +02:00
3 changed files with 56 additions and 5 deletions

53
Dockerfile Normal file
View File

@ -0,0 +1,53 @@
# Stage 1: Build frontend
FROM node:22 AS frontend-builder
WORKDIR /app/web
COPY web/ .
RUN npm install && npm run build
# Stage 2: Build backend
FROM golang:1.24 AS backend-builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Copy built frontend into Go embed path (adjust if needed)
# COPY --from=frontend-builder /app/web/dist ./web/dist
RUN CGO_ENABLED=0 GOOS=linux make build
# Stage 3: Final image
FROM debian:bookworm-slim
WORKDIR /app
# Install CA certificates for HTTPS
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=backend-builder /app/bin/hspguard .
COPY --from=frontend-builder /app/dist ./dist
# Optional: copy default .env file if used
# COPY .env .env
# Set environment variables (can be overridden at runtime)
ENV ENV=production \
GUARD_PORT=3001 \
GUARD_HOST="127.0.0.1" \
GUARD_DB_URL="postgres://user:user@localhost:5432/db?sslmode=disable" \
GUARD_ADMIN_NAME="admin" \
GUARD_ADMIN_EMAIL="admin@test.net" \
GUARD_ADMIN_PASSWORD="secret" \
GUARD_JWT_PRIVATE="rsa" \
GUARD_JWT_PUBLIC="rsa" \
GUARD_JWT_KID="my-rsa-key-1" \
GUARD_JWT_ISSUER="http://localhost:3001" \
GUARD_MINIO_ENDPOINT="localhost:9000" \
GUARD_MINIO_ACCESS_KEY="" \
GUARD_MINIO_SECRET_KEY="" \
GOOSE_DRIVER="postgres" \
GOOSE_DBSTRING=$GUARD_DB_URL \
GOOSE_MIGRATION_DIR="./migrations"
EXPOSE 3001
CMD ["./hspguard"]

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"os"
"gitea.local/admin/hspguard/cmd/hspguard/api"
"gitea.local/admin/hspguard/internal/config"
@ -16,9 +17,8 @@ import (
func main() {
err := godotenv.Load()
if err != nil {
log.Fatalln("ERR: Failed to load environment variables:", err)
return
if err != nil && os.Getenv("ENV") != "production" {
log.Fatalln("WARNING: .env file not found. Skipping...")
}
var cfg config.AppConfig

View File

@ -1,4 +1,3 @@
services:
db:
image: postgres
@ -9,4 +8,3 @@ services:
POSTGRES_PASSWORD: guard
ports:
- "5432:5432"