Skip to content

Commit

Permalink
Remove signalcontext, rename main module to onmetalimage
Browse files Browse the repository at this point in the history
  • Loading branch information
adracus committed Feb 7, 2023
1 parent 3374851 commit 717dfb0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 25 deletions.
12 changes: 0 additions & 12 deletions cmd/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
15 changes: 8 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 13 additions & 1 deletion image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion image_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package onmetal_image_test
package onmetalimage_test

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion onmetal_image_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package onmetal_image_test
package onmetalimage_test

import (
"testing"
Expand Down

0 comments on commit 717dfb0

Please sign in to comment.