Plan publication using source descriptors
This commit is contained in:
@@ -356,6 +356,10 @@ installed content are unchanged. No claim of asymptotically faster I/O.
|
|||||||
|
|
||||||
## Stage 10: Separate publication mapping from open source handles
|
## Stage 10: Separate publication mapping from open source handles
|
||||||
|
|
||||||
|
**Complete:** Publication mapping now records confined source descriptors and
|
||||||
|
expected checksums instead of retaining inventory-sized sets of open handles.
|
||||||
|
Transfer execution is migrated in the following stage.
|
||||||
|
|
||||||
Read `audit/05-resources.md`, lines 58–116 (RS-01), discussion topic 6, and
|
Read `audit/05-resources.md`, lines 58–116 (RS-01), discussion topic 6, and
|
||||||
publication's run/previous/output source planning and transfer construction.
|
publication's run/previous/output source planning and transfer construction.
|
||||||
|
|
||||||
|
|||||||
@@ -104,11 +104,6 @@ func (publishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
|||||||
runFiles = append(runFiles, file)
|
runFiles = append(runFiles, file)
|
||||||
}
|
}
|
||||||
sort.Slice(runFiles, func(i, j int) bool { return runFiles[i].RelativePath < runFiles[j].RelativePath })
|
sort.Slice(runFiles, func(i, j int) bool { return runFiles[i].RelativePath < runFiles[j].RelativePath })
|
||||||
runSources, err := openPublishRunFiles(runRoot, runFiles)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("publish: verify run files: %w", err)
|
|
||||||
}
|
|
||||||
defer closePublishSources(runSources)
|
|
||||||
uploader, ok := env.ObjectStore.(storage.ReaderUploader)
|
uploader, ok := env.ObjectStore.(storage.ReaderUploader)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("publish: object store does not support verified source uploads")
|
return nil, fmt.Errorf("publish: object store does not support verified source uploads")
|
||||||
@@ -117,11 +112,6 @@ func (publishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("publish: collect previous files: %w", err)
|
return nil, fmt.Errorf("publish: collect previous files: %w", err)
|
||||||
}
|
}
|
||||||
previousSources, err := openPublishRunFiles(sessionPaths.PreviousDir, previousFiles)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("publish: verify previous files: %w", err)
|
|
||||||
}
|
|
||||||
defer closePublishSources(previousSources)
|
|
||||||
runtimeCatalog, err := buildPublishRuntimeArtifactCatalog(
|
runtimeCatalog, err := buildPublishRuntimeArtifactCatalog(
|
||||||
sessionPaths,
|
sessionPaths,
|
||||||
m,
|
m,
|
||||||
@@ -169,7 +159,7 @@ func (publishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("publish: %w", err)
|
return nil, fmt.Errorf("publish: %w", err)
|
||||||
}
|
}
|
||||||
transfers, err := buildPublishTransferPlan(runPrefix, runFiles, runSources, previousFiles, previousSources, outputPlan)
|
transfers, err := buildPublishTransferPlan(runPrefix, runRoot, runFiles, sessionPaths.PreviousDir, previousFiles, sessionPaths.Root, outputPlan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("publish: build immutable upload mapping: %w", err)
|
return nil, fmt.Errorf("publish: build immutable upload mapping: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type discoveredPublishOutput struct {
|
|||||||
Source string
|
Source string
|
||||||
LocalPath string
|
LocalPath string
|
||||||
Provenance string
|
Provenance string
|
||||||
|
Checksum string
|
||||||
}
|
}
|
||||||
|
|
||||||
type publishOutputOutcome struct {
|
type publishOutputOutcome struct {
|
||||||
@@ -43,6 +44,7 @@ type publishOutputOutcome struct {
|
|||||||
Required bool
|
Required bool
|
||||||
LocalPath string
|
LocalPath string
|
||||||
Provenance string
|
Provenance string
|
||||||
|
Checksum string
|
||||||
Declaration artifacts.RemoteArtifact
|
Declaration artifacts.RemoteArtifact
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,6 +127,7 @@ func buildPublishOutputPlan(
|
|||||||
outcome.OriginRun = identity.RunID
|
outcome.OriginRun = identity.RunID
|
||||||
outcome.LocalPath = discoveredSource.LocalPath
|
outcome.LocalPath = discoveredSource.LocalPath
|
||||||
outcome.Provenance = discoveredSource.Provenance
|
outcome.Provenance = discoveredSource.Provenance
|
||||||
|
outcome.Checksum = discoveredSource.Checksum
|
||||||
outcome.Declaration = artifacts.RemoteArtifact{
|
outcome.Declaration = artifacts.RemoteArtifact{
|
||||||
Type: artifacts.RemoteArtifactTypePublishedOutput, Source: rule.Source, DestinationKey: declaredKey,
|
Type: artifacts.RemoteArtifactTypePublishedOutput, Source: rule.Source, DestinationKey: declaredKey,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func discoverPublishOutputs(
|
|||||||
return nil, fmt.Errorf("resolve source %q: %w", rule.Source, err)
|
return nil, fmt.Errorf("resolve source %q: %w", rule.Source, err)
|
||||||
}
|
}
|
||||||
out = append(out, discoveredPublishOutput{
|
out = append(out, discoveredPublishOutput{
|
||||||
Source: rule.Source, LocalPath: resolved.Path, Provenance: resolved.Provenance,
|
Source: rule.Source, LocalPath: resolved.Path, Provenance: resolved.Provenance, Checksum: resolved.Checksum,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
|
|||||||
@@ -246,24 +246,6 @@ func collectPublishPreviousFiles(ctx context.Context, previousDir string) ([]pub
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func openPublishRunFiles(runRoot string, files []publishUploadFile) ([]*os.File, error) {
|
|
||||||
sources := make([]*os.File, 0, len(files))
|
|
||||||
for _, candidate := range files {
|
|
||||||
file, err := openPublishSourceUnderRoot(runRoot, candidate.SourceRelativePath)
|
|
||||||
if err != nil {
|
|
||||||
closePublishSources(sources)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := verifyPublishSourceChecksum(file, candidate.RelativePath, candidate.Checksum); err != nil {
|
|
||||||
_ = file.Close()
|
|
||||||
closePublishSources(sources)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
sources = append(sources, file)
|
|
||||||
}
|
|
||||||
return sources, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func openPublishSourceUnderRoot(rootPath, relativePath string) (*os.File, error) {
|
func openPublishSourceUnderRoot(rootPath, relativePath string) (*os.File, error) {
|
||||||
relativePath, err := pathsafe.NormalizeRelativeDestination(relativePath)
|
relativePath, err := pathsafe.NormalizeRelativeDestination(relativePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -346,12 +328,6 @@ func verifyPublishSourceChecksum(file *os.File, relativePath, expected string) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func closePublishSources(sources []*os.File) {
|
|
||||||
for _, source := range sources {
|
|
||||||
_ = source.Close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func publishUploadPaths(files []publishUploadFile) []string {
|
func publishUploadPaths(files []publishUploadFile) []string {
|
||||||
paths := make([]string, 0, len(files))
|
paths := make([]string, 0, len(files))
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
|||||||
@@ -8,79 +8,59 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type publishTransfer struct {
|
type publishTransfer struct {
|
||||||
Artifact artifacts.RemoteArtifact
|
Artifact artifacts.RemoteArtifact
|
||||||
Source *os.File
|
SourceRoot string
|
||||||
|
SourcePath string
|
||||||
|
Checksum string
|
||||||
TemporaryPath string
|
TemporaryPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildPublishTransferPlan(
|
func buildPublishTransferPlan(
|
||||||
runPrefix string,
|
runPrefix, runRoot string,
|
||||||
runFiles []publishUploadFile,
|
runFiles []publishUploadFile,
|
||||||
runSources []*os.File,
|
previousRoot string,
|
||||||
previousFiles []publishUploadFile,
|
previousFiles []publishUploadFile,
|
||||||
previousSources []*os.File,
|
sessionRoot string,
|
||||||
outputPlan *publishOutputPlan,
|
outputPlan *publishOutputPlan,
|
||||||
) ([]publishTransfer, error) {
|
) ([]publishTransfer, error) {
|
||||||
if len(runFiles) != len(runSources) || len(previousFiles) != len(previousSources) {
|
|
||||||
return nil, fmt.Errorf("verified publish sources do not match their declared files")
|
|
||||||
}
|
|
||||||
if outputPlan == nil {
|
if outputPlan == nil {
|
||||||
return nil, fmt.Errorf("publish output plan is required")
|
return nil, fmt.Errorf("publish output plan is required")
|
||||||
}
|
}
|
||||||
transfers := make([]publishTransfer, 0, len(runFiles)+len(previousFiles)+len(outputPlan.Outcomes))
|
transfers := make([]publishTransfer, 0, len(runFiles)+len(previousFiles)+len(outputPlan.Outcomes))
|
||||||
add := func(artifact artifacts.RemoteArtifact, source *os.File) error {
|
for _, file := range runFiles {
|
||||||
if source == nil {
|
transfers = append(transfers, publishTransfer{
|
||||||
return fmt.Errorf("source for %q is required", artifact.DestinationKey)
|
Artifact: artifacts.RemoteArtifact{Type: artifacts.RemoteArtifactTypeRunFile, Source: "run:" + file.RelativePath, DestinationKey: artifacts.S3RunRelativeDestinationKey(runPrefix, file.RelativePath)},
|
||||||
}
|
SourceRoot: runRoot, SourcePath: file.SourceRelativePath, Checksum: file.Checksum,
|
||||||
transfers = append(transfers, publishTransfer{Artifact: artifact, Source: source})
|
})
|
||||||
return nil
|
|
||||||
}
|
|
||||||
for index, file := range runFiles {
|
|
||||||
if err := add(artifacts.RemoteArtifact{
|
|
||||||
Type: artifacts.RemoteArtifactTypeRunFile,
|
|
||||||
Source: "run:" + file.RelativePath,
|
|
||||||
DestinationKey: artifacts.S3RunRelativeDestinationKey(runPrefix, file.RelativePath),
|
|
||||||
}, runSources[index]); err != nil {
|
|
||||||
closePublishTransfers(transfers)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for index, file := range previousFiles {
|
|
||||||
if err := add(artifacts.RemoteArtifact{
|
|
||||||
Type: artifacts.RemoteArtifactTypePreviousArtifact,
|
|
||||||
Source: "previous:" + file.SourceRelativePath,
|
|
||||||
DestinationKey: artifacts.S3RunRelativeDestinationKey(runPrefix, file.RelativePath),
|
|
||||||
}, previousSources[index]); err != nil {
|
|
||||||
closePublishTransfers(transfers)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
for _, file := range previousFiles {
|
||||||
|
transfers = append(transfers, publishTransfer{
|
||||||
|
Artifact: artifacts.RemoteArtifact{Type: artifacts.RemoteArtifactTypePreviousArtifact, Source: "previous:" + file.SourceRelativePath, DestinationKey: artifacts.S3RunRelativeDestinationKey(runPrefix, file.RelativePath)},
|
||||||
|
SourceRoot: previousRoot, SourcePath: file.SourceRelativePath, Checksum: file.Checksum,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
for _, output := range outputPlan.Outcomes {
|
for _, output := range outputPlan.Outcomes {
|
||||||
if output.Status != publishOutputPublished {
|
if output.Status != publishOutputPublished {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
source, err := openPublishOutputSource(output.LocalPath)
|
relative, err := pathsafe.SlashRelativeFromRoot(sessionRoot, output.LocalPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
closePublishTransfers(transfers)
|
return nil, fmt.Errorf("output source %q: %w", output.Source, err)
|
||||||
return nil, fmt.Errorf("open output source %q: %w", output.Source, err)
|
|
||||||
}
|
|
||||||
if err := add(artifacts.RemoteArtifact{
|
|
||||||
Type: artifacts.RemoteArtifactTypePublishedOutput,
|
|
||||||
Source: output.Source,
|
|
||||||
DestinationKey: output.DeclaredKey,
|
|
||||||
}, source); err != nil {
|
|
||||||
_ = source.Close()
|
|
||||||
closePublishTransfers(transfers)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
transfers = append(transfers, publishTransfer{
|
||||||
|
Artifact: artifacts.RemoteArtifact{Type: artifacts.RemoteArtifactTypePublishedOutput, Source: output.Source, DestinationKey: output.DeclaredKey},
|
||||||
|
SourceRoot: sessionRoot, SourcePath: relative, Checksum: output.Checksum,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
sort.Slice(transfers, func(i, j int) bool {
|
sort.Slice(transfers, func(i, j int) bool {
|
||||||
return transfers[i].Artifact.DestinationKey < transfers[j].Artifact.DestinationKey
|
return transfers[i].Artifact.DestinationKey < transfers[j].Artifact.DestinationKey
|
||||||
@@ -118,18 +98,13 @@ func appendCommittedSessionManifest(transfers *[]publishTransfer, localPath, des
|
|||||||
if transfers == nil {
|
if transfers == nil {
|
||||||
return fmt.Errorf("transfer plan is required")
|
return fmt.Errorf("transfer plan is required")
|
||||||
}
|
}
|
||||||
source, err := os.Open(localPath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*transfers = append(*transfers, publishTransfer{
|
*transfers = append(*transfers, publishTransfer{
|
||||||
Artifact: artifacts.RemoteArtifact{
|
Artifact: artifacts.RemoteArtifact{
|
||||||
Type: artifacts.RemoteArtifactTypeSessionManifest,
|
Type: artifacts.RemoteArtifactTypeSessionManifest,
|
||||||
Source: "session.manifest",
|
Source: "session.manifest",
|
||||||
DestinationKey: destinationKey,
|
DestinationKey: destinationKey,
|
||||||
},
|
},
|
||||||
Source: source,
|
SourceRoot: filepath.Dir(localPath), SourcePath: filepath.Base(localPath), TemporaryPath: localPath,
|
||||||
TemporaryPath: localPath,
|
|
||||||
})
|
})
|
||||||
sort.Slice(*transfers, func(i, j int) bool {
|
sort.Slice(*transfers, func(i, j int) bool {
|
||||||
return (*transfers)[i].Artifact.DestinationKey < (*transfers)[j].Artifact.DestinationKey
|
return (*transfers)[i].Artifact.DestinationKey < (*transfers)[j].Artifact.DestinationKey
|
||||||
@@ -308,9 +283,6 @@ func verifyPublishedObject(ctx context.Context, store storage.ObjectStore, key s
|
|||||||
|
|
||||||
func closePublishTransfers(transfers []publishTransfer) {
|
func closePublishTransfers(transfers []publishTransfer) {
|
||||||
for _, transfer := range transfers {
|
for _, transfer := range transfers {
|
||||||
if transfer.Source != nil {
|
|
||||||
_ = transfer.Source.Close()
|
|
||||||
}
|
|
||||||
if transfer.TemporaryPath != "" {
|
if transfer.TemporaryPath != "" {
|
||||||
_ = os.Remove(transfer.TemporaryPath)
|
_ = os.Remove(transfer.TemporaryPath)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user