Skip to content
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
44 changes: 22 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ jobs:
setup:
uses: ./.github/workflows/setup.yml

test:
needs: setup
runs-on: ${{ fromJSON(needs.setup.outputs.runner-labels)[matrix.os] }}
strategy:
matrix:
os: ${{ fromJSON(needs.setup.outputs.available-runners) }}
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
- name: Install zlib static on AL2 ARM instances
if: matrix.os == 'al2-arm'
run: dnf install zlib-static.aarch64 -y
- run: make
- run: make test-with-coverage
- name: Show test coverage
run: make show-test-coverage
# test:
# needs: setup
# runs-on: ${{ fromJSON(needs.setup.outputs.runner-labels)[matrix.os] }}
# strategy:
# matrix:
# os: ${{ fromJSON(needs.setup.outputs.available-runners) }}
# timeout-minutes: 15
# steps:
# - uses: actions/checkout@v6
# - uses: actions/setup-go@v6
# with:
# go-version: ${{ env.GO_VERSION }}
# - name: Install zlib static on AL2 ARM instances
# if: matrix.os == 'al2-arm'
# run: dnf install zlib-static.aarch64 -y
# - run: make
# - run: make test-with-coverage
# - name: Show test coverage
# run: make show-test-coverage

integration:
needs: setup
Expand All @@ -72,6 +72,6 @@ jobs:
if [[ "${{ matrix.os }}" == "ubuntu-x86" ]]; then
SKIP_SYSTEMD_TESTS=1
fi
SKIP_SYSTEMD_TESTS=$SKIP_SYSTEMD_TESTS make integration-with-coverage
- name: Show test coverage
run: make show-integration-coverage
SKIP_SYSTEMD_TESTS=$SKIP_SYSTEMD_TESTS GO_TEST_FLAGS="-count 1 -run TestConvert/convert_and_replace" make integration
# - name: Show test coverage
# run: make show-integration-coverage
65 changes: 65 additions & 0 deletions integration/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,57 @@ func TestConvertWithForceRecreateZtocs(t *testing.T) {
func validateConversion(t *testing.T, sh *shell.Shell, originalDigest, convertedDigest string) {
t.Helper()

// Helper function to get digest label mapping
getDigestLabelMapping := func(manifestDigest string) (map[string][]string, error) {
digestMap := make(map[string][]string)

manifestLabelOutput := sh.O("ctr", "content", "label", manifestDigest)
manifestLabels := strings.Split(strings.TrimSpace(string(manifestLabelOutput)), ",")

if len(manifestLabels) <= 0 {
return nil, fmt.Errorf("manifest does not contain any labels")
}

for _, label := range manifestLabels {
keyVal := strings.Split(label, "=")
if len(keyVal) != 2 {
continue
}
digestMap[keyVal[1]] = append(digestMap[keyVal[1]], keyVal[0])
}
return digestMap, nil
}

// Helper function to verify image layers contain required labels
verifyImageLayersContainsLabel := func(digestMap map[string][]string, manifest ocispec.Manifest) error {
// Helper function to check if a digest has the required label
checkDigestLabels := func(digest string) error {
if labels, ok := digestMap[digest]; ok {
for _, label := range labels {
if strings.Contains(label, "containerd.io/gc.ref.content") {
return nil // Found the required label
}
}
return fmt.Errorf("digest %s does not have associated gc label", digest)
}
return fmt.Errorf("digest %s not found in digestMap", digest)
}

// Check all layer digests
for _, layer := range manifest.Layers {
if err := checkDigestLabels(layer.Digest.String()); err != nil {
return err
}
}

// Check config digest
if err := checkDigestLabels(manifest.Config.Digest.String()); err != nil {
return err
}

return nil
}

if originalDigest == convertedDigest {
t.Fatalf("conversion did not change the digest: %s", originalDigest)
}
Expand Down Expand Up @@ -197,7 +248,21 @@ func validateConversion(t *testing.T, sh *shell.Shell, originalDigest, converted
if dg, ok := manifest.Annotations[soci.ImageAnnotationSociIndexDigest]; !ok || dg != sociIndexDesc.Digest.String() {
t.Errorf("manifest %v does not contain expected soci index digest %v", manifestDesc, sociIndexDesc.Digest)
}

// get labels associated with the manifest and extract the digest
digestLabelMap, err := getDigestLabelMapping(manifestDesc.Digest.String())
if err != nil {
t.Errorf("failed to get config digest from manifest: %v", err)
continue
}

err = verifyImageLayersContainsLabel(digestLabelMap, manifest)
if err != nil {
t.Errorf("error verifying layers: %v", err)
continue
}
}

}

func TestConvert(t *testing.T) {
Expand Down
12 changes: 12 additions & 0 deletions soci/soci_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@ func (b *IndexBuilder) annotateImages(ctx context.Context, ociIndex *ocispec.Ind
}
indexWithMetadata.Desc.Annotations[IndexAnnotationImageManifestDigest] = manifestDesc.Digest.String()
}

err = store.LabelGCRefContent(ctx, b.blobStore, *manifestDesc, "config", manifest.Config.Digest.String())
if err != nil {
return err
}

for i, layer := range manifest.Layers {
err = store.LabelGCRefContent(ctx, b.blobStore, *manifestDesc, fmt.Sprintf("l.%d", i), layer.Digest.String())
if err != nil {
return err
}
}
}
return nil
}
Expand Down