Skip to content

Commit

Permalink
Refactor project structure (#16)
Browse files Browse the repository at this point in the history
* Restructure codebase to conform golang project layout

Signed-off-by: Henry Wang <[email protected]>

* refactor internal/backend to split out different areas of functionality

Signed-off-by: Henry Wang <[email protected]>

---------

Signed-off-by: Henry Wang <[email protected]>
  • Loading branch information
henry118 authored Aug 28, 2024
1 parent 183581a commit 747f025
Show file tree
Hide file tree
Showing 243 changed files with 1,140 additions and 1,052 deletions.
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build::
$(eval PACKAGE := github.com/runfinch/finch-daemon)
$(eval VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.modified' --always --tags))
$(eval GITCOMMIT := $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi))
$(eval LDFLAGS := "-X $(PACKAGE)/pkg/version.Version=$(VERSION) -X $(PACKAGE)/pkg/version.GitCommit=$(GITCOMMIT)")
$(eval LDFLAGS := "-X $(PACKAGE)/version.Version=$(VERSION) -X $(PACKAGE)/version.GitCommit=$(GITCOMMIT)")
GOOS=linux go build -ldflags $(LDFLAGS) -v -o bin/finch-daemon $(PACKAGE)/cmd/finch-daemon

# Linux targets
Expand Down Expand Up @@ -45,14 +45,14 @@ code-gen: linux
GOBIN=$(BIN) go install github.com/golang/mock/mockgen
GOBIN=$(BIN) go install golang.org/x/tools/cmd/stringer
PATH=$(BIN):$(PATH) go generate ./...
PATH=$(BIN):$(PATH) mockgen --destination=./pkg/mocks/mocks_container/container.go -package=mocks_container github.com/containerd/containerd Container
PATH=$(BIN):$(PATH) mockgen --destination=./pkg/mocks/mocks_container/process.go -package=mocks_container github.com/containerd/containerd Process
PATH=$(BIN):$(PATH) mockgen --destination=./pkg/mocks/mocks_container/task.go -package=mocks_container github.com/containerd/containerd Task
PATH=$(BIN):$(PATH) mockgen --destination=./pkg/mocks/mocks_image/store.go -package=mocks_image github.com/containerd/containerd/images Store
PATH=$(BIN):$(PATH) mockgen --destination=./pkg/mocks/mocks_container/network_manager.go -package=mocks_container github.com/containerd/nerdctl/pkg/containerutil NetworkOptionsManager
PATH=$(BIN):$(PATH) mockgen --destination=./pkg/mocks/mocks_cio/io.go -package=mocks_cio github.com/containerd/containerd/cio IO
PATH=$(BIN):$(PATH) mockgen --destination=./pkg/mocks/mocks_http/response_writer.go -package=mocks_http net/http ResponseWriter
PATH=$(BIN):$(PATH) mockgen --destination=./pkg/mocks/mocks_http/conn.go -package=mocks_http net Conn
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_container/container.go -package=mocks_container github.com/containerd/containerd Container
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_container/process.go -package=mocks_container github.com/containerd/containerd Process
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_container/task.go -package=mocks_container github.com/containerd/containerd Task
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_image/store.go -package=mocks_image github.com/containerd/containerd/images Store
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_container/network_manager.go -package=mocks_container github.com/containerd/nerdctl/pkg/containerutil NetworkOptionsManager
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_cio/io.go -package=mocks_cio github.com/containerd/containerd/cio IO
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_http/response_writer.go -package=mocks_http net/http ResponseWriter
PATH=$(BIN):$(PATH) mockgen --destination=./mocks/mocks_http/conn.go -package=mocks_http net Conn

GOLINT=$(BIN)/golangci-lint
$(GOLINT): linux
Expand All @@ -64,7 +64,7 @@ golint: linux $(GOLINT)

.PHONY: run-unit-tests
run-unit-tests: linux
$(GINKGO) $(GFLAGS) ./pkg/...
$(GINKGO) $(GFLAGS) ./...

# Runs tests in headless dlv mode, must specify package directory with PKG_DIR
PKG_DIR ?= .
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions api/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Package api provides types and interfaces that can be used by
// client-side software to communicate with finch daemon.
// It currently implements the Docker API Spec v1.43.
package api
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/containerd/containerd/namespaces"
"github.com/containerd/nerdctl/pkg/api/types"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/pkg/utility/maputility"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/mocks/mocks_backend"
"github.com/runfinch/finch-daemon/mocks/mocks_builder"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_backend"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_builder"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
)

var _ = Describe("Build API", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
ncTypes "github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/config"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/pkg/backend"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/internal/backend"
"github.com/runfinch/finch-daemon/pkg/flog"
)

Expand All @@ -30,7 +30,7 @@ func RegisterHandlers(r types.VersionedRouter,

// Service interface for build related APIs
//
//go:generate mockgen --destination=../../../mocks/mocks_builder/buildersvc.go -package=mocks_builder github.com/runfinch/finch-daemon/pkg/api/handlers/builder Service
//go:generate mockgen --destination=../../../mocks/mocks_builder/buildersvc.go -package=mocks_builder github.com/runfinch/finch-daemon/api/handlers/builder Service
type Service interface {
Build(ctx context.Context, options *ncTypes.BuilderBuildOptions, tarBody io.ReadCloser) ([]types.BuildResult, error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_backend"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_builder"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/mocks/mocks_backend"
"github.com/runfinch/finch-daemon/mocks/mocks_builder"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
)

// TestBuilderHandler function is the entry point of builder handler package's unit test using ginkgo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/moby/moby/api/server/httputils"
"github.com/moby/moby/api/types/versions"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import (
"github.com/gorilla/mux"
"github.com/moby/moby/api/server/httputils"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/types"

"github.com/containerd/nerdctl/pkg/config"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pkg/errors"

"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_http"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_http"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"

hj "github.com/getlantern/httptest"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
ncTypes "github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/config"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/pkg/flog"
)

//go:generate mockgen --destination=../../../mocks/mocks_container/containersvc.go -package=mocks_container github.com/runfinch/finch-daemon/pkg/api/handlers/container Service
//go:generate mockgen --destination=../../../mocks/mocks_container/containersvc.go -package=mocks_container github.com/runfinch/finch-daemon/api/handlers/container Service
type Service interface {
GetPathToFilesInContainer(ctx context.Context, cid string, path string) (string, func(), error)
Remove(ctx context.Context, cid string, force, removeVolumes bool) error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
)

// TestContainerHandler function is the entry point of container handler package's unit test using ginkgo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/docker/go-connections/nat"
"github.com/sirupsen/logrus"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
)

var _ = Describe("Container Create API ", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/containerd/containerd/namespaces"
"github.com/gorilla/mux"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
)

var _ = Describe("Container Exec API ", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/gorilla/mux"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
)

var _ = Describe("Container Get Archive API", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
)

var _ = Describe("Container Inspect API", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/containerd/containerd/namespaces"
ncTypes "github.com/containerd/nerdctl/pkg/api/types"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/api/response"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
)

var _ = Describe("Container List API", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/gorilla/mux"
"github.com/moby/moby/api/server/httputils"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"

hj "github.com/getlantern/httptest"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/gorilla/mux"
"github.com/moby/moby/api/server/httputils"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/pkg/api/types"
"github.com/runfinch/finch-daemon/api/types"
"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
)

var _ = Describe("Container Put Archive API", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
)

var _ = Describe("Container Remove API", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/runfinch/finch-daemon/mocks/mocks_container"
"github.com/runfinch/finch-daemon/mocks/mocks_logger"
"github.com/runfinch/finch-daemon/pkg/errdefs"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_container"
"github.com/runfinch/finch-daemon/pkg/mocks/mocks_logger"
)

var _ = Describe("Container Rename API ", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"

"github.com/runfinch/finch-daemon/pkg/api/response"
"github.com/runfinch/finch-daemon/api/response"
"github.com/runfinch/finch-daemon/pkg/errdefs"
)

Expand Down
Loading

0 comments on commit 747f025

Please sign in to comment.