Commit Β·
0984f9f
0
Parent(s):
Initial commit: Mixly HF Space deploy config
Browse filesModelled on Host-Tierly. Adapted after verifying against Mixly's
actual source (scripts/restore-db.mjs, src/lib/backup.ts, src/lib/s3.ts,
src/instrumentation.ts, src/lib/env.ts, shopify.app.toml):
- DB path /data/mixly.db, bucket Mixly-storage, snapshot prefix mixly-
- Space solora-hq/Mixly, GitHub source phamdung2209/Mixly
- Kept Prisma Studio proxy (Mixly has src/lib/ops/studio-proxy.ts)
- Dropped Crisp build secret (no Crisp integration in Mixly)
- Dropped --config=production (only a default shopify.app.toml exists)
- Scopes/API version taken from Mixly's own shopify.app.toml
Files changed (4)
- .gitattributesAdded+35
- DEPLOY.mdAdded+155
- DockerfileAdded+96
- README.mdAdded+22
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155# Mixly on Hugging Face Spaces β deploy & operations
The Space (`solora-hq/Mixly`) is a **Docker** host. Its `Dockerfile` clones the**private** GitHub repo `phamdung2209/Mixly` at build time and runs the Next.js app.
Public URL: `https://solora-hq-mixly.hf.space`
> β οΈ **Data isolation.** `solora-hq` also hosts **Tierly**, which is LIVE with real> merchant data. Mixly's `DATABASE_URL`, `S3_BUCKET`, and Space name are a> completely separate set of identifiers from Tierly's β never copy a value from> Tierly's `DEPLOY.md` here. Concretely: DB path is `/data/mixly.db` (not> `tierly.db`), bucket is `Mixly-storage` (not `Tierly-storage`), Space is> `solora-hq/Mixly` (not `solora-hq/Tierly`). Pointing Mixly at any of Tierly's> identifiers risks corrupting or leaking live merchant data.
---
## 0. First-time setup (do this once β the Space doesn't exist yet)
1. **Create the Space**: https://huggingface.co/new-space β Owner `solora-hq`, Space name `Mixly`, **SDK: Docker**, visibility your choice, no template.2. **Add the remote and push this repo**: ``` git remote add origin https://huggingface.co/spaces/solora-hq/Mixly git push -u origin main ``` The first build will fail (or crash-loop) until the secrets in Β§2 are set β that's expected, HF just needs a repo to attach the build to.3. **Create the S3 storage bucket**: HF β your `solora-hq` org β **Storage** β **New bucket** β name it exactly `Mixly-storage` (bare name, no slashes). Double check it is not `Tierly-storage`.4. **Set every secret in Β§2 below** (Space β Settings β Variables and secrets), then Space β Settings β **Factory rebuild**.
---
## 1. GitHub token (required β the repo is private)
Cloning a private repo inside the Docker build needs a token. Create a**fine-grained Personal Access Token**, scoped to just this repo, read-only:
1. GitHub β **Settings β Developer settings β Personal access tokens β Fine-grained tokens β Generate new**.2. **Resource owner**: `phamdung2209`. **Repository access**: *Only select repositories* β `Mixly`.3. **Permissions β Repository β Contents: Read-only** (that's all it needs).4. Expiration: 90 days (rotate on expiry). Generate β copy the `github_pat_β¦`.
Then add it to the Space as a **build secret**:- Space β **Settings β Variables and secrets β New secret**- Name: `GITHUB_TOKEN` Β· Value: the `github_pat_β¦`
> The Dockerfile reads it via `--mount=type=secret,id=GITHUB_TOKEN`, so it is> **never baked into an image layer**.
---
## 2. Space secrets (runtime) β Settings β Variables and secrets
π Paste values in the HF UI, never into code/git. **Secrets** (hidden) vs**Variables** (visible) β put all credentials as *Secrets*.
### Required| Name | Value / where from ||---|---|| `GITHUB_TOKEN` | build secret from Β§1 || `SHOPIFY_API_KEY` | Partner Dashboard β Mixly β API credentials || `SHOPIFY_API_SECRET` | β³ (secret) || `NEXT_PUBLIC_SHOPIFY_API_KEY` | **same value as** `SHOPIFY_API_KEY` || `SHOPIFY_SCOPES` | `read_orders,read_products,write_discounts` (match `shopify.app.toml`) || `SHOPIFY_APP_URL` | `https://solora-hq-mixly.hf.space` || `SHOPIFY_API_VERSION` | `2026-07` || `DATABASE_URL` | `file:/data/mixly.db` (persistent mount β see Β§3) || `SESSION_ENCRYPTION_KEY` | `openssl rand -hex 32`. **Set once, never change** (rotating it forces every store to re-auth). |
### Ops Console + DB access (`/ops`, `/ops/studio`)| Name | Value ||---|---|| `OPS_ALLOWLIST` | comma-separated emails allowed into `/ops` || `AUTH_SECRET` | `npx auth secret`. Keep stable (else your `/ops` sessions drop). || `AUTH_GOOGLE_ID` | Google Cloud Console β OAuth client ID || `AUTH_GOOGLE_SECRET` | β³ (redirect URI: `https://solora-hq-mixly.hf.space/api/auth/callback/google`) |
### DB backup (Β§4) β HF Storage Bucket via S3 API| Name | Value ||---|---|| `S3_ENDPOINT` | `https://s3.hf.co/solora-hq` (gateway scoped to the namespace) || `S3_BUCKET` | `Mixly-storage` (bare bucket name β **not** `Tierly-storage`) || `S3_ACCESS_KEY_ID` | `HFAKβ¦` β HF **Access Tokens** β token (Write) β dropdown β **Generate S3 credentials** || `S3_SECRET_ACCESS_KEY` | β³ (shown once) || `HF_TOKEN` | HF bearer token β used to rebuild/restart the Space from `/ops/backup` after a DB restore (Β§4), and by `scripts/sync-env.mjs` (Β§5), NOT the S3 creds |
### Optional (features degrade gracefully when unset)`SENTRY_DSN`, `HF_SPACE_ID` (defaults to `solora-hq/Mixly` in code β only set ifthe Space is ever renamed), `GITHUB_REPO` (overrides the clone source; theDockerfile's `ARG GITHUB_REPO` build arg already defaults to the right repo).
Mixly has **no** Crisp chat, QStash, or email (Resend) integration β unlikeTierly, none of `NEXT_PUBLIC_CRISP_WEBSITE_ID`, `QSTASH_*`, `RESEND_API_KEY`,`EMAIL_FROM`, or `CRON_SECRET` apply here; don't set them.
---
## 3. Persistent storage
Space β **Settings β Persistent storage** β enable (Small is plenty). It mountsat `/data`, which is where `DATABASE_URL=file:/data/mixly.db` points. Without it,`/data` resets on every rebuild β which is exactly why Β§4 exists.
> Do **not** mount the Storage Bucket as a data volume. Backup talks to it over the> S3 API (Β§4); a bucket *mount* is a schedule-time dependency and, if HF can't attach> it, the Space fails with "Scheduling failure: unable to schedule".
---
## 4. Database backup / restore (HF Storage Bucket, S3 API)
The app backs the SQLite DB up to a **Storage Bucket over the S3 API** and restoresit on boot if `/data` is empty β so data survives a rebuild even on the free tier.Network-only (no mount), so it never blocks Space scheduling.
- **What's backed up:** only the SQLite DB file (`/data/mixly.db`). It holds everything stateful: Shopify sessions (tokens encrypted at rest), bundle offers, bundle configs, shop profiles, settings. Migrations live in git; nothing else needs backing up.- **The one thing that is NOT in the bucket:** `SESSION_ENCRYPTION_KEY`. It lives only in Space secrets. Keep it β a restored DB with a lost/rotated key can't decrypt stored Shopify tokens (the app then just re-exchanges them, no data loss, but avoid churn).- **Bucket:** `solora-hq/Mixly-storage`. Objects: `latest.db` (overwritten in place β no history growth) + `snapshots/mixly-YYYY-MM-DD.db` (daily, pruned after 30 days).- **Schedule:** in-process β an initial backup ~1 min after boot, then hourly, plus a debounced write after each DB change and a final flush on SIGTERM (see `src/lib/backup.ts` + `src/lib/s3.ts`, started from `src/instrumentation.ts`).- **Operator-driven backup/restore:** unlike a plain snapshot loop, Mixly ships an `/ops/backup` panel (Google-authenticated, see Β§2) that can trigger an immediate backup, upload a snapshot to restore from, and inspect it (table/row checks) before committing. Restoring requires typing `overwrite` to confirm, snapshots the *current* DB as a `pre-restore-β¦db` rollback key first, then calls `restartSpace()` (needs `HF_TOKEN`) to restart the Space onto the restored file.
---
## 5. Deploy / rebuild
- **Redeploy the web app:** push to GitHub `main`, then in the Space use **Settings β Factory rebuild** (re-clones latest `main`).- **Push local env vars as Space secrets:** `HF_TOKEN=β¦ node scripts/sync-env.mjs [.env.production.local] [solora-hq/Mixly]` (both args optional, those are the defaults) β reads `KEY=value` lines and pushes each as a secret via the HF API. Changes apply on the next rebuild/restart.- **Deploy the Shopify Function / extensions:** that is a *separate* target, run from your machine (needs the Shopify CLI + Partner auth) β `npm run app:deploy`. The container also runs this non-fatally during a Space build (see Dockerfile), gated on the `SHOPIFY_CLI_PARTNERS_TOKEN` build secret.
> After changing scopes or the app URL, re-open the app in the store to re-consent.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596# syntax=docker/dockerfile:1## Hugging Face Space (Docker SDK) for Mixly.## The app source lives in the PRIVATE GitHub repo, not in this Space repo β this# Dockerfile clones it at build time using the GITHUB_TOKEN *build secret*, builds# the Next.js app, then runs it. Keeping the Space tiny means a rebuild always# pulls the latest `main` from GitHub.## The SQLite DB lives on the /data mount. On boot it is restored from the HF Storage# Bucket (S3 API) if /data is empty, so data survives even without paid Persistent# Storage (see scripts/restore-db.mjs).
# ---- builder ----FROM node:24-slim AS builderWORKDIR /appRUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates \ && rm -rf /var/lib/apt/lists/*
# Which repo/branch to deploy. Override GITHUB_REF (Space variable) to pin a release.ARG GITHUB_REPO=github.com/phamdung2209/Mixly.gitARG GITHUB_REF=main
# Clone with the token mounted as a build secret β it is never written into an# image layer. Add GITHUB_TOKEN in Space β Settings β Secrets.RUN --mount=type=secret,id=GITHUB_TOKEN,required=true \ git clone --depth 1 --branch "${GITHUB_REF}" \ "https://x-access-token:$(cat /run/secrets/GITHUB_TOKEN)@${GITHUB_REPO}" .
ENV NEXT_TELEMETRY_DISABLED=1# Placeholder values ONLY so env validation passes during `next build` (some server# modules read env at import). The app reads the REAL values from HF secrets at# runtime; none of these are NEXT_PUBLIC, so nothing is baked into the output.ENV SHOPIFY_API_KEY=build SHOPIFY_API_SECRET=build SHOPIFY_SCOPES=read_products \ SHOPIFY_APP_URL=https://build.invalid SHOPIFY_API_VERSION=2026-07 DATABASE_URL=file:/tmp/build.db# NEXT_PUBLIC_* is inlined into the client bundle at BUILD time, so it must exist# during `npm run build` β a runtime secret is too late. The Shopify API key is# public (it ships in the browser), so mounting the secret just for the build is safe.RUN --mount=type=secret,id=NEXT_PUBLIC_SHOPIFY_API_KEY \ export NEXT_PUBLIC_SHOPIFY_API_KEY="$(cat /run/secrets/NEXT_PUBLIC_SHOPIFY_API_KEY 2>/dev/null)" && \ npm ci && npx prisma generate && npm run build && mkdir -p public
# Deploy the Shopify Function + app config as part of the Space build, so ONE rebuild# ships the web app AND the extensions together. Only runs on a real rebuild (not on# restart/wake), so no version churn. NON-FATAL: a Shopify hiccup never breaks the web# deploy. Needs the SHOPIFY_CLI_PARTNERS_TOKEN Space secret (else it just skips).RUN --mount=type=secret,id=SHOPIFY_CLI_PARTNERS_TOKEN \ if [ -s /run/secrets/SHOPIFY_CLI_PARTNERS_TOKEN ]; then \ export SHOPIFY_CLI_PARTNERS_TOKEN="$(cat /run/secrets/SHOPIFY_CLI_PARTNERS_TOKEN)" CI=true; \ for d in extensions/*/; do [ -f "${d}package.json" ] && (cd "$d" && npm install --no-audit --no-fund || true); done; \ npx shopify app deploy --allow-updates || echo "WARN: shopify app deploy failed (non-fatal)"; \ else echo "SHOPIFY_CLI_PARTNERS_TOKEN not set β skipping Shopify deploy"; fi
# ---- runner ----FROM node:24-slim AS runnerWORKDIR /appENV NODE_ENV=production NEXT_TELEMETRY_DISABLED=1 PORT=3000 HOSTNAME=0.0.0.0
# tini as PID 1: forwards SIGTERM to the app and reaps zombies. Without it (e.g.# `npm start` as PID 1) npm swallows SIGTERM and never forwards it to the Node# server, so the shutdown DB backup (src/lib/backup.ts) never runs on a rebuild.RUN apt-get update && apt-get install -y --no-install-recommends tini \ && rm -rf /var/lib/apt/lists/*
# node:24-slim already ships a `node` user at UID 1000 (which HF mounts /data for) β# reuse it; creating a second UID-1000 user fails with "UID 1000 is not unique".COPY --from=builder --chown=node /app/node_modules ./node_modulesCOPY --from=builder --chown=node /app/.next ./.nextCOPY --from=builder --chown=node /app/public ./publicCOPY --from=builder --chown=node /app/package.json ./package.jsonCOPY --from=builder --chown=node /app/next.config.ts ./next.config.tsCOPY --from=builder --chown=node /app/prisma ./prismaCOPY --from=builder --chown=node /app/prisma.config.ts ./prisma.config.tsCOPY --from=builder --chown=node /app/scripts ./scripts
# Make /data writable with OR without Persistent Storage. If enabled, HF mounts# /data (uid 1000) over this. If not, this ephemeral dir is used and data still# survives rebuilds via the S3 bucket restore on boot (scripts/restore-db.mjs).RUN mkdir -p /data && chown node:node /dataUSER node
EXPOSE 3000# 1) restore the DB from the HF Storage Bucket (S3) if /data is empty, 2) apply migrations,# 3) start. Restore MUST run before migrate β migrate would otherwise create an# empty DB and the restore would think data already exists.# `exec next` (NOT `npm start`) so the Node server itself becomes the process that# receives SIGTERM on rebuild/sleep β that's what triggers the final DB backup# (src/lib/backup.ts). npm would fork the server as a child and swallow the signal.# tini (ENTRYPOINT) forwards the signal and reaps zombies.ENTRYPOINT ["tini", "--"]# Prisma Studio runs in the background on port 5555. NOTE: prisma studio v7 binds# 0.0.0.0 (no hostname flag) β it is NOT localhost-only. It stays private because HF# routes ONLY port 3000 as ingress and network-isolates the container; the DB is# reached via the operator + same-origin gated route handlers (src/lib/ops/studio-proxy)# at /ops/studio. Do NOT reuse this where 5555 is published (e.g. docker -p 5555:5555).CMD ["sh", "-c", "node scripts/restore-db.mjs && node_modules/.bin/prisma migrate deploy && (node_modules/.bin/prisma studio --port 5555 --browser none &) && exec node_modules/.bin/next start"]12345678910111213141516171819202122---title: Mixlyemoji: π¦colorFrom: purplecolorTo: greensdk: dockerapp_port: 3000pinned: falselicense: mitshort_description: Product bundles that discount what's already in the cart. No new SKUs, no inventory drift.---
# Mixly β Hugging Face Space
Docker host for the [Mixly](https://github.com/phamdung2209/Mixly) Shopify app.This Space repo holds only the `Dockerfile`; it clones the app source from theprivate GitHub repo at build time.
**Deploy / operations guide β [`DEPLOY.md`](./DEPLOY.md)** (GitHub token, secrets,persistent storage, DB backup/restore, rebuilds).
Config reference: https://huggingface.co/docs/hub/spaces-config-reference.gitattributesAdded+35
DEPLOY.mdAdded+155
DockerfileAdded+96
README.mdAdded+22