fix docker stuff

This commit is contained in:
2025-05-10 19:43:13 +01:00
parent f5fe3ff2ce
commit 2b7d8fe691
3 changed files with 23 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
FROM golang:1.24 as builder
FROM golang:1.24 AS builder
WORKDIR /app
@@ -10,14 +10,18 @@ COPY web ./web
RUN CGO_ENABLED=0 GOOS=linux go build -o ./server
FROM gcr.io/distroless/base-debian11 AS build-release-stage
FROM alpine:3.21.3
COPY --from=builder /app/server /app/server
ARG uid
ARG gid
RUN apk add --no-cache tzdata && addgroup -g ${gid} -S nonroot && adduser -u ${uid} -S nonroot -G nonroot
COPY --from=builder --chown=nonroot:nonroot /app/server /app/server
WORKDIR /app
RUN chown -R nonroot:nonroot /app
USER nonroot:nonroot
WORKDIR /app
EXPOSE 8080
ENTRYPOINT ["./server"]

View File

@@ -2,8 +2,14 @@ services:
server:
build:
dockerfile: ./Dockerfile
env_file:
- .env
args:
uid: $UID
gid: $GID
environment:
GEMINI_API_KEY: $GEMINI_API_KEY
OPEN_WEATHER_MAP_API_KEY: $OPEN_WEATHER_MAP_API_KEY
VAPID_PRIVATE_KEY_BASE64: $VAPID_PRIVATE_KEY_BASE64
VAPID_PUBLIC_KEY_BASE64: $VAPID_PUBLIC_KEY_BASE64
ports:
- "8080:8080"
volumes:

View File

@@ -417,6 +417,12 @@ func handleHTTPRequest(state *state) http.HandlerFunc {
}
func initDB() (*sql.DB, error) {
f, err := os.OpenFile("data/data.sqlite", os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
f.Close()
db, err := sql.Open("sqlite", "file:data/data.sqlite")
if err != nil {
log.Fatalln("failed to initialize database")