Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
VERSION=$(shell git describe --tags --always)
include common.mk

VERSION=$(shell git describe --tags --always)
API_PROTO_FILES=$(shell find api -name *.proto)

.PHONY: init
# init env
init:
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30.0
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0
go install github.com/envoyproxy/protoc-gen-validate@v1.0.1
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
go install github.com/google/wire/cmd/wire@latest
go install github.com/vektra/mockery/v2@v2.20.0
go install ariga.io/atlas/cmd/atlas@v0.12.0
go install github.com/bufbuild/buf/cmd/buf@v1.10.0

.PHONY: api
# generate api proto
api:
Expand Down Expand Up @@ -54,22 +42,3 @@ lint:
# All tests, both unit and integration
test:
go test ./...

# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help
29 changes: 5 additions & 24 deletions app/artifact-cas/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
VERSION=$(shell git describe --tags --always)
include ../../common.mk

.PHONY: config
# generate config proto
config:
config: check-buf-tool
cd ./internal/conf && buf generate

.PHONY: api
# generate api proto
api:
api: check-buf-tool
cd ./api && buf generate

.PHONY: build
Expand All @@ -30,37 +30,18 @@ test:

.PHONY: lint
# lint
lint:
lint: check-golangci-lint-tool check-buf-tool
golangci-lint run
buf lint api
buf lint internal/conf

.PHONY: generate
# generate
generate:
generate: check-wire-tool api config
go generate ./...

.PHONY: all
# generate all
all:
make config;
make generate;

# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help
9 changes: 6 additions & 3 deletions app/artifact-cas/internal/service/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
v1 "github.com/chainloop-dev/chainloop/app/artifact-cas/api/cas/v1"
backend "github.com/chainloop-dev/chainloop/internal/blobmanager"
sl "github.com/chainloop-dev/chainloop/internal/servicelogger"
"github.com/go-kratos/kratos/v2/errors"
)

type ResourceService struct {
Expand All @@ -41,13 +42,15 @@ func (s *ResourceService) Describe(ctx context.Context, req *v1.ResourceServiceD
return nil, err
}

backend, err := s.backendP.FromCredentials(ctx, info.StoredSecretID)
b, err := s.backendP.FromCredentials(ctx, info.StoredSecretID)
if err != nil {
return nil, sl.LogAndMaskErr(err, s.log)
}

res, err := backend.Describe(ctx, req.Digest)
if err != nil {
res, err := b.Describe(ctx, req.Digest)
if err != nil && backend.IsNotFound(err) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we now check if the error is not found

return nil, errors.NotFound("not found", err.Error())
} else if err != nil {
return nil, sl.LogAndMaskErr(err, s.log)
}

Expand Down
2 changes: 1 addition & 1 deletion app/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
}
}

// handle predefinided errors and handle types so we can tailor the experience
// handle predefined errors and handle types so we can tailor the experience
func errorInfo(err error, logger zerolog.Logger) (string, int) {
var msg string
exitCode := 1
Expand Down
33 changes: 7 additions & 26 deletions app/controlplane/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
VERSION=$(shell git describe --tags --always)
include ../../common.mk

.PHONY: config
# generate config proto bindings
config:
config: check-buf-tool
cd ./internal/conf && buf generate

.PHONY: api
# generate api proto bindings
api:
api: check-buf-tool
cd ./api && buf generate

.PHONY: build
Expand All @@ -28,13 +28,13 @@ local_db = postgres://postgres:@localhost:5432/controlplane?sslmode=disable

.PHONY: migration_apply
# run migrations against local db
migration_apply:
migration_apply: check-atlas-tool
atlas migrate status --dir ${local_migrations_dir} --url ${local_db}
atlas migrate apply --dir ${local_migrations_dir} --url ${local_db}

.PHONY: migration_new
# generate new migration if needed from the current ent schema
migration_new:
migration_new: check-atlas-tool
atlas migrate diff --dir ${local_migrations_dir} --to "ent://internal/data/ent/schema" --dev-url "docker://postgres/15/test?search_path=public"

.PHONY: test
Expand All @@ -49,14 +49,14 @@ test-unit:

.PHONY: lint
# lint
lint:
lint: check-golangci-lint-tool check-buf-tool
buf lint api
buf lint internal/conf
golangci-lint run

.PHONY: generate
# generate proto bindings, wire injectors, and ent models
generate: api config
generate: check-wire-tool api config
go generate ./...

.PHONY: all
Expand All @@ -69,22 +69,3 @@ all:
# Visualize data model
visualize-data-model:
xdg-open internal/data/ent/schema-viz.html

# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help
62 changes: 62 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
VERSION=$(shell git describe --tags --always)

.PHONY: init
# init env
init:
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.30.0
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0
go install github.com/envoyproxy/protoc-gen-validate@v1.0.1
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
go install github.com/google/wire/cmd/wire@latest
go install github.com/vektra/mockery/v2@v2.20.0
go install ariga.io/atlas/cmd/atlas@v0.12.0
go install github.com/bufbuild/buf/cmd/buf@v1.10.0

# show help
help:
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

.DEFAULT_GOAL := help

.PHONY: check-goreleaser-tool
check-atlas-tool:
@if ! command -v atlas >/dev/null 2>&1; then \
echo "altas is not installed. Please run \"make init\" or install the tool manually."; \
exit 1; \
fi

.PHONY: check-wire-tool
check-wire-tool:
@if ! command -v wire >/dev/null 2>&1; then \
echo "wire is not installed. Please run \"make init\" or install the tool manually."; \
exit 1; \
fi

.PHONY: check-golangci-lint-tool
check-golangci-lint-tool:
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "golangci-lint is not installed. Please run \"make init\" or install the tool manually."; \
exit 1; \
fi

.PHONY: check-buf-tool
check-buf-tool:
@if ! command -v buf >/dev/null 2>&1; then \
echo "buf is not installed. Please run \"make init\" or install the tool manually."; \
exit 1; \
fi

37 changes: 37 additions & 0 deletions internal/blobmanager/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Copyright 2023 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package backend

import (
"errors"
"fmt"
)

type ErrNotFound struct {
entity string
}

func NewErrNotFound(entity string) ErrNotFound {
return ErrNotFound{entity}
}

func (e ErrNotFound) Error() string {
return fmt.Sprintf("%s not found", e.entity)
}

func IsNotFound(err error) bool {
return errors.As(err, &ErrNotFound{})
}
9 changes: 8 additions & 1 deletion internal/blobmanager/oci/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ import (
"github.com/google/go-containerregistry/pkg/v1/empty"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
"github.com/google/go-containerregistry/pkg/v1/static"
"github.com/google/go-containerregistry/pkg/v1/types"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"

pb "github.com/chainloop-dev/chainloop/app/artifact-cas/api/cas/v1"
backend "github.com/chainloop-dev/chainloop/internal/blobmanager"
)

type Backend struct {
Expand Down Expand Up @@ -185,6 +187,11 @@ func (b *Backend) Describe(_ context.Context, digest string) (*pb.CASResource, e

img, err := remote.Image(ref, remote.WithAuthFromKeychain(b.keychain))
if err != nil {
var e *transport.Error
if errors.As(err, &e) && e.StatusCode == http.StatusNotFound {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the way we bubble up the not found error

return nil, backend.NewErrNotFound("image")
}

return nil, fmt.Errorf("getting image: %w", err)
}

Expand All @@ -197,7 +204,7 @@ func (b *Backend) Describe(_ context.Context, digest string) (*pb.CASResource, e
return nil, fmt.Errorf("extracting manifest: %w", err)
}

// Valirate image already checked that the manifest has exactly one layer
// Validate image already checked that the manifest has exactly one layer
size := manifest.Layers[0].Size

filename, ok := manifest.Annotations[ocispec.AnnotationTitle]
Expand Down
2 changes: 1 addition & 1 deletion internal/blobmanager/oci/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *testSuite) TestDescribe() {
name: "not found",
digest: "deadbeef",
wantErr: true,
errMsg: "Unknown name",
errMsg: "not found",
},
{
name: "valid image",
Expand Down