Skip to content

Commit

Permalink
Merge branch 'main' into feature/diff-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinAbro321 committed May 6, 2024
2 parents 04d20e7 + cfe8f19 commit 7e88fdf
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/injector/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde_json::Value;
use sha2::{Digest, Sha256};
use tar::Archive;

const DOCKER_MIME_TYPE: &str = "application/vnd.docker.distribution.manifest.v2+json";
const OCI_MIME_TYPE: &str = "application/vnd.oci.image.manifest.v1+json";

// Reads the binary contents of a file
fn get_file(path: &PathBuf) -> io::Result<Vec<u8>> {
Expand Down Expand Up @@ -140,7 +140,7 @@ fn handle_request(root: &Path, request: &Request) -> Response {
// on Content-Length, we respond the same as a GET
return accept!(
request,
DOCKER_MIME_TYPE => {
OCI_MIME_TYPE => {
handle_get_manifest(&root, &namespaced_name, &tag_or_digest)
},
"*/*" => Response::empty_406()
Expand Down Expand Up @@ -183,7 +183,7 @@ fn handle_get_manifest(root: &Path, name: &String, tag: &String) -> Response {

if sha_manifest != "" {
let file = File::open(&root.join("blobs").join("sha256").join(&sha_manifest)).unwrap();
Response::from_file(DOCKER_MIME_TYPE, file)
Response::from_file(OCI_MIME_TYPE, file)
.with_additional_header(
"Docker-Content-Digest",
format!("sha256:{}", sha_manifest.to_owned()),
Expand Down
5 changes: 5 additions & 0 deletions src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func (p *Packager) ClearTempPaths() {
_ = os.RemoveAll(layout.SBOMDir)
}

// GetVariableConfig returns the variable configuration for the packager.
func (p *Packager) GetVariableConfig() *variables.VariableConfig {
return p.variableConfig
}

// connectToCluster attempts to connect to a cluster if a connection is not already established
func (p *Packager) connectToCluster(timeout time.Duration) (err error) {
if p.isConnectedToCluster() {
Expand Down
66 changes: 66 additions & 0 deletions src/pkg/packager/creator/differential_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

package creator

import (
"testing"

"github.com/defenseunicorns/zarf/src/types"
"github.com/stretchr/testify/require"
)

func TestRemoveCopiesFromComponents(t *testing.T) {
components := []types.ZarfComponent{
{
Images: []string{
"example.com/include-image-tag:latest",
"example.com/image-with-tag:v1",
"example.com/diff-image-with-tag:v1",
"example.com/image-with-digest@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"example.com/diff-image-with-digest@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"example.com/image-with-tag-and-digest:v1@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"example.com/diff-image-with-tag-and-digest:v1@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
},
Repos: []string{
"https://example.com/no-ref.git",
"https://example.com/branch.git@refs/heads/main",
"https://example.com/tag.git@v1",
"https://example.com/diff-tag.git@v1",
"https://example.com/commit.git@524980951ff16e19dc25232e9aea8fd693989ba6",
"https://example.com/diff-commit.git@524980951ff16e19dc25232e9aea8fd693989ba6",
},
},
}
loadedDiffData := types.DifferentialData{
DifferentialImages: map[string]bool{
"example.com/include-image-tag:latest": true,
"example.com/diff-image-with-tag:v1": true,
"example.com/diff-image-with-digest@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855": true,
"example.com/diff-image-with-tag-and-digest:v1@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855": true,
},
DifferentialRepos: map[string]bool{
"https://example.com/no-ref.git": true,
"https://example.com/branch.git@refs/heads/main": true,
"https://example.com/diff-tag.git@v1": true,
"https://example.com/diff-commit.git@524980951ff16e19dc25232e9aea8fd693989ba6": true,
},
}
diffComponents, err := removeCopiesFromComponents(components, &loadedDiffData)
require.NoError(t, err)

expectedImages := []string{
"example.com/include-image-tag:latest",
"example.com/image-with-tag:v1",
"example.com/image-with-digest@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"example.com/image-with-tag-and-digest:v1@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
}
require.ElementsMatch(t, expectedImages, diffComponents[0].Images)
expectedRepos := []string{
"https://example.com/no-ref.git",
"https://example.com/branch.git@refs/heads/main",
"https://example.com/tag.git@v1",
"https://example.com/commit.git@524980951ff16e19dc25232e9aea8fd693989ba6",
}
require.ElementsMatch(t, expectedRepos, diffComponents[0].Repos)
}
6 changes: 3 additions & 3 deletions zarf-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ agent_image = 'defenseunicorns/zarf/agent'
agent_image_tag = 'local'

# Tag for the zarf injector binary to use
injector_version = '2023-08-02'
injector_amd64_shasum = '91de0768855ee2606a4f85a92bb480ff3a14ca205fd8d05eb397c18e15aa0247'
injector_arm64_shasum = '663df681deea957b0ec53538eab221691a83de8e95d86b8a29008af711934bee'
injector_version = '2024-05-03'
injector_amd64_shasum = 'e5a3d380bac4bf6c68ba18275d6a92bb002e86c116eb364f960d393fd2f44da8'
injector_arm64_shasum = 'f7f26e37a514f2ca36d795b7611d64491398a4bdc424e0045875af391dc28659'

# The image reference to use for the registry that Zarf deploys into the cluster
registry_image_domain = ''
Expand Down

0 comments on commit 7e88fdf

Please sign in to comment.