mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-27 15:48:54 +00:00
badges: webapp feature branch (#7548)
* badges: webapp (#7433) * badges: service migrations, store and catalog * badges: BTCPay provider and settlement poller * badges: web listener and /api endpoints * web: checkout single-page app * badges: tests and BTCPay fixtures * badges: README and ini reference * badges: fix hex16 build on GHC 8.10.7 * badges: Stripe card lane * badges: fix Stripe card checkout, add theming * badges: add a discount row to the order summary * badges: site navbar, embedding, theme, Forget move * badges: use SB code prefix in web checkout * badges: rename sxb app namespace to sb * badges: embed checkout nav via site; keep original app navbar * badges: post iframe height, apply site background when embedded * badges: embed dark surfaces, steadier iframe height * badges: hide app footer when embedded * badges: size embedded body to content, not viewport * badges: declare color-scheme to stop reload flash * badges: fade shell in on load, no reload blank * badges: prerender app shell into index.html * badges: pre-paint theme, hide shell on deep reload * badges: logo returns to landing client-side * badges: embedded wizard back, buy-a-code, resume * badges: signal app-managed screens, resume across reload * badges: rebuild wizard history on deep load so Back walks it * badges: carry welcome-page height as the iframe floor * badges: keep selection on Buy a code; rename to Your codes * badges: read web shell as UTF-8, not locale * badges: resume the exact paid order after Stripe card redirect * badges: move docker deploy under scripts * badges: add serve_webapp toggle and webapp export * badges: wire split webapp deploy in docker config * badges: quiet agent logs by default * badges: resume card redirect in the embedded frame * badges: migrate Stripe adapter to PaymentIntents * badges: correct Stripe restricted key scopes in ini example * badges: card via Payment Element and PaymentIntents * badges: fix stale Checkout Session wording in Stripe adapter * badges: fix stale CheckoutActions reference in card comment * badges: order shell stylesheet before bootstrap script * badges: remove development card stand-in * badges: theme the Stripe card form with the site palette * badges: exclude web from the Haskell build stage * badges: unify invoice cancel and mark canceled * badges: default log level to info * badges: unify closed-invoice buy-again button * badges: mute agent connection logs at info level * badges: show purchase time in local timezone in Your codes * badges: log service events on own channel, quiet agent * badges: fold service migrations into one baseline * badges: run compose on postgres over host network * badges: use high-res hero art * badges: add web CI to catch stale builds * badges: rebuild web shell from committed source * badges: normalize invoice-code link and columns * badges: drop unused columns, rename index * badges: note deferred receipt_hash in migrations * badges: apply code-review fixes * badges: reduce comments across service and web --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> * badges: improve web page (#7546) * badges: improve web page * improve layout * improve layout * fix * small changes --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> * badges: read one issuer key from the ini * badges: move and group the service tests * badges: service fixes (#7567) * badges: match the redeem error wording in tests * badges: drop unused imports in the bot tests * badges: cancel Stripe orders when they expire * badges: correct the Stripe config and docs * badges: refuse to revoke a redeemed code * badges: make the fake Stripe cancel like Stripe * badges: limit replayed webhook deliveries --------- Co-authored-by: sh <37271604+shumvgolove@users.noreply.github.com> Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> Co-authored-by: shum <github.shum@liber.li> Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
This commit is contained in:
co-authored by
Evgeny @ SimpleX Chat
sh
shum
spaced4ndy
parent
64014cd8b0
commit
19e70faeec
@@ -0,0 +1,99 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
# Built from the repository root, not this directory, because the COPY paths are repo-relative.
|
||||
# The Haskell stage compiles simplexmq and simplex-chat from source, which takes hours on a cold
|
||||
# cache and needs about 15 GB.
|
||||
|
||||
ARG UBUNTU=24.04
|
||||
ARG GHC=9.6.3
|
||||
ARG CABAL=3.10.2.0
|
||||
ARG NODE=24
|
||||
|
||||
# The checkout page's dist/ is gitignored, so this stage builds it.
|
||||
FROM node:${NODE}-bookworm-slim AS web
|
||||
|
||||
WORKDIR /web
|
||||
COPY apps/simplex-badge-service/web/package.json apps/simplex-badge-service/web/package-lock.json ./
|
||||
RUN npm ci
|
||||
COPY apps/simplex-badge-service/web ./
|
||||
RUN npm run build
|
||||
|
||||
FROM ubuntu:${UBUNTU} AS build
|
||||
|
||||
ARG GHC
|
||||
ARG CABAL
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential ca-certificates curl git libgmp3-dev libnuma-dev \
|
||||
libpq-dev libssl-dev llvm pkg-config zlib1g-dev && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \
|
||||
BOOTSTRAP_HASKELL_GHC_VERSION=${GHC} \
|
||||
BOOTSTRAP_HASKELL_CABAL_VERSION=${CABAL} \
|
||||
BOOTSTRAP_HASKELL_INSTALL_NO_STACK=true \
|
||||
BOOTSTRAP_HASKELL_INSTALL_NO_STACK_HOOK=true
|
||||
RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
|
||||
ENV PATH="/root/.ghcup/bin:/root/.cabal/bin:$PATH"
|
||||
# Set explicitly so the cache mount below matches where cabal keeps its store.
|
||||
ENV CABAL_DIR=/root/.cabal
|
||||
|
||||
WORKDIR /src
|
||||
COPY cabal.project simplex-chat.cabal README.md PRIVACY.md ./
|
||||
COPY scripts/cabal.project.local.linux ./cabal.project.local
|
||||
COPY src ./src
|
||||
# Excluding web/ keeps a webapp edit from invalidating this layer and re-running the cabal build,
|
||||
# and the binary does not depend on it.
|
||||
COPY --exclude=web apps/simplex-badge-service ./apps/simplex-badge-service
|
||||
|
||||
# The store and build tree are cache mounts rather than layers, so the binary is copied out inside
|
||||
# the same RUN because dist-newstyle does not exist in the resulting layer.
|
||||
RUN --mount=type=cache,target=/root/.cabal \
|
||||
--mount=type=cache,target=/src/dist-newstyle \
|
||||
set -eu; \
|
||||
cabal update; \
|
||||
cabal build --flags="+client_postgres" exe:simplex-badge-service; \
|
||||
mkdir -p /out; \
|
||||
cp "$(cabal list-bin --flags="+client_postgres" exe:simplex-badge-service)" /out/simplex-badge-service; \
|
||||
strip /out/simplex-badge-service
|
||||
|
||||
FROM ubuntu:${UBUNTU} AS runtime
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Built with +client_postgres, so the binary needs libpq and there is no SQLite backend.
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates dumb-init libgmp10 libpq5 libssl3 zlib1g && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set these to your own uid and gid so the state volume is readable without root.
|
||||
ARG USER_UID=1000
|
||||
ARG USER_GID=1000
|
||||
|
||||
# ubuntu:24.04 ships a default user at 1000, so drop whoever holds the ids.
|
||||
RUN if existing_user=$(getent passwd ${USER_UID} | cut -d: -f1) && [ -n "${existing_user}" ]; then \
|
||||
userdel -r "${existing_user}" 2>/dev/null || userdel "${existing_user}"; \
|
||||
fi && \
|
||||
if existing_group=$(getent group ${USER_GID} | cut -d: -f1) && [ -n "${existing_group}" ]; then \
|
||||
groupdel "${existing_group}" 2>/dev/null || true; \
|
||||
fi && \
|
||||
groupadd -g ${USER_GID} badge && \
|
||||
useradd -u ${USER_UID} -g ${USER_GID} -m -d /home/badge badge
|
||||
|
||||
COPY --from=build /out/simplex-badge-service /usr/local/bin/simplex-badge-service
|
||||
COPY --from=web /web/dist /srv/web
|
||||
|
||||
USER badge
|
||||
WORKDIR /home/badge
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
# There is no HEALTHCHECK because the listener answers before the chat side has an address, so it
|
||||
# would report healthy too early.
|
||||
|
||||
# The flags live in CMD so `docker compose run` can replace them while dumb-init still forwards
|
||||
# signals.
|
||||
ENTRYPOINT ["dumb-init", "--", "simplex-badge-service"]
|
||||
# Without --yes-migrate the service blocks on stdin at every schema change, and a container has no
|
||||
# console to answer.
|
||||
CMD ["-d", "postgresql://simplex@127.0.0.1:5432/badge_service", "--create-schema", "--yes-migrate", "--service-config", "/etc/simplex-badge-service/badge_service.ini"]
|
||||
@@ -0,0 +1,30 @@
|
||||
# The build context is the repository root. Exclude everything, then add back
|
||||
# what the image is built from, one directory level at a time.
|
||||
*
|
||||
|
||||
!cabal.project
|
||||
!simplex-chat.cabal
|
||||
!README.md
|
||||
!PRIVACY.md
|
||||
!src
|
||||
|
||||
!scripts
|
||||
scripts/*
|
||||
!scripts/cabal.project.local.linux
|
||||
|
||||
!apps
|
||||
apps/*
|
||||
!apps/simplex-badge-service
|
||||
|
||||
# Build output, caches, local state, and anything holding a secret. The ini is
|
||||
# mounted at run time and must never be baked into an image: it holds the issuer
|
||||
# secret, and with [btcpay] the API key and webhook secret too.
|
||||
badge_service.ini
|
||||
**/dist
|
||||
**/dist-newstyle
|
||||
**/node_modules
|
||||
**/*.db
|
||||
**/*.db-*
|
||||
apps/simplex-badge-service/test-fixtures
|
||||
apps/simplex-badge-service/web-traversal-test
|
||||
apps/simplex-badge-service/web/build
|
||||
@@ -0,0 +1,46 @@
|
||||
[listener]
|
||||
host = 0.0.0.0
|
||||
port = 8080
|
||||
; the built webapp in the image, read as the export source
|
||||
static_dir = /srv/web
|
||||
; split deployment: Caddy serves the exported folder; this service is the API and webhooks only.
|
||||
; Set to on for an all-in-one deployment where this service serves the webapp itself.
|
||||
serve_webapp = off
|
||||
; the webapp is written here at boot with the publishable key injected; compose bind-mounts it to a
|
||||
; host path Caddy serves. Unset it when serve_webapp = on.
|
||||
webapp_export_dir = /srv/webapp
|
||||
; on because Caddy proxies /api and /webhooks to this service; without it the rate limiter keys on
|
||||
; Caddy's address and shares one bucket across all callers
|
||||
trust_forwarded_for = on
|
||||
|
||||
[btcpay]
|
||||
host = https://btcpay.example.org
|
||||
api_key = replace-me
|
||||
store_id = replace-me
|
||||
webhook_secret = replace-me
|
||||
expiry_minutes = 60
|
||||
speed_policy = MediumSpeed
|
||||
payment_tolerance = 0.5
|
||||
|
||||
; optional; omit the whole [stripe] section to disable card payments
|
||||
[stripe]
|
||||
; restricted key (rk_): Payment Intents write + Charges read — never a full secret key (sk_)
|
||||
secret_key = rk_test_replace-me
|
||||
publishable_key = pk_test_replace-me
|
||||
; the signing secret of the /webhooks/stripe endpoint configured in the Dashboard
|
||||
webhook_secret = whsec_replace-me
|
||||
; minutes the service holds an unpaid card invoice open before it expires it; 1-1440
|
||||
session_minutes = 60
|
||||
|
||||
[poll]
|
||||
waiting_seconds = 3
|
||||
idle_seconds = 60
|
||||
|
||||
; index is the one clients verify against; private_key is from `simplex-chat badge keygen`.
|
||||
; To rotate, change both together, once clients trust the new index.
|
||||
[issuer]
|
||||
index = 1
|
||||
private_key = replace-me
|
||||
|
||||
[dev]
|
||||
chat_redeem = on
|
||||
@@ -0,0 +1,24 @@
|
||||
services:
|
||||
badge-service:
|
||||
image: simplex-badge-service:latest
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: scripts/badge-service/Dockerfile
|
||||
args:
|
||||
USER_UID: ${USER_UID:-1000}
|
||||
USER_GID: ${USER_GID:-1000}
|
||||
restart: on-failure:5
|
||||
user: "${USER_UID:-1000}:${USER_GID:-1000}"
|
||||
tty: true
|
||||
network_mode: host
|
||||
command:
|
||||
- "-d"
|
||||
- "${BADGE_DB_CONN:-postgresql://simplex@127.0.0.1:5432/badge_service}"
|
||||
- "--create-schema"
|
||||
- "--yes-migrate"
|
||||
- "--service-config"
|
||||
- "/etc/simplex-badge-service/badge_service.ini"
|
||||
volumes:
|
||||
- ./badge_service.ini:/etc/simplex-badge-service/badge_service.ini:ro
|
||||
- ./web:/srv/webapp
|
||||
stop_grace_period: 10s
|
||||
Reference in New Issue
Block a user