From 66ea44bc7bf86bf31ac180107fcc863dab604653 Mon Sep 17 00:00:00 2001 From: brookjeynes Date: Sun, 19 Apr 2026 19:51:02 +1000 Subject: [PATCH] feat(ci): setup fly.io hosting Signed-off-by: brookjeynes --- .dockerignore | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ fly.toml | 37 ++++++++++++++++++++++++++++++++ litefs.yml | 28 ++++++++++++++++++++++++ 4 files changed, 181 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 fly.toml create mode 100644 litefs.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c31d26e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,59 @@ +# Database files +*.db +*.db-* + +# Environment +.env +.env.local +.env.*.local + +# Fly.io config +fly.toml + +# Generated files +*/**/*templ.go + +# Build artifacts +static/files + +# Scripts +run.sh + +# Git +.git/ +.jj/ +.gitignore +.gitattributes + +# Documentation +README.md +*.md +docs/ + +# CI/CD +.github/ +.gitlab-ci.yml + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +Thumbs.db + +# Dependencies +node_modules/ +vendor/ + +# Logs and test coverage +*.log +coverage.txt +*.coverprofile + +# Temporary files +tmp/ +temp/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..513c379 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +ARG GO_VERSION=1 +FROM golang:${GO_VERSION}-bookworm as builder + +# Install the templ CLI tool for Go +RUN go install github.com/a-h/templ/cmd/templ@latest + +# Install the standalone Tailwind CSS CLI +RUN curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 && \ + chmod +x tailwindcss-linux-x64 && \ + mv tailwindcss-linux-x64 /usr/local/bin/tailwindcss + +# Install the minify CLI tool +RUN curl -L -o minify.tar.gz https://github.com/tdewolff/minify/releases/download/v2.24.0/minify_linux_amd64.tar.gz && \ + tar -xzf minify.tar.gz && \ + mv minify /usr/local/bin/minify && \ + rm minify.tar.gz + +WORKDIR /usr/src/app + +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . + +RUN /go/bin/templ generate + +# Create the directory structure for static assets +RUN mkdir -p ./static/files + +# Minify existing JS files +RUN find internal static -path 'static/files' -prune -o -name '*.js' -print | while read f; do minify "$f" -o "static/files/js/$(basename "$f")"; done + +# Download frontend libraries into the static folder +RUN curl -sLo ./static/files/js/htmx.min.js https://cdn.jsdelivr.net/npm/htmx.org@2.0.6/dist/htmx.min.js +RUN curl -sLo ./static/files/js/lucide.min.js https://unpkg.com/lucide@0.525.0/dist/umd/lucide.min.js +RUN curl -sLo ./static/files/js/alpinejs.min.js https://cdn.jsdelivr.net/npm/alpinejs@3.14.9/dist/cdn.min.js +RUN curl -sLo ./static/files/js/htmx-toaster.min.js https://unpkg.com/htmx-toaster@0.0.20/dist/htmx-toaster.min.js + +RUN tailwindcss -i ./input.css -o ./static/files/style.css --minify + +RUN go build -v -o /run-app ./cmd/server/main.go + +FROM debian:bookworm + +# Install ca-certificates for TLS and the sqlite3 CLI tool +RUN apt-get update -y && \ + apt-get install -y ca-certificates fuse3 sqlite3 && \ + rm -rf /var/lib/apt/lists/* + +# Copy LiteFS binary and config +COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs +COPY litefs.yml /etc/litefs.yml + +# Copy the compiled Go binary +COPY --from=builder /run-app /usr/local/bin/ + +CMD ["litefs", "mount", "-config", "/etc/litefs.yml"] diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..f6f17b7 --- /dev/null +++ b/fly.toml @@ -0,0 +1,37 @@ +app = 'shlf.space' +primary_region = 'syd' +kill_signal = "SIGINT" +kill_timeout = "5s" + +[build] + [build.args] + GO_VERSION = '1.25.0' + +[experimental] + auto_rollback = true + +[env] + YOTEN_PORT = '8081' + YOTEN_DB_PATH = '/litefs/shlf.db' + +[http_service] + internal_port = 8080 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 1 + processes = ['app'] + + [http_service.concurrency] + type = "requests" + hard_limit = 1000 + soft_limit = 800 + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1 + +[mounts] + source = 'litefs' + destination = '/var/lib/litefs' diff --git a/litefs.yml b/litefs.yml new file mode 100644 index 0000000..70ccb98 --- /dev/null +++ b/litefs.yml @@ -0,0 +1,28 @@ +fuse: + dir: "/litefs" + +data: + dir: "/var/lib/litefs" + +exit-on-error: true + +proxy: + addr: ":8080" + target: "localhost:8081" + db: "shlf.db" + passthrough: + - "*.ico" + - "*.png" + +exec: + - cmd: "run-app" + +lease: + type: "consul" + advertise-url: "http://${HOSTNAME}.vm.${FLY_APP_NAME}.internal:20202" + candidate: ${FLY_REGION == PRIMARY_REGION} + promote: true + + consul: + url: "${FLY_CONSUL_URL}" + key: "litefs/${FLY_APP_NAME}" -- 2.51.2