diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c9386f..8820b3c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,8 +30,6 @@ jobs: head_ref: ${{ github.head_ref }} - name: Cleanup run: make cleanup - - name: Generate wire - run: make wire - name: Vendor run: make vendor - name: Build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d0b3d4f..743719c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,14 +17,12 @@ jobs: uses: actions/checkout@v2 - name: Cleanup run: make cleanup - - name: Generate wire - run: make wire - name: Vendor run: make vendor - - name: Test - run: make test - name: Lint run: make lint + - name: Test + run: make test - name: Send code coverage report uses: codecov/codecov-action@v1 with: diff --git a/.gitignore b/.gitignore index 3829777..0b75afc 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,3 @@ /bin/* coverage.out -wire_gen.go -*packr.go diff --git a/Makefile b/Makefile index 14b7d04..2ec3409 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ override APP_NAME=inizio override GO_VERSION=1.16 -override PROTOC_VERSION=3.1.32 -override MOCKERY_VERSION=v2.7.1 -override GOLANGCI_LINT_VERSION=v1.38.0 +override GOLANGCI_LINT_VERSION=v1.39.0 override SECUREGO_GOSEC_VERSION=v2.7.0 -override HADOLINT_VERSION=v1.23.0 +override HADOLINT_VERSION=v2.2.0 +override WIRE_VERSION=v0.5.0 +override PROTOC_VERSION=3.1.33 +override MOCKERY_VERSION=v2.7.4 override CHANGELOG_GENERATOR_VERSION=1.15.2 GOOS?=$(shell go env GOOS || echo linux) @@ -20,7 +21,7 @@ $(error "Binary docker not found in $(PATH)") endif .PHONY: all -all: cleanup wire vendor lint test build +all: cleanup vendor lint test build # --- [ CI helpers ] --------------------------------------------------------------------------------------------------- @@ -28,23 +29,8 @@ all: cleanup wire vendor lint test build cleanup: @rm ${PWD}/bin/${APP_NAME} || true @rm ${PWD}/coverage.out || true - @find ${PWD} -type f -name "wire_gen.go" -delete @rm -r ${PWD}/vendor || true -.PHONY: wire -wire: - @docker build \ - --build-arg GO_VERSION=${GO_VERSION} \ - -f ${PWD}/build/docker/utils/wire/Dockerfile \ - -t wire:custom \ - build/docker/utils/wire - @find ${PWD} -type f -name "wire_gen.go" -delete - @docker run --rm \ - -v ${PWD}:/project \ - -w /project \ - wire:custom \ - /project/... - .PHONY: vendor vendor: @rm -r ${PWD}/vendor || true @@ -133,6 +119,21 @@ build: # --- [ Local helpers ] ------------------------------------------------------------------------------------------------ +.PHONY: wire +wire: + @docker build \ + --build-arg GO_VERSION=${GO_VERSION} \ + --build-arg WIRE_VERSION=${WIRE_VERSION} \ + -f ${PWD}/build/docker/utils/wire/Dockerfile \ + -t wire:custom \ + build/docker/utils/wire + @find ${PWD} -type f -name "wire_gen.go" -delete + @docker run --rm \ + -v ${PWD}:/project \ + -w /project \ + wire:custom \ + /project/... + .PHONY: protoc protoc: $(shell find api/protobuf -type f -name "*.proto") @find ${PWD}/internal -type f -name "*.pb.go" -delete diff --git a/build/docker/cmd/inizio/Dockerfile b/build/docker/cmd/inizio/Dockerfile index f9e561e..190e6d8 100644 --- a/build/docker/cmd/inizio/Dockerfile +++ b/build/docker/cmd/inizio/Dockerfile @@ -1,17 +1,6 @@ ARG GO_VERSION=1.16 ARG ALPINE_VERSION=3.12 -### Wire -FROM golang:${GO_VERSION} as wire -ARG WIRE_VERSION=v0.5.0 -RUN GO111MODULE=on go get -u -t github.com/google/wire/cmd/wire@${WIRE_VERSION} -COPY . /project -WORKDIR /project -RUN find . -not -path "./vendor/*" -type f -name "wire_gen.go" -delete \ - && /go/bin/wire ./... \ - && mkdir -p /usr/local/src/wire \ - && find . -not -path "./vendor/*" -type f -name "wire_gen.go" -exec cp --parents {} /usr/local/src/wire \; - ### Vendor FROM golang:${GO_VERSION} as vendor COPY . /project @@ -22,7 +11,6 @@ RUN go mod tidy && \ ### Build binary FROM golang:${GO_VERSION} as build-binary COPY . /project -COPY --from=wire /usr/local/src/wire /project COPY --from=vendor /project/vendor /project/vendor WORKDIR /project RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GO111MODULE=on go build \ diff --git a/build/docker/utils/wire/Dockerfile b/build/docker/utils/wire/Dockerfile index c1fb987..1a6394e 100644 --- a/build/docker/utils/wire/Dockerfile +++ b/build/docker/utils/wire/Dockerfile @@ -2,5 +2,6 @@ ARG GO_VERSION=1.16 ### Image FROM golang:${GO_VERSION} -RUN go get -u -t github.com/google/wire/cmd/wire +ARG WIRE_VERSION=v0.5.0 +RUN go get -u -t github.com/google/wire/cmd/wire@${WIRE_VERSION} ENTRYPOINT ["/go/bin/wire"] diff --git a/cmd/inizio/internal/wire_gen.go b/cmd/inizio/internal/wire_gen.go new file mode 100644 index 0000000..152e0ff --- /dev/null +++ b/cmd/inizio/internal/wire_gen.go @@ -0,0 +1,72 @@ +// Code generated by Wire. DO NOT EDIT. + +//go:generate go run github.com/google/wire/cmd/wire +//+build !wireinject + +package internal + +import ( + "context" + "github.com/insidieux/inizio/internal/builtin/layout" + "github.com/insidieux/inizio/internal/plugins" + "github.com/spf13/afero" + "github.com/spf13/pflag" +) + +// Injectors from wire.go: + +func newCore(contextContext context.Context, flagSet *pflag.FlagSet) (*core, func(), error) { + boxDirectory := _wireBoxDirectoryValue + readFileFS, err := layout.ProvideEmbedFS(boxDirectory) + if err != nil { + return nil, nil, err + } + fs := afero.NewOsFs() + boxInterface := layout.NewBox(readFileFS, fs) + templateInterface := provideTemplate() + rendererInterface := layout.NewRenderer(boxInterface, templateInterface) + viper, err := provideCommandViper(flagSet) + if err != nil { + return nil, nil, err + } + internalLayoutCleanup := provideLayoutCleanup(viper) + internalLayoutTemplateDockerfile, err := provideLayoutTemplateDockerfile(viper) + if err != nil { + return nil, nil, err + } + internalLayoutTemplateMakefile, err := provideLayoutTemplateMakefile(viper) + if err != nil { + return nil, nil, err + } + v := provideGeneratorOptions(internalLayoutCleanup, internalLayoutTemplateDockerfile, internalLayoutTemplateMakefile) + generator := layout.NewGenerator(rendererInterface, fs, v...) + internalPluginsConfigPath := providePluginsConfigPath(viper) + configInterface, err := providePluginsConfig(fs, internalPluginsConfigPath) + if err != nil { + return nil, nil, err + } + level, err := provideLoggerLevel(viper) + if err != nil { + return nil, nil, err + } + fieldLogger := provideLogger(level) + loader := plugins.NewLoader(configInterface, fs, fieldLogger) + internalPluginsPath, err := providePluginsPath(viper) + if err != nil { + return nil, nil, err + } + v2, err := provideRegistryClients(contextContext, loader, internalPluginsPath) + if err != nil { + return nil, nil, err + } + internalRegistryFailFast := provideRegistryFailFast(viper) + registryInterface, cleanup := provideRegistry(v2, fieldLogger, internalRegistryFailFast) + internalCore := provideCore(generator, registryInterface, fieldLogger) + return internalCore, func() { + cleanup() + }, nil +} + +var ( + _wireBoxDirectoryValue = layout.BoxDirectory(layout.EmbedDirectory) +) diff --git a/cmd/inizio/main.go b/cmd/inizio/main.go index 5c67607..d33f687 100644 --- a/cmd/inizio/main.go +++ b/cmd/inizio/main.go @@ -10,7 +10,8 @@ import ( ) func main() { - ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer stop() if err := internal.NewCommand().ExecuteContext(ctx); err != nil { logger.GetLogger().Fatalf(`Failed to execute command: %s`, err.Error()) } diff --git a/internal/builtin/layout/embed/Makefile.gotmpl b/internal/builtin/layout/embed/Makefile.gotmpl index 9113662..82fd154 100644 --- a/internal/builtin/layout/embed/Makefile.gotmpl +++ b/internal/builtin/layout/embed/Makefile.gotmpl @@ -1,8 +1,8 @@ override APP_NAME={{ .Application.Name | lower }} {{ $version := semver (.Golang.Version | default "1.16") }}override GO_VERSION={{ $version.Major }}.{{ $version.Minor }} -override GOLANGCI_LINT_VERSION=v1.38.0 +override GOLANGCI_LINT_VERSION=v1.39.0 override SECUREGO_GOSEC_VERSION=v2.7.0 -override HADOLINT_VERSION=v1.23.0 +override HADOLINT_VERSION=v2.2.0 GOOS?=$(shell go env GOOS || echo linux) GOARCH?=$(shell go env GOARCH || echo amd64)