Skip to content

Commit

Permalink
feat: add CreateRepositoryTag endpoint (#8)
Browse files Browse the repository at this point in the history
Because

- Distribution registry doesn't hold digest or timestamp info for tags

This commit

- Implements the tag creation endpoint in `artifact-backend`, which will
be used by `api-gateway` when it detects an image push has finished
successfully.
  • Loading branch information
jvallesm authored Apr 1, 2024
1 parent 6cc2d8d commit 61bc325
Show file tree
Hide file tree
Showing 14 changed files with 581 additions and 151 deletions.
2 changes: 1 addition & 1 deletion cmd/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func main() {
reflection.Register(publicGrpcS)
artifactPB.RegisterArtifactPublicServiceServer(
publicGrpcS,
handler.NewPublicHandler(ctx, service),
handler.NewPublicHandler(ctx),
)

privateGrpcS := grpc.NewServer(grpcServerOpts...)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0
github.com/influxdata/influxdb-client-go/v2 v2.12.3
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240326081344-9f99c3127134
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240327112131-e593145f363a
github.com/instill-ai/usage-client v0.2.4-alpha.0.20240123081026-6c78d9a5197a
github.com/instill-ai/x v0.3.0-alpha.0.20231219052200-6230a89e386c
github.com/knadh/koanf v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ github.com/influxdata/influxdb-client-go/v2 v2.12.3 h1:28nRlNMRIV4QbtIUvxhWqaxn0
github.com/influxdata/influxdb-client-go/v2 v2.12.3/go.mod h1:IrrLUbCjjfkmRuaCiGQg4m2GbkaeJDcuWoxiWdQEbA0=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240326081344-9f99c3127134 h1:7EiXVSm6qMcFIWDXz3o6RsR26wqBdXQGxcjoDfrddm0=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240326081344-9f99c3127134/go.mod h1:lYlHty9DgagOIvnLifXZ40dO+N/xMh4uKLIelLNnPUI=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240327112131-e593145f363a h1:k4tq5qQQABKiQ7uuEN2K54jnx3eVaW/PQpZXBU/SGdQ=
github.com/instill-ai/protogen-go v0.3.3-alpha.0.20240327112131-e593145f363a/go.mod h1:jhEL0SauySMoPLVvx105DWyThju9sYTbsXIySVCArmM=
github.com/instill-ai/usage-client v0.2.4-alpha.0.20240123081026-6c78d9a5197a h1:gmy8BcCFDZQan40c/D3f62DwTYtlCwi0VrSax+pKffw=
github.com/instill-ai/usage-client v0.2.4-alpha.0.20240123081026-6c78d9a5197a/go.mod h1:EpX3Yr661uWULtZf5UnJHfr5rw2PDyX8ku4Kx0UtYFw=
github.com/instill-ai/x v0.3.0-alpha.0.20231219052200-6230a89e386c h1:a2RVkpIV2QcrGnSHAou+t/L+vBsaIfFvk5inVg5Uh4s=
Expand Down
88 changes: 0 additions & 88 deletions pkg/handler/handler.go

This file was deleted.

63 changes: 63 additions & 0 deletions pkg/handler/private.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package handler

import (
"context"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"

"github.com/instill-ai/artifact-backend/pkg/logger"
artifact "github.com/instill-ai/artifact-backend/pkg/service"
pb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha"
)

var tracer = otel.Tracer("artifact-backend.private-handler.tracer")

// PrivateHandler handles the private Artifact endpoints.
type PrivateHandler struct {
pb.UnimplementedArtifactPrivateServiceServer
service *artifact.Service
}

// NewPrivateHandler returns an initialized private handler.
func NewPrivateHandler(_ context.Context, s *artifact.Service) pb.ArtifactPrivateServiceServer {
return &PrivateHandler{
service: s,
}
}

// ListRepositoryTags returns the versions of a distribution registry
// repository.
func (h *PrivateHandler) ListRepositoryTags(ctx context.Context, req *pb.ListRepositoryTagsRequest) (*pb.ListRepositoryTagsResponse, error) {
ctx, span := tracer.Start(ctx, "ListRepositoryTags", trace.WithSpanKind(trace.SpanKindServer))
defer span.End()

logger, _ := logger.GetZapLogger(ctx)

resp, err := h.service.ListRepositoryTags(ctx, req)
if err != nil {
span.SetStatus(1, err.Error())
return nil, err
}

logger.Info("ListRepositoryTags")
return resp, nil
}

// CreateRepositoryTag registers the information of a repository tag after it
// has been pushed to the registry.
func (h *PrivateHandler) CreateRepositoryTag(ctx context.Context, req *pb.CreateRepositoryTagRequest) (*pb.CreateRepositoryTagResponse, error) {
ctx, span := tracer.Start(ctx, "CreateRepositoryTag", trace.WithSpanKind(trace.SpanKindServer))
defer span.End()

logger, _ := logger.GetZapLogger(ctx)

resp, err := h.service.CreateRepositoryTag(ctx, req)
if err != nil {
span.SetStatus(1, err.Error())
return nil, err
}

logger.Info("CreateRepositoryTag")
return resp, nil
}
36 changes: 36 additions & 0 deletions pkg/handler/public.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package handler

import (
"context"

artifactpb "github.com/instill-ai/protogen-go/artifact/artifact/v1alpha"
healthcheckPB "github.com/instill-ai/protogen-go/common/healthcheck/v1beta"
)

// PublicHandler handles public API
type PublicHandler struct {
artifactpb.UnimplementedArtifactPublicServiceServer
}

// NewPublicHandler initiates a handler instance
func NewPublicHandler(_ context.Context) artifactpb.ArtifactPublicServiceServer {
return &PublicHandler{}
}

// Liveness returns the health of the service.
func (h *PublicHandler) Liveness(_ context.Context, _ *artifactpb.LivenessRequest) (*artifactpb.LivenessResponse, error) {
return &artifactpb.LivenessResponse{
HealthCheckResponse: &healthcheckPB.HealthCheckResponse{
Status: healthcheckPB.HealthCheckResponse_SERVING_STATUS_SERVING,
},
}, nil
}

// Readiness returns the state of the service.
func (h *PublicHandler) Readiness(_ context.Context, _ *artifactpb.ReadinessRequest) (*artifactpb.ReadinessResponse, error) {
return &artifactpb.ReadinessResponse{
HealthCheckResponse: &healthcheckPB.HealthCheckResponse{
Status: healthcheckPB.HealthCheckResponse_SERVING_STATUS_SERVING,
},
}, nil
}
Loading

0 comments on commit 61bc325

Please sign in to comment.