Skip to content

New codebuild integration 3 1 #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:

jobs:
test:
runs-on: ubuntu-20.04
runs-on: codebuild-new_soci_CLI-${{ github.run_id }}-${{ github.run_attempt }}-ubuntu-7.0-xlarge
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
Expand All @@ -34,7 +34,7 @@ jobs:
- run: make
- run: make test
integration:
runs-on: ubuntu-20.04
runs-on: codebuild-new_soci_CLI-${{ github.run_id }}-${{ github.run_attempt }}-ubuntu-7.0-xlarge
timeout-minutes: 40
strategy:
fail-fast: false
Expand Down
7 changes: 1 addition & 6 deletions cmd/soci/commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@ var CreateCommand = cli.Command{
return err
}

sociIndexWithMetadata, err := builder.Build(ctx, srcImg)
if err != nil {
return err
}

err = soci.WriteSociIndex(ctx, sociIndexWithMetadata, blobStore, builder.ArtifactsDb)
_, err = builder.BuildAndPush(ctx, blobStore, srcImg)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion integration/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestLazyPullWithSparseIndex(t *testing.T) {
}

func checkFuseMounts(t *testing.T, sh *shell.Shell, remoteSnapshotsExpectedCount int) {
mounts := string(sh.O("mount"))
mounts := string(sh.O("cat", "/proc/mounts"))
remoteSnapshotsActualCount := strings.Count(mounts, "fuse.rawBridge")
if remoteSnapshotsExpectedCount != remoteSnapshotsActualCount {
t.Fatalf("incorrect number of remote snapshots; expected=%d, actual=%d",
Expand Down
39 changes: 32 additions & 7 deletions soci/soci_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,42 @@ func NewIndexBuilder(contentStore content.Store, blobStore orascontent.Storage,
}, nil
}

// BuildAndPush builds a SOCI index, pushes and labels the artifacts, and returns the SOCI index.
func (b *IndexBuilder) BuildAndPush(ctx context.Context, blobStore store.Store, img images.Image) (*IndexWithMetadata, error) {
sociIndexWithMetadata, done, err := b.Build(ctx, blobStore, img)
if err != nil {
return nil, err
}
defer done(ctx)

err = WriteSociIndex(ctx, sociIndexWithMetadata, blobStore, b.ArtifactsDb)
if err != nil {
return nil, err
}
return sociIndexWithMetadata, nil
}

// Build builds a soci index for `img` and return the index with metadata.
func (b *IndexBuilder) Build(ctx context.Context, img images.Image) (*IndexWithMetadata, error) {
// To prevent garbage collection of the zTOCs pushed by this command,
// we obtain a lease from containerd and also return it.
// It is the responsibility of the caller to terminate the lease.
// Ideally the lease ends after labelling and pushing the index and related zTOCs.
func (b *IndexBuilder) Build(ctx context.Context, blobStore store.Store, img images.Image) (*IndexWithMetadata, store.CleanupFunc, error) {
// we get manifest descriptor before calling images.Manifest, since after calling
// images.Manifest, images.Children will error out when reading the manifest blob (this happens on containerd side)
imgManifestDesc, err := GetImageManifestDescriptor(ctx, b.contentStore, img.Target, platforms.OnlyStrict(b.config.platform))
if err != nil {
return nil, err
return nil, nil, err
}
manifest, err := images.Manifest(ctx, b.contentStore, img.Target, platforms.OnlyStrict(b.config.platform))

if err != nil {
return nil, err
return nil, nil, err
}

ctx, done, err := blobStore.BatchOpen(ctx)
if err != nil {
return nil, nil, err
}

// attempt to build a ztoc for each layer
Expand Down Expand Up @@ -357,8 +381,8 @@ func (b *IndexBuilder) Build(ctx context.Context, img images.Image) (*IndexWithM
for _, err := range errs {
errWrap = fmt.Errorf("%w; %v", errWrap, err)
}

return nil, errWrap
done(ctx)
return nil, nil, errWrap
}

ztocsDesc := make([]ocispec.Descriptor, 0, len(sociLayersDesc))
Expand All @@ -369,7 +393,8 @@ func (b *IndexBuilder) Build(ctx context.Context, img images.Image) (*IndexWithM
}

if len(ztocsDesc) == 0 {
return nil, ErrEmptyIndex
done(ctx)
return nil, nil, ErrEmptyIndex
}

annotations := map[string]string{
Expand All @@ -388,7 +413,7 @@ func (b *IndexBuilder) Build(ctx context.Context, img images.Image) (*IndexWithM
Platform: &b.config.platform,
ImageDigest: img.Target.Digest,
CreatedAt: time.Now(),
}, nil
}, done, nil
}

// buildSociLayer builds a ztoc for an image layer (`desc`) and returns ztoc descriptor.
Expand Down