Skip to content

Commit

Permalink
refactor: containers/image -> ggcr step 2
Browse files Browse the repository at this point in the history
Signed-off-by: jason yang <jasonyangshadow@gmail.com>
  • Loading branch information
JasonYangShadow committed Sep 13, 2024
1 parent 6e78c93 commit 4b84718
Show file tree
Hide file tree
Showing 22 changed files with 1,136 additions and 300 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ jobs:
- name: Upload artifacts
if: env.run_tests
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: e2e-artifact
path: builddir/e2e-cmd-report.txt
Expand Down
6 changes: 0 additions & 6 deletions LICENSE_DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -917,12 +917,6 @@ The dependencies and their licenses are as follows:

**License URL:** <https://github.com/titanous/rocacheck/blob/master/LICENSE>

## github.com/urfave/cli

**License:** MIT

**License URL:** <https://github.com/urfave/cli/blob/master/LICENSE>

## go.mozilla.org/pkcs7

**License:** MIT
Expand Down
4 changes: 2 additions & 2 deletions cmd/internal/cli/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/apptainer/apptainer/internal/pkg/client/oras"
"github.com/apptainer/apptainer/internal/pkg/client/shub"
"github.com/apptainer/apptainer/internal/pkg/instance"
"github.com/apptainer/apptainer/internal/pkg/ocitransport"
"github.com/apptainer/apptainer/internal/pkg/ociimage"
"github.com/apptainer/apptainer/internal/pkg/runtime/launch"
"github.com/apptainer/apptainer/internal/pkg/util/env"
"github.com/apptainer/apptainer/internal/pkg/util/uri"
Expand Down Expand Up @@ -158,7 +158,7 @@ func replaceURIWithImage(ctx context.Context, cmd *cobra.Command, args []string)
image, err = handleOras(ctx, imgCache, cmd, args[0])
case uri.Shub:
image, err = handleShub(ctx, imgCache, args[0])
case ocitransport.SupportedTransport(t):
case ociimage.SupportedTransport(t):
image, err = handleOCI(ctx, imgCache, cmd, args[0])
case uri.HTTP:
image, err = handleNet(ctx, imgCache, args[0])
Expand Down
4 changes: 2 additions & 2 deletions cmd/internal/cli/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/apptainer/apptainer/internal/pkg/client/oci"
"github.com/apptainer/apptainer/internal/pkg/client/oras"
"github.com/apptainer/apptainer/internal/pkg/client/shub"
"github.com/apptainer/apptainer/internal/pkg/ocitransport"
"github.com/apptainer/apptainer/internal/pkg/ociimage"
"github.com/apptainer/apptainer/internal/pkg/remote/endpoint"
"github.com/apptainer/apptainer/internal/pkg/util/uri"
"github.com/apptainer/apptainer/pkg/cmdline"
Expand Down Expand Up @@ -278,7 +278,7 @@ func pullRun(cmd *cobra.Command, args []string) {
if err != nil {
sylog.Fatalf("While pulling from image from http(s): %v\n", err)
}
case ocitransport.SupportedTransport(transport):
case ociimage.SupportedTransport(transport):
ociAuth, err := makeOCICredentials(cmd)
if err != nil {
sylog.Fatalf("While creating Docker credentials: %v", err)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/sylabs/json-resp v0.9.3
github.com/urfave/cli v1.22.14 // indirect
github.com/vbauerster/mpb/v8 v8.8.3
golang.org/x/crypto v0.26.0
golang.org/x/sys v0.24.0
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ github.com/AdamKorcz/go-fuzz-headers v0.0.0-20210319161527-f761c2329661/go.mod h
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
Expand Down Expand Up @@ -94,7 +93,6 @@ github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
Expand Down Expand Up @@ -481,8 +479,6 @@ github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/urfave/cli v1.19.1/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk=
github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA=
github.com/vbatts/go-mtree v0.5.0 h1:dM+5XZdqH0j9CSZeerhoN/tAySdwnmevaZHO1XGW2Vc=
github.com/vbatts/go-mtree v0.5.0/go.mod h1:7JbaNHyBMng+RP8C3Q4E+4Ca8JnGQA2R/MB+jb4tSOk=
github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts=
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/build/conveyorPacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"fmt"

"github.com/apptainer/apptainer/internal/pkg/build/sources"
"github.com/apptainer/apptainer/internal/pkg/ocitransport"
"github.com/apptainer/apptainer/internal/pkg/ociimage"
"github.com/apptainer/apptainer/pkg/build/types"
)

Expand Down Expand Up @@ -48,7 +48,7 @@ func conveyorPacker(def types.Definition) (ConveyorPacker, error) {
return &sources.OrasConveyorPacker{}, nil
case "shub":
return &sources.ShubConveyorPacker{}, nil
case ocitransport.SupportedTransport(bs):
case ociimage.SupportedTransport(bs):
return &sources.OCIConveyorPacker{}, nil
case "busybox":
return &sources.BusyBoxConveyorPacker{}, nil
Expand Down
18 changes: 9 additions & 9 deletions internal/pkg/build/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"strings"

"github.com/apptainer/apptainer/internal/pkg/cache"
"github.com/apptainer/apptainer/internal/pkg/ocitransport"
"github.com/apptainer/apptainer/internal/pkg/ociimage"
"github.com/apptainer/apptainer/pkg/sylog"
"github.com/containers/image/v5/copy"
"github.com/containers/image/v5/docker"
Expand Down Expand Up @@ -76,14 +76,14 @@ var ArchMap = map[string]GoArch{
}

// ConvertReference converts a source reference into a cache.ImageReference to cache its blobs
func ConvertReference(ctx context.Context, imgCache *cache.Handle, src types.ImageReference, topts *ocitransport.TransportOptions) (types.ImageReference, error) {
func ConvertReference(ctx context.Context, imgCache *cache.Handle, src types.ImageReference, topts *ociimage.TransportOptions) (types.ImageReference, error) {
if imgCache == nil {
return nil, fmt.Errorf("undefined image cache")
}

if topts == nil {
// nolint:staticcheck
topts = ocitransport.TransportOptionsFromSystemContext(nil)
topts = ociimage.TransportOptionsFromSystemContext(nil)
}

// Our cache dir is an OCI directory. We are using this as a 'blob pool'
Expand Down Expand Up @@ -135,7 +135,7 @@ func (t *ImageReference) newImageSource(ctx context.Context, sys *types.SystemCo

// ParseImageName parses a uri (e.g. docker://ubuntu) into it's transport:reference
// combination and then returns the proper reference
func ParseImageName(ctx context.Context, imgCache *cache.Handle, uri string, topts *ocitransport.TransportOptions) (types.ImageReference, error) {
func ParseImageName(ctx context.Context, imgCache *cache.Handle, uri string, topts *ociimage.TransportOptions) (types.ImageReference, error) {
ref, _, err := parseURI(uri)
if err != nil {
return nil, fmt.Errorf("unable to parse image name %v: %v", uri, err)
Expand Down Expand Up @@ -164,7 +164,7 @@ func parseURI(uri string) (types.ImageReference, *GoArch, error) {
}

// ImageDigest obtains the digest of a uri's manifest
func ImageDigest(ctx context.Context, uri string, topts *ocitransport.TransportOptions) (digest string, err error) {
func ImageDigest(ctx context.Context, uri string, topts *ociimage.TransportOptions) (digest string, err error) {
ref, arch, err := parseURI(uri)
if err != nil {
return "", fmt.Errorf("unable to parse image name %v: %v", uri, err)
Expand All @@ -179,7 +179,7 @@ func ImageDigest(ctx context.Context, uri string, topts *ocitransport.TransportO
}

// getRefDigest obtains the manifest digest for a ref.
func getRefDigest(ctx context.Context, ref types.ImageReference, topts *ocitransport.TransportOptions) (digest string, err error) {
func getRefDigest(ctx context.Context, ref types.ImageReference, topts *ociimage.TransportOptions) (digest string, err error) {
// Handle docker references specially, using a HEAD request to ensure we don't hit API limits
if ref.Transport().Name() == "docker" {
digest, err := getDockerRefDigest(ctx, ref, topts)
Expand All @@ -194,7 +194,7 @@ func getRefDigest(ctx context.Context, ref types.ImageReference, topts *ocitrans

// Otherwise get the manifest and calculate sha256 over it
// nolint:staticcheck
source, err := ref.NewImageSource(ctx, ocitransport.SystemContextFromTransportOptions(topts))
source, err := ref.NewImageSource(ctx, ociimage.SystemContextFromTransportOptions(topts))
if err != nil {
return "", err
}
Expand All @@ -216,9 +216,9 @@ func getRefDigest(ctx context.Context, ref types.ImageReference, topts *ocitrans
}

// getDockerRefDigest obtains the manifest digest for a docker ref.
func getDockerRefDigest(ctx context.Context, ref types.ImageReference, topts *ocitransport.TransportOptions) (digest string, err error) {
func getDockerRefDigest(ctx context.Context, ref types.ImageReference, topts *ociimage.TransportOptions) (digest string, err error) {
// nolint:staticcheck
d, err := docker.GetDigest(ctx, ocitransport.SystemContextFromTransportOptions(topts), ref)
d, err := docker.GetDigest(ctx, ociimage.SystemContextFromTransportOptions(topts), ref)
if err != nil {
return "", err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/build/oci/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"

"github.com/apptainer/apptainer/internal/pkg/cache"
"github.com/apptainer/apptainer/internal/pkg/ocitransport"
"github.com/apptainer/apptainer/internal/pkg/ociimage"
"github.com/apptainer/apptainer/internal/pkg/test"
buildTypes "github.com/apptainer/apptainer/pkg/build/types"
"github.com/containers/image/v5/oci/layout"
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestConvertReference(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// nolint: staticcheck
_, err := ConvertReference(context.Background(), imgCache, tt.ref, ocitransport.TransportOptionsFromSystemContext(tt.ctx))
_, err := ConvertReference(context.Background(), imgCache, tt.ref, ociimage.TransportOptionsFromSystemContext(tt.ctx))
if tt.shouldPass == true && err != nil {
t.Fatalf("test expected to succeeded but failed: %s\n", err)
}
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestImageNameAndImageSHA(t *testing.T) {
testName := "ParseImageName - " + tt.name
t.Run(testName, func(t *testing.T) {
// nolint:staticcheck
_, err := ParseImageName(context.Background(), imgCache, tt.uri, ocitransport.TransportOptionsFromSystemContext(tt.ctx))
_, err := ParseImageName(context.Background(), imgCache, tt.uri, ociimage.TransportOptionsFromSystemContext(tt.ctx))
if tt.shouldPass == true && err != nil {
t.Fatalf("test expected to succeeded but failed: %s\n", err)
}
Expand All @@ -359,7 +359,7 @@ func TestImageNameAndImageSHA(t *testing.T) {
testName = "ImageSHA - " + tt.name
t.Run(testName, func(t *testing.T) {
// nolint: staticcheck
_, err := ImageDigest(context.Background(), tt.uri, ocitransport.TransportOptionsFromSystemContext(tt.ctx))
_, err := ImageDigest(context.Background(), tt.uri, ociimage.TransportOptionsFromSystemContext(tt.ctx))
if tt.shouldPass == true && err != nil {
t.Fatal("test expected to succeeded but failed")
}
Expand Down
Loading

0 comments on commit 4b84718

Please sign in to comment.