From 717dfb0b55679ca8b94928bf9575f68c2e64d1e6 Mon Sep 17 00:00:00 2001 From: Axel Christ Date: Tue, 7 Feb 2023 14:30:08 +0100 Subject: [PATCH] Remove signalcontext, rename main module to onmetalimage --- cmd/common/common.go | 12 ------------ cmd/main.go | 15 ++++++++------- go.mod | 1 - go.sum | 2 -- image.go | 14 +++++++++++++- image_test.go | 2 +- onmetal_image_suite_test.go | 2 +- 7 files changed, 23 insertions(+), 25 deletions(-) diff --git a/cmd/common/common.go b/cmd/common/common.go index e0fb439..6781dc9 100644 --- a/cmd/common/common.go +++ b/cmd/common/common.go @@ -22,9 +22,6 @@ import ( "github.com/onmetal/onmetal-image/oci/descriptormatcher" - "github.com/containerd/containerd/remotes" - onmetalimage "github.com/onmetal/onmetal-image" - "github.com/onmetal/onmetal-image/docker" "github.com/distribution/distribution/reference" @@ -97,12 +94,3 @@ func FuzzyResolveRef(ctx context.Context, store *store.Store, ref string) (strin return dsc.Digest.String(), nil } - -// SetupContext sets up context.Context to not log warnings on onmetal media types. -func SetupContext(ctx context.Context) context.Context { - ctx = remotes.WithMediaTypeKeyPrefix(ctx, onmetalimage.ConfigMediaType, "config-") - ctx = remotes.WithMediaTypeKeyPrefix(ctx, onmetalimage.RootFSLayerMediaType, "layer-") - ctx = remotes.WithMediaTypeKeyPrefix(ctx, onmetalimage.InitRAMFSLayerMediaType, "layer-") - ctx = remotes.WithMediaTypeKeyPrefix(ctx, onmetalimage.KernelLayerMediaType, "layer-") - return ctx -} diff --git a/cmd/main.go b/cmd/main.go index c06ce52..8780ff9 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -15,24 +15,25 @@ package main import ( + "context" "os" - - "github.com/onmetal/onmetal-image/cmd/common" + "os/signal" + "syscall" "github.com/go-logr/zapr" - onmetalimage "github.com/onmetal/onmetal-image/cmd/onmetal-image" + onmetalimage "github.com/onmetal/onmetal-image" + cmdonmetalimage "github.com/onmetal/onmetal-image/cmd/onmetal-image" "go.uber.org/zap" "github.com/go-logr/logr" - "github.com/sethvargo/go-signalcontext" ) func main() { - ctx, cancel := signalcontext.OnInterrupt() + ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer cancel() - ctx = common.SetupContext(ctx) + ctx = onmetalimage.SetupContext(ctx) zapLog, err := zap.NewDevelopment() if err != nil { @@ -41,7 +42,7 @@ func main() { log := zapr.NewLogger(zapLog) ctx = logr.NewContext(ctx, log) - if err := onmetalimage.Command().ExecuteContext(ctx); err != nil { + if err := cmdonmetalimage.Command().ExecuteContext(ctx); err != nil { log.Error(err, "Error running command") os.Exit(1) } diff --git a/go.mod b/go.mod index c92582a..7c455db 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,6 @@ require ( github.com/onsi/gomega v1.26.0 github.com/opencontainers/go-digest v1.0.0 github.com/opencontainers/image-spec v1.1.0-rc2 - github.com/sethvargo/go-signalcontext v0.1.0 github.com/spf13/cobra v1.6.1 go.uber.org/zap v1.24.0 oras.land/oras-go v1.2.2 diff --git a/go.sum b/go.sum index a7abff2..f658615 100644 --- a/go.sum +++ b/go.sum @@ -276,8 +276,6 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sethvargo/go-signalcontext v0.1.0 h1:3IU7HOlmRXF0PSDf85C4nJ/zjYDjF+DS+LufcKfLvyk= -github.com/sethvargo/go-signalcontext v0.1.0/go.mod h1:PXu9UmR2f7mmp8kEwgkKmaDbxq/PbqixkiC66WIkkWE= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= diff --git a/image.go b/image.go index 554a679..6963ac3 100644 --- a/image.go +++ b/image.go @@ -12,13 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -package onmetal_image +package onmetalimage import ( "context" "encoding/json" "fmt" + "github.com/containerd/containerd/remotes" "github.com/onmetal/onmetal-image/oci/image" ) @@ -53,8 +54,19 @@ func readImageConfig(ctx context.Context, img image.Image) (*Config, error) { return config, nil } +// SetupContext sets up context.Context to not log warnings on onmetal media types. +func SetupContext(ctx context.Context) context.Context { + ctx = remotes.WithMediaTypeKeyPrefix(ctx, ConfigMediaType, "config-") + ctx = remotes.WithMediaTypeKeyPrefix(ctx, RootFSLayerMediaType, "layer-") + ctx = remotes.WithMediaTypeKeyPrefix(ctx, InitRAMFSLayerMediaType, "layer-") + ctx = remotes.WithMediaTypeKeyPrefix(ctx, KernelLayerMediaType, "layer-") + return ctx +} + // ResolveImage resolves an oci image to an onmetal Image. func ResolveImage(ctx context.Context, ociImg image.Image) (*Image, error) { + ctx = SetupContext(ctx) + config, err := readImageConfig(ctx, ociImg) if err != nil { return nil, err diff --git a/image_test.go b/image_test.go index 9f50dec..9be4810 100644 --- a/image_test.go +++ b/image_test.go @@ -1,4 +1,4 @@ -package onmetal_image_test +package onmetalimage_test import ( "context" diff --git a/onmetal_image_suite_test.go b/onmetal_image_suite_test.go index cd84a58..6606b0e 100644 --- a/onmetal_image_suite_test.go +++ b/onmetal_image_suite_test.go @@ -1,4 +1,4 @@ -package onmetal_image_test +package onmetalimage_test import ( "testing"