diff --git a/Makefile b/Makefile index 8cee17b..90bd148 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,11 @@ golint: linux $(GOLINT) run-unit-tests: linux $(GINKGO) $(GFLAGS) ./... +.PHONY: licenses +licenses: + GOBIN=$(BIN) go install github.com/google/go-licenses@latest + PATH=$(BIN):$(PATH) go-licenses report --template="scripts/third-party-license.tpl" --ignore github.com/runfinch ./... > THIRD_PARTY_LICENSES + # Runs tests in headless dlv mode, must specify package directory with PKG_DIR PKG_DIR ?= . .PHONY: debug-unit-tests diff --git a/go.mod b/go.mod index 24aa49c..6ffb988 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/runfinch/finch-daemon -go 1.22.7 +go 1.22 require ( github.com/containerd/cgroups/v3 v3.0.3 diff --git a/internal/service/builder/build.go b/internal/service/builder/build.go index d3dfe3d..e917936 100644 --- a/internal/service/builder/build.go +++ b/internal/service/builder/build.go @@ -9,6 +9,7 @@ import ( "context" "fmt" "io" + "strings" ncTypes "github.com/containerd/nerdctl/pkg/api/types" @@ -18,6 +19,7 @@ import ( ) const tagEventAction = "tag" +const shortLen = 12 // setting publishTagEventFunc as a variable to allow mocking this function for unit testing. var publishTagEventFunc = (*service).publishTagEvent @@ -92,7 +94,7 @@ func tagTopic() string { func getTagEvent(digest, imgName string) *events.Event { return &events.Event{ - ID: digest, + ID: truncateID(digest), // for docker compatibility Status: tagEventAction, Type: "image", Action: tagEventAction, @@ -104,3 +106,13 @@ func getTagEvent(digest, imgName string) *events.Event { }, } } + +func truncateID(id string) string { + if i := strings.IndexRune(id, ':'); i >= 0 { + id = id[i+1:] + } + if len(id) > shortLen { + id = id[:shortLen] + } + return id +} diff --git a/internal/service/image/load.go b/internal/service/image/load.go index febd5a4..7c7ea49 100644 --- a/internal/service/image/load.go +++ b/internal/service/image/load.go @@ -42,11 +42,16 @@ func (s *service) Load(ctx context.Context, inStream io.Reader, outStream io.Wri return err } defer func() { - rw.Close() os.Remove(img) }() go func() { - io.Copy(rw, inStream) + written, err := io.Copy(rw, inStream) + if err != nil { + s.logger.Errorf("failed to copy: %s", err) + } else { + s.logger.Debugf("copied %d bytes", written) + } + rw.Close() }() if err = s.nctlImageSvc.LoadImage(ctx, img, outStream, quiet); err != nil { s.logger.Errorf("failed to load image %s: %s", img, err) diff --git a/internal/service/image/load_test.go b/internal/service/image/load_test.go index f6fc394..14e149f 100644 --- a/internal/service/image/load_test.go +++ b/internal/service/image/load_test.go @@ -46,26 +46,28 @@ var _ = Describe("Image Load API", func() { Return(name, nil) ncClient.EXPECT().LoadImage(gomock.Any(), gomock.Any(), nil, gomock.Any()). Return(nil) + logger.EXPECT().Debugf(gomock.Any(), gomock.Any()) // service should return no error err := service.Load(ctx, inStream, nil, false) Expect(err).Should(BeNil()) }) It("should return an error if load image method returns an error", func() { - logger.EXPECT().Errorf(gomock.Any(), gomock.Any()) ncClient.EXPECT().GetDataStore(). Return(name, nil) + logger.EXPECT().Debugf(gomock.Any(), gomock.Any()) ncClient.EXPECT().LoadImage(gomock.Any(), gomock.Any(), nil, gomock.Any()). Return(errors.New("error message")) + logger.EXPECT().Errorf(gomock.Any(), gomock.Any()) // service should return an error err := service.Load(ctx, inStream, nil, false) Expect(err).ShouldNot(BeNil()) }) It("should return an error if get datastore method returns an error", func() { - logger.EXPECT().Errorf(gomock.Any(), gomock.Any()) ncClient.EXPECT().GetDataStore(). Return(name, errors.New("error message")) + logger.EXPECT().Errorf(gomock.Any(), gomock.Any()) // service should return an error err := service.Load(ctx, inStream, nil, false) diff --git a/internal/service/network/create.go b/internal/service/network/create.go index 55ced55..031718d 100644 --- a/internal/service/network/create.go +++ b/internal/service/network/create.go @@ -38,6 +38,8 @@ func (s *service) Create(ctx context.Context, request types.NetworkCreateRequest if v != "0.0.0.0" { s.logger.Warnf("network option com.docker.network.bridge.host_binding_ipv4 is set to %s, but it must be 0.0.0.0", v) } + case "com.docker.network.bridge.enable_icc": + s.logger.Warnf("network option com.docker.network.bridge.enable_icc is not currently supported in nerdctl", v) case "com.docker.network.bridge.name": bridge = v default: diff --git a/scripts/third-party-license.tpl b/scripts/third-party-license.tpl new file mode 100644 index 0000000..7b1a266 --- /dev/null +++ b/scripts/third-party-license.tpl @@ -0,0 +1,7 @@ +{{ range . -}} +-------------------------------------------------------------------------------- +** {{.Name}}; version {{.Version}} - https://{{.Name}} + +{{ .LicenseText }} + +{{end -}}