Point the builder's package binding at the port given with --packages-port (hq ADR 0100)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -53,6 +55,9 @@ func InstallBuilder(ctx context.Context, o Options, d Deps, control controlPlane
|
||||
"This is the manifest that makes the builder an ordinary module. Without it the mesh "+
|
||||
"has the image and no way to run it, so nothing can be built here", err)
|
||||
}
|
||||
if manifest, err = followPackagesPort(manifest, o.Ports.orDefaults().Packages); err != nil {
|
||||
return out, err
|
||||
}
|
||||
pinned, places, err := pinPlaceholder(manifest, published.Reference, BuilderModule)
|
||||
if err != nil {
|
||||
return out, err
|
||||
@@ -84,3 +89,25 @@ func InstallBuilder(ctx context.Context, o Options, d Deps, control controlPlane
|
||||
out.Installed.Pushed, err = pushNode(ctx, o, control, say)
|
||||
return out, err
|
||||
}
|
||||
|
||||
// packagesPortInBinding is the package registry's port as the builder's manifest names it, in the
|
||||
// binding file it carries — JSON inside a JSON string, so its quotes are escaped.
|
||||
const packagesPortInBinding = `\"port\": 3000`
|
||||
|
||||
// followPackagesPort points the builder's package binding at the port the node gave the package
|
||||
// registry (novox/hq ADR 0100). Genesis raises the registry by hand before gitea is a module, so no
|
||||
// binding the controller resolves can say where it is; the builder carries the address in its own
|
||||
// manifest, and a port given at genesis must reach it there or the base build dials a port nothing
|
||||
// answers on. At the default it is left byte for byte as the catalogue has it.
|
||||
func followPackagesPort(manifest []byte, port int) ([]byte, error) {
|
||||
if port == defaultGiteaPort {
|
||||
return manifest, nil
|
||||
}
|
||||
if n := bytes.Count(manifest, []byte(packagesPortInBinding)); n != 1 {
|
||||
return nil, fmt.Errorf("the builder's manifest names the package registry's port %d time(s) where "+
|
||||
"this installer looks for it once (%s), so the port given with --packages-port cannot reach "+
|
||||
"it; nothing was changed", n, packagesPortInBinding)
|
||||
}
|
||||
return bytes.Replace(manifest, []byte(packagesPortInBinding),
|
||||
[]byte(`\"port\": `+strconv.Itoa(port)), 1), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user