After the build ended the module pushes the packed bundle with mesh-sdk's PushBlob under <module>/<artifact> by its digest, a candidate's as a trunk build's, and the step answers artifact-store://<module>/<artifact>/blobs/<digest> instead of the archive's path. A push that fails fails the step not stored: <artifact>: <the store's words>; the packed bytes are never written to the node. The manifest requires artifact-store and places its address.
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package main
|
|
|
|
// The push of a done build's archive (novox/hq ADR 0498 §1 §2; issue 1587): from this module's own process, after the
|
|
// build step ended, with mesh-sdk's one client (buildstep.PushBlob), to the artifact store whose address the manifest
|
|
// binds into RegistryFile. No build step reaches the store: a run step has no network (ADR 0448).
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/buildstep"
|
|
)
|
|
|
|
// registry is the artifact store's address, host:port, as the manifest bound it into RegistryFile.
|
|
func (m *Module) registry() (string, error) {
|
|
raw, err := os.ReadFile(m.RegistryFile)
|
|
if err != nil {
|
|
return "", fmt.Errorf("the artifact store's address cannot be read: %w", err)
|
|
}
|
|
addr := strings.TrimSpace(string(raw))
|
|
if addr == "" || strings.Contains(addr, "${") || strings.HasPrefix(addr, ":") || strings.HasSuffix(addr, ":") {
|
|
return "", fmt.Errorf("the artifact store's address in %s is %q, not host:port", m.RegistryFile, addr)
|
|
}
|
|
return addr, nil
|
|
}
|
|
|
|
// push puts body into the artifact store as a blob of repository (<module>/<artifact>) by its digest: Push when a test
|
|
// set it, else buildstep.PushBlob.
|
|
func (m *Module) push(ctx context.Context, repository, digest string, body []byte) error {
|
|
addr, err := m.registry()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if m.Push != nil {
|
|
return m.Push(ctx, addr, repository, digest, body)
|
|
}
|
|
return buildstep.PushBlob(ctx, &http.Client{Timeout: 10 * time.Minute}, addr, repository, digest, body)
|
|
}
|