Created
January 7, 2026 08:16
-
-
Save shrumm/6e588a4b40c128d4566a2075435a07a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Build stage - compile and test with CGO/FTS5 support | |
| FROM golang:1.25-bookworm AS builder | |
| # Install build dependencies and test runtime | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| gcc \ | |
| libsqlite3-dev \ | |
| nodejs \ | |
| npm \ | |
| chromium \ | |
| libnss3 \ | |
| libfreetype6 \ | |
| libharfbuzz0b \ | |
| ca-certificates \ | |
| fonts-freefont-ttf \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set Playwright to use system Chromium | |
| ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 | |
| ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium | |
| WORKDIR /app | |
| # Copy go mod files first for better caching | |
| COPY go.mod go.sum ./ | |
| RUN go mod download | |
| # Copy e2e package files and install dependencies | |
| COPY e2e/package*.json ./e2e/ | |
| RUN cd e2e && npm ci | |
| # Copy all source code | |
| COPY . . | |
| # Set CGO flags for FTS5 support | |
| ENV CGO_ENABLED=1 | |
| ENV CGO_CFLAGS="-DSQLITE_ENABLE_FTS5" | |
| ENV CGO_LDFLAGS="-lm" | |
| # Run Go unit tests - build fails if tests fail | |
| RUN go test -v ./... | |
| # Build the production binary | |
| RUN go build -ldflags="-s -w" -o bin/promptbin ./cmd/server | |
| # Run E2E tests against the built server | |
| ENV DATABASE_PATH=:memory: | |
| ENV PORT=8081 | |
| ENV ALLOWED_ORIGIN=http://localhost:8081 | |
| RUN ./bin/promptbin & SERVER_PID=$! && \ | |
| sleep 2 && \ | |
| cd e2e && npx playwright test --project=chromium; \ | |
| TEST_EXIT=$?; \ | |
| kill $SERVER_PID 2>/dev/null; \ | |
| exit $TEST_EXIT | |
| # Runtime stage - minimal image | |
| FROM debian:bookworm-slim | |
| # Install runtime dependencies | |
| RUN apt-get update \ | |
| && apt-get install -y --no-install-recommends libsqlite3-0 wget ca-certificates \ | |
| && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | |
| # Non-root user for security | |
| RUN useradd --no-create-home --shell /sbin/nologin --uid 10001 promptbin \ | |
| && mkdir -p /data \ | |
| && chown promptbin:promptbin /data | |
| WORKDIR /app | |
| # Copy binary from builder | |
| COPY --from=builder /app/bin/promptbin . | |
| USER promptbin | |
| EXPOSE 8080 | |
| HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ | |
| CMD wget -qO- http://localhost:8080/health || exit 1 | |
| CMD ["./promptbin"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment