Skip to content

Commit

Permalink
Merge branch 'runfinch:main' into add-api-allowlisting
Browse files Browse the repository at this point in the history
  • Loading branch information
sondavidb authored Sep 14, 2024
2 parents 9705a05 + 26d1c7d commit 109020c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 13 additions & 1 deletion internal/service/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"fmt"
"io"
"strings"

ncTypes "github.com/containerd/nerdctl/pkg/api/types"

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
9 changes: 7 additions & 2 deletions internal/service/image/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions internal/service/image/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/service/network/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions scripts/third-party-license.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{ range . -}}
--------------------------------------------------------------------------------
** {{.Name}}; version {{.Version}} - https://{{.Name}}

{{ .LicenseText }}

{{end -}}

0 comments on commit 109020c

Please sign in to comment.