Skip to content

The only tool you need to know what is happening and how to fix it.

2.7 KB
Raw Blame
# ==============================================================================
# Traceway SQLite Docker Image
# Single binary serving API and Frontend with embedded SQLite.
# No external databases required. Optional S3 for blob storage.
# ==============================================================================

# ==============================================================================
# Stage 1: Build Frontend
# ==============================================================================
ARG NODE_VERSION=26

FROM --platform=$BUILDPLATFORM node:${NODE_VERSION}-alpine AS frontend-builder

WORKDIR /app/frontend

COPY frontend/package.json frontend/package-lock.json ./

RUN npm ci

COPY frontend/ ./

ENV CLOUD_MODE=false
RUN npm run build

# ==============================================================================
# Stage 2: Build Backend with embedded frontend (no storage tags = SQLite mode)
# ==============================================================================
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS backend-builder

WORKDIR /app/backend

RUN apk add --no-cache git

COPY backend/ ./
COPY cli/ /app/cli/

COPY --from=frontend-builder /app/frontend/build ./static/frontend/

RUN go mod edit -dropreplace=go.tracewayapp.com -dropreplace=go.tracewayapp.com/tracewaygin
RUN go mod tidy
RUN go mod download

# Build WITHOUT storage tags so the SQLite codepaths in app/db/db_transactional_sqlite.go
# and db_telemetry_sqlite.go are selected. modernc.org/sqlite is pure Go, so CGO_ENABLED=0 is fine.
ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w" -o /traceway ./cmd/traceway

# ==============================================================================
# Stage 3: Minimal runtime image
# ==============================================================================
FROM alpine:3.20

RUN apk add --no-cache ca-certificates tzdata

COPY --from=backend-builder /traceway /usr/local/bin/traceway

RUN mkdir -p /data && chmod 755 /data

WORKDIR /app

# SQLite databases and local blob storage both live under /data so a single
# bind-mount or named volume covers all persistent state.
ENV GIN_MODE=release \
    DB_TYPE=sqlite \
    SQLITE_PATH=/data/traceway.db \
    STORAGE_TYPE=local \
    STORAGE_PATH=/data/storage

# /data holds both SQLite files and local blob storage. Mount a host folder
# or named volume there to persist state across restarts. We deliberately do
# NOT declare a VOLUME here so the image stays compatible with platforms that
# require platform-managed volumes (e.g. Railway).

EXPOSE 80 8082

HEALTHCHECK --interval=30s --timeout=3s --start-period=300s --retries=3 \
    CMD wget -qO- http://localhost/health || exit 1

ENTRYPOINT ["/usr/local/bin/traceway"]