Skip to content

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

TypeScript fluxerfluxerapp

fix(rexctl): pin voice images only when their tag matches (#3888)

Hampus244d0d3b5152
diff --git a/fluxer_rexctl/internal/stack/images.go b/fluxer_rexctl/internal/stack/images.go
index 74142e79e..190e7886a 100644
--- a/fluxer_rexctl/internal/stack/images.go
+++ b/fluxer_rexctl/internal/stack/images.go
@@ -24,7 +24,6 @@ type ImageSet struct {
Release string `json:"release"`
Images map[string]string `json:"images"`
Builds map[string]string `json:"builds,omitempty"`
- Tags map[string]string `json:"tags,omitempty"`
Layers map[string]Layer `json:"layers,omitempty"`
Platforms map[string]map[string][]string `json:"platforms,omitempty"`
}
@@ -185,7 +184,14 @@ func pinImages(compose []byte, release string, images map[string]string) ([]byte
case !pinned:
continue
default:
- if name, _, ok := defaultedVar(img.value); ok {
+ name, def, ok := defaultedVar(img.value)
+ if !ok {
+ def = img.value
+ }
+ if withoutDigest(ref) != withoutDigest(def) {
+ continue
+ }
+ if ok {
value = "${" + name + ":-" + ref + "}"
} else {
value = ref
@@ -265,6 +271,11 @@ func RegistryServices() map[string]bool {
return out
}
+func withoutDigest(ref string) string {
+ name, _, _ := strings.Cut(ref, "@")
+ return name
+}
+
func digestPinned(ref string) bool {
_, digest, ok := strings.Cut(ref, "@sha256:")
if !ok || len(digest) != 64 {
diff --git a/fluxer_rexctl/internal/stack/layersizes/main.go b/fluxer_rexctl/internal/stack/layersizes/main.go
index b9aa3f098..aaa74c01b 100644
--- a/fluxer_rexctl/internal/stack/layersizes/main.go
+++ b/fluxer_rexctl/internal/stack/layersizes/main.go
@@ -12,6 +12,7 @@ import (
"flag"
"fmt"
"io"
+ "io/fs"
"maps"
"net/http"
"net/url"
@@ -86,7 +87,7 @@ func run(ctx context.Context, setPath, cachePath string, pin bool) error {
if err := json.Unmarshal(data, &set); err != nil {
return err
}
- third, err := thirdParty()
+ third, err := thirdParty(stack.Embedded())
if err != nil {
return err
}
@@ -115,7 +116,6 @@ func run(ctx context.Context, setPath, cachePath string, pin bool) error {
}
}
- set.Tags = map[string]string{}
set.Layers = map[string]stack.Layer{}
set.Platforms = map[string]map[string][]string{}
var todo []blob
@@ -125,13 +125,10 @@ func run(ctx context.Context, setPath, cachePath string, pin bool) error {
if err != nil {
return err
}
- top, topDigest, err := c.manifest(ctx, r, r.ref)
+ top, _, err := c.manifest(ctx, r, r.ref)
if err != nil {
return fmt.Errorf("%s: %w", ref, err)
}
- if !strings.Contains(ref, "@") {
- set.Tags[ref] = topDigest
- }
for _, p := range platforms {
m, err := c.platformManifest(ctx, r, top, p)
if err != nil {
@@ -200,20 +197,31 @@ func run(ctx context.Context, setPath, cachePath string, pin bool) error {
return writeJSON(setPath, set)
}
-func thirdParty() (map[string]string, error) {
- compose, err := stack.ReadFile(stack.Embedded(), stack.ComposeFile)
+func thirdParty(set *stack.Set) (map[string]string, error) {
+ files := []string{stack.ComposeFile}
+ voice, err := fs.Glob(set.Files, "voice/*.compose.yml")
if err != nil {
return nil, err
}
+ files = append(files, voice...)
out := map[string]string{}
- for svc, value := range stack.ComposeImages(compose) {
- if strings.HasPrefix(value, "${FLUXER_REGISTRY") {
- continue
+ for _, name := range files {
+ compose, err := stack.ReadFile(set, name)
+ if err != nil {
+ return nil, err
}
- if def, ok := stack.ImageDefault(value); ok {
- value = def
+ for svc, value := range stack.ComposeImages(compose) {
+ if strings.HasPrefix(value, "${FLUXER_REGISTRY") {
+ continue
+ }
+ if def, ok := stack.ImageDefault(value); ok {
+ value = def
+ }
+ if seen, ok := out[svc]; ok && seen != value {
+ return nil, fmt.Errorf("%s runs %s in one compose file and %s in another, so it can't have one pinned image", svc, seen, value)
+ }
+ out[svc] = value
}
- out[svc] = value
}
return out, nil
}
diff --git a/fluxer_rexctl/internal/stack/layersizes/thirdparty_test.go b/fluxer_rexctl/internal/stack/layersizes/thirdparty_test.go
new file mode 100644
index 000000000..e9f1e9fbb
--- /dev/null
+++ b/fluxer_rexctl/internal/stack/layersizes/thirdparty_test.go
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+package main
+
+import (
+ "strings"
+ "testing"
+ "testing/fstest"
+
+ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/stack"
+)
+
+func composeSet(main, voice string) *stack.Set {
+ return &stack.Set{Files: fstest.MapFS{
+ stack.ComposeFile: {Data: []byte(main)},
+ "voice/voice-edge.compose.yml": {Data: []byte(voice)},
+ }}
+}
+
+func TestThirdPartyIncludesVoiceComposeImages(t *testing.T) {
+ got, err := thirdParty(composeSet(
+ "services:\n edge:\n image: ${FLUXER_CADDY_IMAGE:-caddy:2.11-alpine}\n",
+ "services:\n edge:\n image: ${FLUXER_CADDY_IMAGE:-caddy:2.11-alpine}\n turn:\n image: coturn/coturn:4.7\n",
+ ))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got["edge"] != "caddy:2.11-alpine" || got["turn"] != "coturn/coturn:4.7" {
+ t.Fatalf("thirdParty() = %v", got)
+ }
+ if _, err := thirdParty(stack.Embedded()); err != nil {
+ t.Fatalf("the shipped compose files: %v", err)
+ }
+}
+
+func TestThirdPartyRefusesAServiceWithTwoImages(t *testing.T) {
+ _, err := thirdParty(composeSet(
+ "services:\n edge:\n image: ${FLUXER_CADDY_IMAGE:-caddy:2.11-alpine}\n",
+ "services:\n edge:\n image: ${FLUXER_CADDY_IMAGE:-caddy:2.12-alpine}\n",
+ ))
+ if err == nil || !strings.Contains(err.Error(), "edge") {
+ t.Fatalf("thirdParty() error = %v", err)
+ }
+}
diff --git a/fluxer_rexctl/internal/stack/thirdparty_pin_test.go b/fluxer_rexctl/internal/stack/thirdparty_pin_test.go
index ed2bc7ed0..8300de25f 100644
--- a/fluxer_rexctl/internal/stack/thirdparty_pin_test.go
+++ b/fluxer_rexctl/internal/stack/thirdparty_pin_test.go
@@ -82,3 +82,15 @@ func TestRegistryServicesLeavesOutThirdPartyImages(t *testing.T) {
t.Fatalf("RegistryServices() = %v", got)
}
}
+
+func TestPinImagesLeavesAnImageWhosePinIsForAnotherTag(t *testing.T) {
+ shipped, images := pinnedSet(t)
+ images["postgres"] = "postgres:17-alpine@sha256:" + strings.Repeat("cd", 32)
+ got, err := pinImages(shipped, "test", images)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if pinned := ComposeImages(got)["postgres"]; pinned != "${FLUXER_POSTGRES_IMAGE:-postgres:16-alpine}" {
+ t.Fatalf("postgres image = %q", pinned)
+ }
+}