From ef68672d9d60aa9d45f8499303d31ed2abcad8b4 Mon Sep 17 00:00:00 2001 From: Mat Manna Date: Fri, 15 May 2026 15:45:26 +0000 Subject: [PATCH] fly --- Dockerfile | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ fly.toml | 26 ++++++++++++++++++++++++++ web/main.go | 5 +++-- 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 fly.toml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..228af13 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +# Stage 1: build web API +FROM golang:1.26-alpine AS web-builder +WORKDIR /src +COPY web/go.mod web/go.sum ./ +RUN go mod download +COPY web/*.go web/index.html ./ +RUN CGO_ENABLED=0 go build -o /server . + +# Stage 2: build worker binary +FROM golang:1.26-alpine AS worker-builder +WORKDIR /src +COPY worker/go.mod worker/go.sum ./ +RUN go mod download +COPY worker/*.go ./ +RUN CGO_ENABLED=0 go build -o /worker . + +# Stage 3: build vtracer from Rust +FROM rust:1-slim AS rust-builder +RUN cargo install vtracer + +# Stage 4: download inkstitch +FROM debian:trixie-slim AS inkstitch-builder +RUN apt-get update && apt-get install -y --no-install-recommends \ + wget xz-utils ca-certificates \ + && rm -rf /var/lib/apt/lists/* +ARG INKSTITCH_VERSION=3.2.2 +RUN ARCH=$(dpkg --print-architecture) && \ + if [ "$ARCH" = "arm64" ]; then INKARCH="aarch64"; else INKARCH="x86_64"; fi && \ + wget -q "https://github.com/inkstitch/inkstitch/releases/download/v${INKSTITCH_VERSION}/inkstitch-${INKSTITCH_VERSION}-linux-${INKARCH}.tar.xz" \ + -O /tmp/inkstitch.tar.xz && \ + mkdir -p /opt/inkstitch && \ + tar xJf /tmp/inkstitch.tar.xz -C /opt/inkstitch && \ + rm /tmp/inkstitch.tar.xz && \ + rm -rf /opt/inkstitch/inkstitch/fonts \ + /opt/inkstitch/inkstitch/bin/locales \ + /opt/inkstitch/inkstitch/inx \ + /opt/inkstitch/inkstitch/palettes \ + /opt/inkstitch/inkstitch/tiles \ + /opt/inkstitch/inkstitch/addons \ + /opt/inkstitch/inkstitch/symbols \ + /opt/inkstitch/inkstitch/dbus + +# Stage 5: runtime +FROM debian:trixie-slim +RUN apt-get update && apt-get install -y --no-install-recommends \ + inkscape libwayland-cursor0 libdrm2 libgbm1 libxcb-dri3-0 \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=web-builder /server /usr/local/bin/server +COPY --from=worker-builder /worker /usr/local/bin/worker +COPY --from=rust-builder /usr/local/cargo/bin/vtracer /usr/local/bin/vtracer +COPY --from=inkstitch-builder /opt/inkstitch /opt/inkstitch +ENV INKSTITCH_BIN=/opt/inkstitch/inkstitch/bin/inkstitch diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..b48f650 --- /dev/null +++ b/fly.toml @@ -0,0 +1,26 @@ +app = "pic-to-patch" +primary_region = "iad" + +[build] + dockerfile = "Dockerfile" + +[http_service] + internal_port = 8000 + force_https = true + auto_stop_machines = false + auto_start_machines = true + min_machines_running = 1 + processes = ["api"] + +[[vm]] + cpu_kind = "shared" + cpus = 2 + memory_mb = 4096 + +[[processes]] + name = "api" + command = "server" + +[[processes]] + name = "worker" + command = "worker" diff --git a/web/main.go b/web/main.go index c92ce36..510123b 100644 --- a/web/main.go +++ b/web/main.go @@ -54,8 +54,9 @@ func main() { mux.HandleFunc("GET /health", handleHealth) mux.HandleFunc("GET /", handleRoot) - log.Println("listening on :8000") - log.Fatal(http.ListenAndServe(":8000", mux)) + port := env("PORT", "8000") + log.Printf("listening on :%s", port) + log.Fatal(http.ListenAndServe(":"+port, mux)) } func handleCreatePatch(w http.ResponseWriter, r *http.Request) { -- 2.51.2