Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(rexctl): recognise the compose bundle on takeover (#3590)

Hampus6f09051bcb52
diff --git a/fluxer_rexctl/cmd/bundle.go b/fluxer_rexctl/cmd/bundle.go
index 93f425625..74876b55f 100644
--- a/fluxer_rexctl/cmd/bundle.go
+++ b/fluxer_rexctl/cmd/bundle.go
@@ -6,12 +6,10 @@ 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"
)
@@ -37,7 +35,7 @@ func newBundleCmd(app *App) *cobra.Command {
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 {
+ if err := os.WriteFile(filepath.Join(out, ".env.example"), []byte(instance.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
@@ -46,18 +44,3 @@ func newBundleCmd(app *App) *cobra.Command {
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/internal/instance/adopt.go b/fluxer_rexctl/internal/instance/adopt.go
index 0a2c9ef98..b2efa55be 100644
--- a/fluxer_rexctl/internal/instance/adopt.go
+++ b/fluxer_rexctl/internal/instance/adopt.go
@@ -528,16 +528,23 @@ func overlayFor(path, dir string) string {
}
func isShipped(name string, data []byte) bool {
- sum := sha256.Sum256(normalizeLF(data))
+ data = normalizeLF(data)
+ if name == stack.ComposeFile {
+ data = stack.UnpinImages(data)
+ }
+ sum := sha256.Sum256(data)
h := hex.EncodeToString(sum[:])
if slices.Contains(shippedHashes[name], h) {
return true
}
+ if name == ".env.example" {
+ return string(data) == BundleEnv()
+ }
current, err := fs.ReadFile(stack.Embedded().Files, name)
if err != nil {
return false
}
- return bytes.Equal(normalizeLF(current), normalizeLF(data))
+ return bytes.Equal(normalizeLF(current), data)
}
func normalizeLF(data []byte) []byte {
diff --git a/fluxer_rexctl/internal/instance/values.go b/fluxer_rexctl/internal/instance/values.go
index 6274d8612..740e9f29d 100644
--- a/fluxer_rexctl/internal/instance/values.go
+++ b/fluxer_rexctl/internal/instance/values.go
@@ -3,6 +3,7 @@
package instance
import (
+ "fmt"
"maps"
"slices"
"strconv"
@@ -19,6 +20,21 @@ const SetupTokenVar = "FLUXER_SETUP_TOKEN"
var legacyImageVars = []string{"FLUXER_IMAGE_TAG", "FLUXER_REGISTRY", "FLUXER_REGISTRY_OWNER"}
+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", 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()
+}
+
type valueInput struct {
env map[string]string
set *stack.Set
diff --git a/fluxer_rexctl/internal/stack/images.go b/fluxer_rexctl/internal/stack/images.go
index 8dda23c0f..c09227a9c 100644
--- a/fluxer_rexctl/internal/stack/images.go
+++ b/fluxer_rexctl/internal/stack/images.go
@@ -127,6 +127,39 @@ func pinImages(compose []byte, release string, images map[string]string) ([]byte
return []byte(strings.Join(lines, "\n")), nil
}
+func UnpinImages(compose []byte) []byte {
+ shipped, err := ReadFile(Embedded(), ComposeFile)
+ if err != nil {
+ return compose
+ }
+ templates, err := imageLines(shipped)
+ if err != nil {
+ return compose
+ }
+ found, err := imageLines(compose)
+ if err != nil {
+ return compose
+ }
+ byService := make(map[string]string, len(templates))
+ for _, t := range templates {
+ if strings.HasPrefix(t.value, "${FLUXER_REGISTRY") {
+ byService[t.service] = t.value
+ }
+ }
+ lines := strings.Split(string(compose), "\n")
+ for _, img := range found {
+ template, ok := byService[img.service]
+ repo, digest, pinned := strings.Cut(img.value, "@sha256:")
+ component, _, _ := strings.Cut(template, ":${")
+ i := img.line - 1
+ if !ok || !pinned || len(digest) != 64 || path.Base(repo) != path.Base(component) || i < 0 || i >= len(lines) || img.column-1 > len(lines[i]) {
+ continue
+ }
+ lines[i] = lines[i][:img.column-1] + template
+ }
+ return []byte(strings.Join(lines, "\n"))
+}
+
func defaultedVar(value string) (name, def string, ok bool) {
inner, ok := strings.CutPrefix(value, "${")
if !ok {