From 073668a5b4704b83a9e4c22816c7506da45c7dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Sat, 21 Nov 2026 23:33:28 +0100 Subject: [PATCH] build: add dev compose stack, container image and makefile Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- .env.example | 4 ++++ Dockerfile | 24 ++++++++++++++++++++++++ Makefile | 34 ++++++++++++++++++++++++++++++++++ compose.yaml | 26 ++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 .env.example create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 compose.yaml diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c0d71b4 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +UPTIME_DATABASE_URL=postgres://uptime:uptime@localhost:5432/uptime?sslmode=disable +UPTIME_REDIS_URL=redis://localhost:6379/0 +UPTIME_LOG_FORMAT=text +UPTIME_CHECKER_REGION=local diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..95d9a0f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# syntax=docker/dockerfile:1 +FROM node:24-alpine AS web +WORKDIR /src +COPY package.json package-lock.json ./ +RUN npm ci --no-audit --no-fund +COPY internal/web ./internal/web +RUN npm run build + +FROM golang:1.27-alpine AS build +WORKDIR /src +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +COPY --from=web /src/internal/web/static/dist ./internal/web/static/dist +ARG VERSION=dev +ARG COMMIT=none +RUN CGO_ENABLED=0 go build -trimpath \ + -ldflags "-s -w -X git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo.Version=${VERSION} -X git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo.Commit=${COMMIT}" \ + -o /out/ ./cmd/... + +FROM gcr.io/distroless/static-debian12:nonroot +COPY --from=build /out/ /usr/local/bin/ +USER nonroot +ENTRYPOINT ["/usr/local/bin/api"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cfe3faf --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev) +COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none) +PKG := git.zb-server.de/ZB-Server/uptimesebi +LDFLAGS := -s -w -X $(PKG)/internal/buildinfo.Version=$(VERSION) -X $(PKG)/internal/buildinfo.Commit=$(COMMIT) + +.PHONY: generate web build test lint dev-up dev-down migrate image + +generate: + sqlc generate + go tool templ generate + +web: + npm run build + +build: generate web + CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ ./cmd/... + +test: + go test ./... + +lint: + golangci-lint run + +dev-up: + docker compose up -d --wait + +dev-down: + docker compose down + +migrate: + go run ./cmd/api migrate up + +image: + docker build --build-arg VERSION=$(VERSION) --build-arg COMMIT=$(COMMIT) -t uptimesebi:$(VERSION) . diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..46cdd1c --- /dev/null +++ b/compose.yaml @@ -0,0 +1,26 @@ +name: uptimesebi + +services: + timescaledb: + image: timescale/timescaledb:2.30.1-pg16 + environment: + POSTGRES_USER: uptime + POSTGRES_PASSWORD: uptime + POSTGRES_DB: uptime + ports: ["5432:5432"] + volumes: [pgdata:/var/lib/postgresql/data] + healthcheck: + test: ["CMD", "pg_isready", "-U", "uptime"] + interval: 2s + retries: 30 + + redis: + image: redis:8-alpine + ports: ["6379:6379"] + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 2s + retries: 30 + +volumes: + pgdata: