ScaleTail icon indicating copy to clipboard operation
ScaleTail copied to clipboard

πŸ—οΈ New Service: OpenGym

Open GuillermoFidalgo opened this issue 2 months ago β€’ 0 comments

Service Description

I would like to see OpenGym added to ScaleTail. I got it to work on my raspberrypi. Sadly I wasnΒ΄t savyy enough to get it to work simply with a compose.yaml file, it requires to clone the OpenGym repo and then edit the compose and env files accordingly. Hopefully this isnΒ΄t a big deal. Below I post a sample .env file that worked with the network_mode : service:tailscale option

# Copy this file to ".env" and adjust for your setup, then: docker compose up -d
#
# ── Local testing (default) ────────────────────────────────────────────────
# Works out of the box on the machine running Docker. Open http://localhost:8080
# RP_ID=localhost
# ORIGIN=http://localhost:8080
# WEB_PORT=8080
# RP_NAME=openGym

SERVICE=openGym
TS_AUTHKEY=


# ── Real deployment behind your own HTTPS domain ───────────────────────────
# Passkeys are bound to the exact hostname, and browsers only allow them over
# HTTPS (localhost is the one exception). Put openGym behind a reverse proxy /
# tunnel that terminates TLS for your domain, then set:
#
RP_ID=opengym.<tailnetdomian>.ts.net
ORIGIN=https://opengym.<tailnetdomain>.ts.net
WEB_PORT=8080
RP_NAME=openGym
#
# (Point your proxy at the web container's WEB_PORT. See docs/SELF_HOSTING.md.)

# ── Admin dashboard & invite-only signup (optional) ────────────────────────
# Both off by default β€” a fresh instance has open signup and no admin.
#
# Make yourself an admin: register your own passkey profile first, find your
# user id in ./data/db.json ("users"[].id), then list it here (comma-separated
# for several admins). Admins get an "Admin dashboard" link in Settings to see
# users, disable accounts, generate invite codes and view workout history.
#
#   ADMIN_UIDS=youruserid,anotheradmin
#
# Require an invite code to create new profiles (existing accounts keep working;
# generate the codes from the admin dashboard):
#
#   INVITE_ONLY=1
#
# Remove the "Continue without account" button, so a profile is the only way in.
# Guest mode keeps everything in the browser and never touches this server, but
# on an instance meant for a known set of people it is still the wrong front
# door. Anyone already inside as a guest is signed out on their next visit; the
# data they made stays in that browser. Defaults to on (guests allowed):
#
#   ALLOW_GUEST=0

# ── Activity log (optional) ────────────────────────────────────────────────
# The admin dashboard shows an activity log: who signed in, who tried and
# failed, and every admin action (disabling an account, creating or revoking an
# invite code). It lives in ./data/audit.log, one JSON object per line, so you
# can also just read it with `tail` or `jq`.
#
# It is ON by default. It records strictly less than this instance already
# holds β€” every profile is in db.json and every workout is in state-<uid>.json,
# both readable by any admin β€” and a log that ships switched off tells you
# nothing on the day you need it. Turn it off completely with:
#
#   AUDIT_LOG=0
#
# Retention is a cap, not an archive. Whichever limit is reached first wins;
# set either to 0 to disable that limit:
#
#   AUDIT_MAX=5000            # events kept
#   AUDIT_DAYS=90             # days kept
#
# IP addresses are the one thing that is OFF unless you ask, because they are
# the only field here that says where somebody physically is. They are also the
# only way to tell one failed sign-in from twenty. Three settings:
#
#   AUDIT_IP=off              # default β€” no addresses at all
#   AUDIT_IP=net              # network only: 203.0.113.0/24, 2001:db8:1::/48
#   AUDIT_IP=full             # the whole address
#
# The address is read from CF-Connecting-IP, then the first entry of
# X-Forwarded-For, then X-Real-IP, and finally the connecting socket itself if
# none of those is present.
#
# A forwarded-for header is only worth anything if whatever sits in front
# OVERWRITES it instead of passing a client-supplied one through β€” otherwise a
# caller simply states the address it would like logged. The web container now
# overwrites X-Forwarded-For and X-Real-IP with the real peer, and DROPS
# CF-Connecting-IP, so the bundled stack records an address nobody can choose.
# (Before, X-Forwarded-For was appended to rather than replaced, and
# CF-Connecting-IP was passed straight through β€” both were forgeable.)
#
# Cloudflare is first in that list on purpose: a Cloudflare tunnel does not put
# the visitor in X-Forwarded-For at all, so that header would otherwise record
# the tunnel itself and look perfectly plausible. If β€” and only if β€” Cloudflare
# is genuinely in front of you, let its header through again:
#
#   CF_CONNECTING_IP=$http_cf_connecting_ip
#
# That is safe there because Cloudflare sets the header itself, replacing
# anything the client sent. Anywhere else, leave it unset.

# ── Session length (optional) ──────────────────────────────────────────────
# How long a sign-in lasts, in days. Default 90 β€” long enough that people who
# train regularly never see a login screen, short enough that a stolen cookie
# doesn't stay good forever. Lower it for an instance on the open internet,
# raise it for a private one. Only affects new sign-ins; cookies already handed
# out keep the lifetime they were issued with. Users can end every session on
# every device themselves with "Sign out everywhere" in Settings.
#
#   SESSION_DAYS=90

# ── Fitting into an existing stack (optional) ──────────────────────────────
# The defaults assume openGym is on its own: an API service called `api` on
# port 3000, and nginx listening on 80 inside the web container. If you are
# merging this into a compose file that already has an `api`, or you front the
# web container with your own reverse proxy, move them here. The web image
# renders its nginx config at start-up, so these apply to a prebuilt image and
# need no rebuild. BACKEND and PORT together are what /api is proxied to, so
# they must name a service the web container can reach on your network:
#
#   NGINX_PORT=80
BACKEND=127.0.0.1
#   PORT=3000

# ── Notifications (optional) ───────────────────────────────────────────────
# Push works out of the box β€” nothing to set. VAPID keys are generated on first
# run and saved to ./data/vapid.json. Each user's browser reports its own
# timezone automatically, so the workout-day reminder fires at their local
# time regardless of where the server runs or where they're travelling.
#
# Push services want a contact address for whoever operates the server, in case
# they need to get in touch about your pushes. Defaults to your ORIGIN, which is
# fine; set a mailto: if you would rather they mailed you:
#
#   VAPID_SUBJECT=mailto:[email protected]

Docker Compose File Link

https://gitlab.com/DuarteSantos8/opengym

Docker Compose Configuration

name: opengym

configs:
  ts-serve:
    content: |
      {"TCP":{"443":{"HTTPS":true}},
      "Web":{"$${TS_CERT_DOMAIN}:443":
          {"Handlers":{"/":
          {"Proxy":"http://127.0.0.1:80"}}}},
      "AllowFunnel":{"$${TS_CERT_DOMAIN}:443":false}}

services:
  # One-time: download the exercise images + GIFs into ./media (skipped if already there).
  # ~140 MB, from github.com/hasaneyldrm/exercises-dataset. That dataset is MIT for the
  # metadata and instruction text, but the images and GIFs are Β© Gym visual
  # (https://gymvisual.com/) and are used under the dataset's terms β€” openGym neither
  # redistributes nor relicenses them. See NOTICE.md.
  
    # Tailscale Sidecar Configuration
  tailscale:
    image: tailscale/tailscale:latest # Image to be used
    container_name: tailscale-${SERVICE} # Name for local container management
    hostname: ${SERVICE} # Name used within your Tailscale environment
    environment:
      - TS_AUTHKEY=${TS_AUTHKEY}
      - TS_STATE_DIR=/var/lib/tailscale
      - TS_SERVE_CONFIG=/config/serve.json # Tailscale Serve configuration to expose the web interface on your local Tailnet
      - TS_USERSPACE=false
      - TS_ENABLE_HEALTH_CHECK=true              # Enable healthcheck endpoint: "/healthz"
      - TS_LOCAL_ADDR_PORT=127.0.0.1:41234       # The <addr>:<port> for the healthz endpoint
      #- TS_ACCEPT_DNS=true # Uncomment when using MagicDNS
      - TS_AUTH_ONCE=true
    configs:
      - source: ts-serve
        target: /config/serve.json
    volumes:
      - ./config:/config # Config folder used to store Tailscale files - you may need to change the path
      - ./ts/state:/var/lib/tailscale # Tailscale requirement - you may need to change the path
    devices:
      - /dev/net/tun:/dev/net/tun # Network configuration for Tailscale to work
    cap_add:
      - net_admin # Tailscale requirement
    #ports:
    #  - 0.0.0.0:${SERVICEPORT}:${SERVICEPORT} # Binding port ${SERVICEPORT} to the local network - may be removed if only exposure to your Tailnet is required
    # If any DNS issues arise, use your preferred DNS provider by uncommenting the config below
    #dns:
    #  - ${DNS_SERVER}
    healthcheck:
      test: ["CMD", "wget", "--spider", "-q", "http://127.0.0.1:41234/healthz"] # Check Tailscale has a Tailnet IP and is operational
      interval: 1m # How often to perform the check
      timeout: 10s # Time to wait for the check to succeed
      retries: 3 # Number of retries before marking as unhealthy
      start_period: 10s # Time to wait before starting health checks
    restart: always

  media:
    image: alpine/git
    network_mode: service:tailscale
    volumes:
      - ./media/img:/out/img
      - ./media/gif:/out/gif
    entrypoint: ["/bin/sh", "-c"]
    command:
      - |
        if [ -z "$$(ls -A /out/img 2>/dev/null)" ]; then
          echo "↓ Downloading exercise media (~140 MB, one time)…"
          echo "  Source:  github.com/hasaneyldrm/exercises-dataset"
          echo "  Metadata and instruction text: MIT."
          echo "  Images and animations: Β© Gym visual β€” https://gymvisual.com/"
          echo "  They are used under that dataset's terms, not openGym's AGPL, and are"
          echo "  downloaded from upstream β€” openGym does not redistribute them."
          echo "  Terms: https://gymvisual.com/content/3-terms-and-conditions-of-use"
          echo "  Reusing this media yourself, commercially or not, needs your own licence"
          echo "  from Gym visual. Details in NOTICE.md."
          git clone --depth 1 https://github.com/hasaneyldrm/exercises-dataset /tmp/ds
          cp /tmp/ds/images/*.jpg /out/img/ && cp /tmp/ds/videos/*.gif /out/gif/
          echo "βœ“ Exercise media ready ($$(ls /out/img | wc -l) images)."
        else
          echo "βœ“ Exercise media already present β€” skipping download."
        fi
    restart: "no"

  # Passkey auth + per-user data (Node, no framework).
  # image: prebuilt (docker compose pull). build: from source (docker compose up --build).
  api:
    image: registry.gitlab.com/duartesantos8/opengym/api:latest
    build: ./api
    restart: unless-stopped
    env_file: .env
    network_mode: service:tailscale

    environment:
      # The port the API listens on. web proxies to this same value, so the two
      # cannot drift β€” change it in .env and both follow.
      - PORT=${PORT:-3000}
      - DATA_DIR=/data
    volumes:
      - ./data:/data         # users, passkeys, per-user state, session secret β€” BACK THIS UP

  # Builds the React frontend (multi-stage) and serves it, proxying /api β†’ api
  # and the exercise media from the shared volume. Single origin for passkeys.
  web:
    image: registry.gitlab.com/duartesantos8/opengym/web:latest
    build:
      context: .
      dockerfile: web/Dockerfile
    restart: unless-stopped
    network_mode: service:tailscale
    depends_on:
      tailscale:
        condition: service_healthy     
      media:
        condition: service_completed_successfully
      api:
        condition: service_started
    # ports:
    #   - "${WEB_PORT:-8080}:${NGINX_PORT:-80}"
    # nginx renders its config at start-up from these (web/nginx.conf.template),
    # so the API service does not have to be called `api`. Defaults are the old
    # hardcoded values, so an existing .env and an existing stack are unaffected.
    environment:
      - NGINX_PORT=${NGINX_PORT:-80}
      - BACKEND=${BACKEND:-api}
      - PORT=${PORT:-3000}
      # Empty drops the CF-Connecting-IP header, so a direct client cannot forge the address
      # the activity log records. Cloudflare users set CF_CONNECTING_IP=$$http_cf_connecting_ip.
      - CF_CONNECTING_IP=${CF_CONNECTING_IP:-}
    volumes:
      - ./media/img:/usr/share/nginx/html/img:ro
      - ./media/gif:/usr/share/nginx/html/gif:ro

Website of Service

https://opengym.duarte-santos.ch/

Would you be willing to work on this service?

  • [ ] Yes, I'd like to implement this feature
  • [x] I could help with parts of this feature
  • [ ] No, I'm just suggesting the feature

GuillermoFidalgo avatar Sep 05 '26 20:09 GuillermoFidalgo