Skip to content

Commit

Permalink
fix: fixes bad media type when using create -o with GHCR (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd authored Jan 16, 2024
1 parent 7943f68 commit 52773a8
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ clean: ## Clean up build artifacts

clean-test-artifacts: ## removes bundles and zarf packages that have been created from previous test runs
find src/test -type f -name '*.tar.zst' -delete

push-test-artifacts: ## Push artifacts that UDS CLI tests rely on to GHCR
cd hack && ./push-test-artifacts.sh
37 changes: 37 additions & 0 deletions hack/push-test-artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env sh

# script to push the UDS bundle and Zarf artifacts that we use for testing GHCR
# ensure you have the proper creds and are logged in to GHCR for defenseunicorns

set -e

# create the nginx and podinfo Zarf packages
cd ./../src/test/packages/nginx
zarf package create -o oci://ghcr.io/defenseunicorns/uds-cli --confirm -a amd64
zarf package create -o oci://ghcr.io/defenseunicorns/uds-cli --confirm -a arm64

cd ../podinfo
zarf package create -o oci://ghcr.io/defenseunicorns/uds-cli --confirm -a amd64
zarf package create -o oci://ghcr.io/defenseunicorns/uds-cli --confirm -a arm64

# create ghcr-test bundle
cd ../../bundles/06-ghcr
uds create . -o ghcr.io/defenseunicorns/packages/uds-cli/test/create-remote --confirm -a amd64
uds create . -o ghcr.io/defenseunicorns/packages/uds-cli/test/create-remote --confirm -a arm64

uds create . -o ghcr.io/defenseunicorns/packages/uds-cli/test/publish --confirm -a amd64
uds create . -o ghcr.io/defenseunicorns/packages/uds-cli/test/publish --confirm -a arm64

uds create . -o ghcr.io/defenseunicorns/packages/uds/bundles --confirm -a amd64
uds create . -o ghcr.io/defenseunicorns/packages/uds/bundles --confirm -a arm64

uds create . -o ghcr.io/defenseunicorns/packages/delivery --confirm -a amd64
uds create . -o ghcr.io/defenseunicorns/packages/delivery --confirm -a arm64

# change name of bundle for testing purposes
sed -i'' -e 's/ghcr-test/ghcr-delivery-test/g' uds-bundle.yaml
uds create . -o ghcr.io/defenseunicorns/packages/delivery --confirm -a amd64
uds create . -o ghcr.io/defenseunicorns/packages/delivery --confirm -a arm64
sed -i'' -e 's/ghcr-delivery-test/ghcr-test/g' uds-bundle.yaml

echo "Finished pushing test artifacts to GHCR."
2 changes: 1 addition & 1 deletion src/config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The UDS Authorspackage config
// SPDX-FileCopyrightText: 2023-Present The UDS Authors

// Package config contains configuration strings for UDS-CLI
package config
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func CreateAndPublish(remoteDst *oci.OrasRemote, bundle *types.UDSBundle, signat
return err
}

// hack the media type to be a manifest and append to bundle root manifest
zarfManifestDesc.MediaType = ocispec.MediaTypeImageManifest
// ensure media type is a Zarf blob and append to bundle root manifest
zarfManifestDesc.MediaType = oci.ZarfLayerMediaTypeBlob
message.Debugf("Pushed %s sub-manifest into %s: %s", url, dstRef, message.JSONValue(zarfManifestDesc))
rootManifest.Layers = append(rootManifest.Layers, zarfManifestDesc)

Expand Down
8 changes: 4 additions & 4 deletions src/test/bundles/06-ghcr/uds-bundle.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
kind: UDSBundle
metadata:
name: ghcr-test
description: building from local and remote Zarf pkgs
description: testing a bundle of pkgs from ghcr
version: 0.0.1

packages:
- name: podinfo
repository: ghcr.io/defenseunicorns/uds-cli/podinfo
ref: 0.0.1
- name: nginx
repository: ghcr.io/defenseunicorns/uds-cli/nginx
ref: 0.0.1
- name: podinfo
path: "../../packages/podinfo"
ref: 0.0.1
6 changes: 6 additions & 0 deletions src/test/e2e/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func createRemote(t *testing.T, bundlePath string, registry string) {
require.NoError(t, err)
}

func createRemoteSecure(t *testing.T, bundlePath string, registry string) {
cmd := strings.Split(fmt.Sprintf("create %s -o %s --confirm", bundlePath, registry), " ")
_, _, err := e2e.UDS(cmd...)
require.NoError(t, err)
}

func inspectRemote(t *testing.T, ref string) {
cmd := strings.Split(fmt.Sprintf("inspect %s --insecure --sbom", ref), " ")
_, _, err := e2e.UDS(cmd...)
Expand Down
23 changes: 20 additions & 3 deletions src/test/e2e/ghcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import (

func TestBundleDeployFromOCIFromGHCR(t *testing.T) {
deployZarfInit(t)
e2e.CreateZarfPkg(t, "src/test/packages/podinfo")

bundleDir := "src/test/bundles/06-ghcr"
bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-ghcr-test-%s-0.0.1.tar.zst", e2e.Arch))

registryURL := "oci://ghcr.io/defenseunicorns/packages/uds/bundles/uds-cli/test"
registryURL := "oci://ghcr.io/defenseunicorns/packages/uds-cli/test/publish"

tarballPath := filepath.Join("build", fmt.Sprintf("uds-bundle-ghcr-test-%s-0.0.1.tar.zst", e2e.Arch))
bundleRef := registry.Reference{
Expand All @@ -33,13 +32,31 @@ func TestBundleDeployFromOCIFromGHCR(t *testing.T) {
inspect(t, bundlePath)
publish(t, bundlePath, registryURL)
// test without oci prefix
registryURL = "ghcr.io/defenseunicorns/packages/uds/bundles/uds-cli/test"
registryURL = "ghcr.io/defenseunicorns/packages/uds-cli/test/publish"
publish(t, bundlePath, registryURL)
pull(t, bundleRef.String(), tarballPath)
deploy(t, bundleRef.String())
remove(t, bundlePath)
}

// test the create -o path
func TestBundleCreateAndDeployOCI(t *testing.T) {
deployZarfInit(t)

bundleDir := "src/test/bundles/06-ghcr"
registryURL := "ghcr.io/defenseunicorns/packages/uds-cli/test/create-remote"
bundleRef := registry.Reference{
Registry: registryURL,
// this info is derived from the bundle's metadata
Repository: "ghcr-test",
Reference: fmt.Sprintf("0.0.1-%s", e2e.Arch),
}
createRemoteSecure(t, bundleDir, registryURL)
inspect(t, bundleRef.String())
deploy(t, bundleRef.String())
remove(t, bundleRef.String())
}

// This test requires the following to be published (based on src/test/bundles/06-ghcr/uds-bundle.yaml):
// ghcr.io/defenseunicorns/packages/uds/bundles/ghcr-test:0.0.1-amd64
// ghcr.io/defenseunicorns/packages/uds/bundles/ghcr-test:0.0.1-arm64
Expand Down

0 comments on commit 52773a8

Please sign in to comment.