Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
  • Loading branch information
AustinAbro321 committed Aug 8, 2024
2 parents b1ce576 + 02f2932 commit 7d017ab
Show file tree
Hide file tree
Showing 25 changed files with 320 additions and 164 deletions.
14 changes: 2 additions & 12 deletions examples/dos-games/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,9 @@ RUN wget https://js-dos.com/6.22/current/js-dos.js && \
wget https://js-dos.com/6.22/current/wdosbox.js && \
wget https://js-dos.com/6.22/current/wdosbox.wasm.js

RUN wget -O aladdin.zip "https://web.archive.org/web/20190303222445if_/https://www.dosgames.com/files/DOSBOX_ALADDIN.ZIP"
RUN wget -O doom.zip "https://archive.org/download/DoomsharewareEpisode/doom.ZIP"
RUN wget -O mario-brothers.zip "https://image.dosgamesarchive.com/games/mario-bro.zip"
RUN wget -O prince-of-persia.zip "https://web.archive.org/web/20181030180256if_/http://image.dosgamesarchive.com/games/pop1.zip"
RUN wget -O quake.zip "https://web.archive.org/web/20190303223506if_/https://www.dosgames.com/files/DOSBOX_QUAKE.ZIP"
RUN wget -O warcraft-ii.zip "https://web.archive.org/web/20190303222732if_/https://www.dosgames.com/files/DOSBOX_WAR2.ZIP"

RUN wget -O aladdin.png "https://image.dosgamesarchive.com/screenshots/aladdem-4.png" && \
wget -O doom.png "https://image.dosgamesarchive.com/screenshots/doom01.png" && \
wget -O mario-brothers.png "https://image.dosgamesarchive.com/screenshots/marionl-6.png" && \
wget -O prince-of-persia.png "https://image.dosgamesarchive.com/screenshots/prince102.png" && \
wget -O quake.png "https://image.dosgamesarchive.com/screenshots/quake13.png" && \
wget -O warcraft-ii.png "https://image.dosgamesarchive.com/screenshots/war2demo3.png"
RUN wget -O doom.png "https://image.dosgamesarchive.com/screenshots/doom01.png"


COPY index.html .
Expand All @@ -34,4 +24,4 @@ COPY --from=0 /binary /binary
WORKDIR /site
ENTRYPOINT ["/binary/darkhttpd", "/site", "--port", "8000"]

# docker buildx build --push --platform linux/arm/v7,linux/arm64/v8,linux/amd64 --tag defenseunicorns/zarf-game:multi-tile .
# docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/zarf-dev/doom-game:0.0.1 .
22 changes: 3 additions & 19 deletions examples/dos-games/image/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
}

.column img {
margin-top: 8px;
margin-top: 16px;
vertical-align: middle;
width: 100%;
height: auto;
}

/* Responsive layout - makes a two column-layout instead of four columns */
Expand All @@ -70,22 +71,14 @@
}
}
</style>
</style>
</head>

<body>
<canvas id="jsdos" style="display: none;"></canvas>
<script>
const game = location.search.substr(1)
const gamePaths = {
'aladdin': 'ALADDIN.EXE',
'doom': 'DOOM.EXE',
'mario-brothers': 'MARIO.BAT',
'mega-man-x': 'MMXDEMO.EXE',
'prince-of-persia': 'pop1demo.exe',
'quake': 'QUAKE.EXE',
'sim-city-2k': 'SC2000.EXE',
'warcraft-ii': 'WAR2.EXE',
}

if (gamePaths[game]) {
Expand All @@ -101,15 +94,6 @@

<div class="row">
<div class="column">
<a href="?aladdin"><img src="aladdin.png" style="width:100%"></a>
<a href="?doom"><img src="doom.png" style="width:100%"></a>
</div>
<div class="column">
<a href="?mario-brothers"><img src="mario-brothers.png" style="width:100%"></a>
<a href="?prince-of-persia"><img src="prince-of-persia.png" style="width:100%"></a>
</div>
<div class="column">
<a href="?quake"><img src="quake.png" style="width:100%"></a>
<a href="?warcraft-ii"><img src="warcraft-ii.png" style="width:100%"></a>
<a href="?doom"><img src="doom.png" ></a>
</div>
</div>
2 changes: 1 addition & 1 deletion examples/dos-games/manifests/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
spec:
containers:
- name: multi-game
image: "defenseunicorns/zarf-game:multi-tile-dark"
image: ghcr.io/zarf-dev/doom-game:0.0.1
ports:
- name: http
containerPort: 8000
Expand Down
2 changes: 1 addition & 1 deletion examples/dos-games/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ components:
- manifests/deployment.yaml
- manifests/service.yaml
images:
- defenseunicorns/zarf-game:multi-tile-dark
- ghcr.io/zarf-dev/doom-game:0.0.1
actions:
onDeploy:
after:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ require (
github.com/sigstore/sigstore/pkg/signature/kms/hashivault v1.8.7
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.18.2
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/xeipuuv/gojsonschema v1.2.0
github.com/zarf-dev/zarf/src/api v0.0.0-00010101000000-000000000000
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1597,8 +1597,8 @@ github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.10.0/go.mod h1:SoyBPwAtKDzypXNDFKN5kzH7ppppbGZtls1UpIy5AsM=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/spiffe/go-spiffe/v2 v2.1.7 h1:VUkM1yIyg/x8X7u1uXqSRVRCdMdfRIEdFBzpqoeASGk=
github.com/spiffe/go-spiffe/v2 v2.1.7/go.mod h1:QJDGdhXllxjxvd5B+2XnhhXB/+rC8gr+lNrtOryiWeE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
39 changes: 22 additions & 17 deletions src/internal/packager/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ import (
"golang.org/x/sync/errgroup"
)

func checkForIndex(refInfo transform.Image, desc *remote.Descriptor) error {
if refInfo.Digest != "" && desc != nil && types.MediaType(desc.MediaType).IsIndex() {
var idx v1.IndexManifest
if err := json.Unmarshal(desc.Manifest, &idx); err != nil {
return fmt.Errorf("unable to unmarshal index.json: %w", err)
}
lines := []string{"The following images are available in the index:"}
name := refInfo.Name
if refInfo.Tag != "" {
name += ":" + refInfo.Tag
}
for _, desc := range idx.Manifests {
lines = append(lines, fmt.Sprintf("image - %s@%s with platform %s", name, desc.Digest.String(), desc.Platform.String()))
}
imageOptions := strings.Join(lines, "\n")
return fmt.Errorf("%s resolved to an OCI image index which is not supported by Zarf, select a specific platform to use: %s", refInfo.Reference, imageOptions)
}
return nil
}

// Pull pulls all of the images from the given config.
func Pull(ctx context.Context, cfg PullConfig) (map[transform.Image]v1.Image, error) {
var longer string
Expand Down Expand Up @@ -146,23 +166,8 @@ func Pull(ctx context.Context, cfg PullConfig) (map[transform.Image]v1.Image, er
}
}

if refInfo.Digest != "" && desc != nil && types.MediaType(desc.MediaType).IsIndex() {
message.Warn("Zarf does not currently support direct consumption of OCI image indexes or Docker manifest lists")

var idx v1.IndexManifest
if err := json.Unmarshal(desc.Manifest, &idx); err != nil {
return fmt.Errorf("unable to unmarshal index manifest: %w", err)
}
lines := []string{"The following images are available in the index:"}
name := refInfo.Name
if refInfo.Tag != "" {
name += ":" + refInfo.Tag
}
for _, desc := range idx.Manifests {
lines = append(lines, fmt.Sprintf("\n(%s) %s@%s", desc.Platform, name, desc.Digest))
}
message.Warn(strings.Join(lines, "\n"))
return fmt.Errorf("%s resolved to an index, please select a specific platform to use", refInfo.Reference)
if err := checkForIndex(refInfo, desc); err != nil {
return err
}

cacheImg, err := utils.OnlyHasImageLayers(img)
Expand Down
69 changes: 69 additions & 0 deletions src/internal/packager/images/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,83 @@ package images

import (
"context"
"encoding/json"
"fmt"
"os"
"path/filepath"
"testing"

v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/stretchr/testify/require"
"github.com/zarf-dev/zarf/src/pkg/transform"
)

func TestCheckForIndex(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
ref string
file string
expectedErr string
}{
{
name: "index sha",
ref: "ghcr.io/zarf-dev/zarf/agent:v0.32.6@sha256:05a82656df5466ce17c3e364c16792ae21ce68438bfe06eeab309d0520c16b48",
file: "agent-index.json",
expectedErr: "%s resolved to an OCI image index which is not supported by Zarf, select a specific platform to use",
},
{
name: "docker manifest list",
ref: "defenseunicorns/zarf-game@sha256:0b694ca1c33afae97b7471488e07968599f1d2470c629f76af67145ca64428af",
file: "game-index.json",
expectedErr: "%s resolved to an OCI image index which is not supported by Zarf, select a specific platform to use",
},
{
name: "image manifest",
ref: "ghcr.io/zarf-dev/zarf/agent:v0.32.6",
file: "agent-manifest.json",
expectedErr: "",
},
{
name: "image manifest sha'd",
ref: "ghcr.io/zarf-dev/zarf/agent:v0.32.6@sha256:b3fabdc7d4ecd0f396016ef78da19002c39e3ace352ea0ae4baa2ce9d5958376",
file: "agent-manifest.json",
expectedErr: "",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
refInfo, err := transform.ParseImageRef(tc.ref)
require.NoError(t, err)
file := filepath.Join("testdata", tc.file)
manifest, err := os.ReadFile(file)
require.NoError(t, err)
var idx v1.IndexManifest
err = json.Unmarshal(manifest, &idx)
require.NoError(t, err)
desc := &remote.Descriptor{
Descriptor: v1.Descriptor{
MediaType: idx.MediaType,
},
Manifest: manifest,
}
err = checkForIndex(refInfo, desc)
if tc.expectedErr != "" {
require.ErrorContains(t, err, fmt.Sprintf(tc.expectedErr, refInfo.Reference))
// Ensure the error message contains the digest of the manifests the user can use
for _, manifest := range idx.Manifests {
require.ErrorContains(t, err, manifest.Digest.String())
}
return
}
require.NoError(t, err)
})
}
}

func TestPull(t *testing.T) {
t.Run("pulling a cosign image is successful and doesn't add anything to the cache", func(t *testing.T) {
ref, err := transform.ParseImageRef("ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.sig")
Expand Down
50 changes: 50 additions & 0 deletions src/internal/packager/images/testdata/agent-index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.index.v1+json",
"manifests": [
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:b3fabdc7d4ecd0f396016ef78da19002c39e3ace352ea0ae4baa2ce9d5958376",
"size": 673,
"platform": {
"architecture": "arm64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:454bf871b5d826b6a31ab14c983583ae9d9e30c2036606b500368c5b552d8fdf",
"size": 673,
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:449cd2cd763614f07219f38f8514b56c7831d583f7c6f767491d3ad31572189c",
"size": 566,
"annotations": {
"vnd.docker.reference.digest": "sha256:b3fabdc7d4ecd0f396016ef78da19002c39e3ace352ea0ae4baa2ce9d5958376",
"vnd.docker.reference.type": "attestation-manifest"
},
"platform": {
"architecture": "unknown",
"os": "unknown"
}
},
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:2b51d89bf901b4e65dd85d8c6f135278fc7f86bb48608f0681a83291deadd645",
"size": 566,
"annotations": {
"vnd.docker.reference.digest": "sha256:454bf871b5d826b6a31ab14c983583ae9d9e30c2036606b500368c5b552d8fdf",
"vnd.docker.reference.type": "attestation-manifest"
},
"platform": {
"architecture": "unknown",
"os": "unknown"
}
}
]
}
21 changes: 21 additions & 0 deletions src/internal/packager/images/testdata/agent-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"config": {
"mediaType": "application/vnd.oci.image.config.v1+json",
"digest": "sha256:cd4790c66d0f72eb0e0c12d75c1025478294af876ff0042d1c3501db57b0244b",
"size": 1284
},
"layers": [
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:32f8946351207153325c9d5eb56c61bbd96f9cd8deaa6dcecc4a3d4867609bec",
"size": 327582
},
{
"mediaType": "application/vnd.oci.image.layer.v1.tar+gzip",
"digest": "sha256:72dbbe2df2af4ee1b7a0c7ee66782999e8f6f846ffed250aec3738791d941ba7",
"size": 38937433
}
]
}
34 changes: 34 additions & 0 deletions src/internal/packager/images/testdata/game-index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"schemaVersion": 2,
"manifests": [
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"digest": "sha256:f78e442f0f3eb3e9459b5ae6b1a8fda62f8dfe818112e7d130a4e8ae72b3cbff",
"size": 739,
"platform": {
"architecture": "arm",
"os": "linux",
"variant": "v7"
}
},
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"digest": "sha256:e4d27fe4b7bf6d5cb7ef02ed0d33ec0846796c09d6ed4bd94c8b946119a01b09",
"size": 739,
"platform": {
"architecture": "arm64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"digest": "sha256:e81b1467b812019f8e8e81450728b084471806dc7e959b7beb9f39933c337e7d",
"size": 739,
"platform": {
"architecture": "amd64",
"os": "linux"
}
}
]
}
Loading

0 comments on commit 7d017ab

Please sign in to comment.