A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
feat(rexctl): ship a plain compose bundle with each release (#3578)
Hampusbda7bee05147
diff --git a/.github/workflows/release-image-set.yaml b/.github/workflows/release-image-set.yamlindex ed5cf33a4..048a0feaf 100644--- a/.github/workflows/release-image-set.yaml+++ b/.github/workflows/release-image-set.yaml@@ -294,6 +294,15 @@ jobs:mkdir -p ../releasecp rexctl_"${VERSION}"_* checksums.txt checksums.txt.sigstore.json rexctl-release.json ../release/+ - name: write the compose bundle+ working-directory: fluxer_rexctl+ run: |+ set -euo pipefail+ out="${RUNNER_TEMP}/fluxer-compose"+ go run . bundle --out "${out}"+ tar -czf "release/fluxer-compose-${VERSION}.tar.gz" -C "${out}" .+ tar -tzf "release/fluxer-compose-${VERSION}.tar.gz"+- uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6with:subject-checksums: fluxer_rexctl/dist/checksums.txtdiff --git a/fluxer_docs/astro.config.ts b/fluxer_docs/astro.config.tsindex 67a322c76..706df7aac 100644--- a/fluxer_docs/astro.config.ts+++ b/fluxer_docs/astro.config.ts@@ -167,6 +167,7 @@ export default defineConfig({'operator/reverse-proxy','operator/sign-in','operator/kubernetes',+ 'operator/docker-compose','operator/rexctl',],},diff --git a/fluxer_docs/src/content/docs/operator/docker-compose.mdx b/fluxer_docs/src/content/docs/operator/docker-compose.mdxnew file mode 100644index 000000000..33d9bda2a--- /dev/null+++ b/fluxer_docs/src/content/docs/operator/docker-compose.mdx@@ -0,0 +1,69 @@+---+# SPDX-License-Identifier: AGPL-3.0-or-later+title: Run Fluxer with Docker Compose+description: Run Fluxer from plain compose files on a platform that can't run rexctl.+sidebar:+ label: Docker Compose+---++Use this page if your platform runs compose stacks for you, such as Portainer, TrueNAS or Unraid, and you can't run rexctl on the machine. When you can run rexctl, [install with rexctl](/operator/) instead, because it does all of this for you.++## Get the files++Every release comes with a compose bundle. Download the latest one into an empty folder and unpack it.++```sh+curl -fsSL https://fluxer.dev/compose/latest -o fluxer-compose.tar.gz+tar -xzf fluxer-compose.tar.gz+cp .env.example .env+```++The bundle has `docker-compose.yml` with every Fluxer image pinned to the release, the `Caddyfile`, a few optional compose files and `.env.example`. The bundle for each version is also on its release on [GitHub](https://github.com/fluxerapp/fluxer/releases).++## Fill in .env++Set `FLUXER_DOMAIN` to your instance's domain, such as `chat.example.com`. Then run these commands in the folder to fill in the secrets.++```sh+for key in POSTGRES_PASSWORD MEILI_MASTER_KEY FLUXER_S3_SECRET_KEY FLUXER_SUDO_MODE_SECRET \+ FLUXER_CONNECTION_INITIATION_SECRET FLUXER_PROFILE_PSEUDONYM_SECRET FLUXER_GATEWAY_RPC_AUTH_TOKEN \+ FLUXER_ERLANG_COOKIE FLUXER_MEDIA_PROXY_SECRET_KEY FLUXER_ADMIN_SECRET_KEY_BASE \+ FLUXER_ADMIN_OAUTH_CLIENT_SECRET LIVEKIT_API_SECRET; do+ sed -i "s|^$key=.*|$key=$(openssl rand -hex 32)|" .env+done+sed -i "s|^FLUXER_SETUP_TOKEN=.*|FLUXER_SETUP_TOKEN=$(openssl rand -hex 16)|" .env+sed -i "s|^FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SECRET_BASE64=.*|FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SECRET_BASE64=$(openssl rand -base64 32)|" .env+openssl ecparam -name prime256v1 -genkey -noout -out vapid.pem+sed -i "s|^FLUXER_VAPID_PUBLIC_KEY=.*|FLUXER_VAPID_PUBLIC_KEY=$(openssl ec -in vapid.pem -pubout -outform DER 2>/dev/null | tail -c 65 | base64 | tr '/+' '_-' | tr -d '=\n')|" .env+sed -i "s|^FLUXER_VAPID_PRIVATE_KEY=.*|FLUXER_VAPID_PRIVATE_KEY=$(openssl ec -in vapid.pem -outform DER 2>/dev/null | tail -c +8 | head -c 32 | base64 | tr '/+' '_-' | tr -d '=\n')|" .env+rm vapid.pem+```++Keep a copy of `.env` somewhere safe. The database, search, storage, voice and push keys can't change once Fluxer has started, because your data depends on them. If your platform asks for environment values instead of a `.env` file, paste the lines from `.env` there.++## Start it++Open TCP ports 80, 443 and 7881 and UDP ports 443 and 7882, the same as for a [rexctl install](/operator/). Then start Fluxer.++```sh+docker compose up -d+```++Fluxer serves your domain over HTTPS and gets its own certificate. If another web server already uses ports 80 and 443, add these two lines to `.env` before you start, and point your proxy at `127.0.0.1:8080` as described in [Put Fluxer behind your own proxy](/operator/reverse-proxy/).++```sh+COMPOSE_FILE=docker-compose.yml:docker-compose.proxy.yml+FLUXER_EDGE_BIND=127.0.0.1:8080+```++When every service is healthy, open your domain in a browser and enter the `FLUXER_SETUP_TOKEN` from `.env` to create your admin account.++## Upgrade++Download the new bundle into the same folder and unpack it, which replaces every file except `.env`. If the new `.env.example` has a key your `.env` doesn't have yet, add it, then run `docker compose up -d`.++Back up the Docker volumes yourself before you upgrade, because `rexctl backup` isn't available without rexctl.++## Switch to rexctl later++If you can run rexctl on the machine later, `rexctl takeover --dir <folder>` hands this instance to rexctl with its data and secrets as they are.diff --git a/fluxer_docs/src/content/docs/operator/running.mdx b/fluxer_docs/src/content/docs/operator/running.mdxindex c4f33ad23..a92ff59da 100644--- a/fluxer_docs/src/content/docs/operator/running.mdx+++ b/fluxer_docs/src/content/docs/operator/running.mdx@@ -16,6 +16,12 @@ This upgrades rexctl and Fluxer together. It backs up your instance before FluxeTo see whether there's a new version without upgrading, run `rexctl upgrade --check`.+If you installed Fluxer before rexctl existed, upgrade it with the current install script. It installs rexctl and hands your instance to it with your data and settings as they are.++```sh+curl -fsSL https://fluxer.dev/install.sh | sh -s -- --update --dir /path/to/your/instance+```+## Roll back```shdiff --git a/fluxer_docs/src/installer/RexctlRelease.ts b/fluxer_docs/src/installer/RexctlRelease.tsindex 5cccb0787..6f222f5dc 100644--- a/fluxer_docs/src/installer/RexctlRelease.ts+++ b/fluxer_docs/src/installer/RexctlRelease.ts@@ -6,6 +6,7 @@ const RELEASES_API = 'https://api.github.com/repos/fluxerapp/fluxer/releases';const TAG_PREFIX = 'fluxer-release@';const METADATA_ASSET = 'rexctl-release.json';const CHECKSUMS_ASSET = 'checksums.txt';+const COMPOSE_ASSET_PREFIX = 'fluxer-compose-';const CACHE_MS = 5 * 60 * 1000;const RETRY_MS = 30 * 1000;const FETCH_TIMEOUT_MS = 15 * 1000;@@ -41,6 +42,7 @@ export interface RexctlRelease {readonly min_docker: string;readonly state_schema: number;readonly assets: ReadonlyArray<RexctlAsset>;+ readonly compose_url: string;}interface GitHubAsset {@@ -203,6 +205,7 @@ async function toRexctlRelease(release: GitHubRelease, version: string): Promisemin_docker: minDocker,state_schema: stateSchema,assets,+ compose_url: byName.get(`${COMPOSE_ASSET_PREFIX}${version}.tar.gz`)?.browser_download_url ?? '',};}diff --git a/fluxer_docs/src/pages/compose/latest.ts b/fluxer_docs/src/pages/compose/latest.tsnew file mode 100644index 000000000..0bab34997--- /dev/null+++ b/fluxer_docs/src/pages/compose/latest.ts@@ -0,0 +1,29 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++import type {APIRoute} from 'astro';+import {resolveRexctlRelease} from '@/installer/RexctlRelease';++export const prerender = false;++function errorReply(status: number, error: string): Response {+ return new Response(`${JSON.stringify({error})}\n`, {+ status,+ headers: {'cache-control': 'no-store', 'content-type': 'application/json; charset=utf-8'},+ });+}++export const GET: APIRoute = async () => {+ let release: Awaited<ReturnType<typeof resolveRexctlRelease>>;+ try {+ release = await resolveRexctlRelease(null);+ } catch {+ return errorReply(503, 'release list unavailable');+ }+ if (!release?.compose_url) {+ return errorReply(404, 'no compose bundle yet');+ }+ return new Response(null, {+ status: 302,+ headers: {'cache-control': 'public, max-age=60', location: release.compose_url},+ });+};diff --git a/fluxer_rexctl/cmd/bundle.go b/fluxer_rexctl/cmd/bundle.gonew file mode 100644index 000000000..93f425625--- /dev/null+++ b/fluxer_rexctl/cmd/bundle.go@@ -0,0 +1,63 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++package cmd++import (+ "fmt"+ "os"+ "path/filepath"+ "strings"++ "github.com/spf13/cobra"++ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/instance"+ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/secrets"+ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/stack"+ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/ui"+)++func newBundleCmd(app *App) *cobra.Command {+ var out string+ c := &cobra.Command{+ Use: "bundle",+ Short: "Write the compose files for running Fluxer without rexctl",+ Hidden: true,+ Args: noArgs,+ RunE: func(c *cobra.Command, _ []string) error {+ if out == "" {+ return ui.Refused("Pass --out with the folder to write to.", "")+ }+ images, err := stack.EmbeddedImages()+ if err != nil {+ return err+ }+ if len(images.Images) == 0 {+ return ui.Refused("This rexctl has no image set, so it can't pin Fluxer's images.", "Use a released rexctl.")+ }+ if err := stack.Bundle(out, images.Images); err != nil {+ return ui.Wrap(err, fmt.Sprintf("Couldn't write the files to %s.", out), "Check that you can write to that folder.")+ }+ if err := os.WriteFile(filepath.Join(out, ".env.example"), []byte(bundleEnv()), 0o644); err != nil {+ return ui.Wrap(err, fmt.Sprintf("Couldn't write the files to %s.", out), "Check that you can write to that folder.")+ }+ return nil+ },+ }+ c.Flags().StringVar(&out, "out", "", "folder to write")+ return c+}++func bundleEnv() string {+ var b strings.Builder+ fmt.Fprintf(&b, "%s=true\n", stack.SettingsLoadedVar)+ b.WriteString("FLUXER_DOMAIN=\n")+ fmt.Fprintf(&b, "%s=\n", instance.SetupTokenVar)+ for _, s := range secrets.Required {+ value := ""+ if s.Kind == secrets.KindFixed {+ value = s.Fixed+ }+ fmt.Fprintf(&b, "%s=%s\n", s.Key, value)+ }+ return b.String()+}diff --git a/fluxer_rexctl/cmd/root.go b/fluxer_rexctl/cmd/root.goindex e301b40fa..9f2a56587 100644--- a/fluxer_rexctl/cmd/root.go+++ b/fluxer_rexctl/cmd/root.go@@ -126,6 +126,7 @@ func newRoot(app *App) *cobra.Command {newConfigCmd(app),newVersionCmd(app),newDocsCmd(app),+ newBundleCmd(app),)groupCommands(root)refuseUnknownSubcommands(root)diff --git a/fluxer_rexctl/internal/instance/values.go b/fluxer_rexctl/internal/instance/values.goindex 3c4f8cad5..6274d8612 100644--- a/fluxer_rexctl/internal/instance/values.go+++ b/fluxer_rexctl/internal/instance/values.go@@ -50,7 +50,7 @@ func importValues(in valueInput) (*valueResult, error) {admin: map[string]string{},}for k := range env {- if strings.HasPrefix(k, "COMPOSE_") {+ if strings.HasPrefix(k, "COMPOSE_") || k == stack.SettingsLoadedVar {delete(env, k)}}@@ -166,7 +166,7 @@ func preserve(set *stack.Set, r *valueResult, before map[string]string, read []s}changed := falsefor _, v := range read {- if named[v] || isGeneratedSecret(v) || settings.Twins[v] != "" || isProxyVar(v) {+ if named[v] || v == stack.SettingsLoadedVar || isGeneratedSecret(v) || settings.Twins[v] != "" || isProxyVar(v) {continue}b, a := before[v], after[v]diff --git a/fluxer_rexctl/internal/stack/bundle.go b/fluxer_rexctl/internal/stack/bundle.gonew file mode 100644index 000000000..061dcbfbe--- /dev/null+++ b/fluxer_rexctl/internal/stack/bundle.go@@ -0,0 +1,36 @@+// SPDX-License-Identifier: AGPL-3.0-or-later++package stack++import (+ "os"+ "path/filepath"+)++const BundleProject = "fluxer"++func Bundle(dir string, images map[string]string) error {+ set := Embedded()+ files, _, err := renderFiles(set, nil, images, BundleProject)+ if err != nil {+ return err+ }+ for _, o := range overlayOrder {+ data, err := ReadFile(set, OverlayFiles[o])+ if err != nil {+ return err+ }+ files = append(files, renderedFile{OverlayFiles[o], data})+ }+ for _, d := range MountedDirs {+ if err := os.MkdirAll(filepath.Join(dir, d), 0o755); err != nil {+ return err+ }+ }+ for _, f := range files {+ if err := os.WriteFile(filepath.Join(dir, f.name), f.data, 0o644); err != nil {+ return err+ }+ }+ return nil+}