Skip to content

Commit

Permalink
Draft Tags implementation (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
aatarasoff authored Dec 4, 2023
1 parent d213b8c commit 680db23
Show file tree
Hide file tree
Showing 22 changed files with 997 additions and 171 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+"
- "v[0-9]+.[0-9]+.[0-9]+-wip.[0-9]+"

permissions:
contents: write
Expand Down
3 changes: 3 additions & 0 deletions api/pbuf-registry/v1/entities.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ message Module {

// The tags of the module.
repeated string tags = 3;

// The draft tags of the module.
repeated string draft_tags = 4;
}

// ProtoFile is a proto file registered in the registry.
Expand Down
6 changes: 6 additions & 0 deletions api/pbuf-registry/v1/registry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ message ListModulesResponse {
message GetModuleRequest {
// The name of the module to retrieve.
string name = 1;

// Include draft tags or not
bool include_draft_tags = 2;
}

// PullModuleRequest is the request message for PullModule.
Expand Down Expand Up @@ -142,6 +145,9 @@ message PushModuleRequest {

// Dependencies
repeated Dependency dependencies = 4;

// Is tag a draft
bool is_draft = 5;
}

// DeleteModuleRequest is the request message for DeleteModule.
Expand Down
35 changes: 33 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/log"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/pbufio/pbuf-registry/internal/background"
"github.com/pbufio/pbuf-registry/internal/config"
"github.com/pbufio/pbuf-registry/internal/data"
"github.com/pbufio/pbuf-registry/internal/server"
Expand All @@ -22,6 +23,15 @@ var (
id, _ = os.Hostname()
)

type Launcher struct {
config *config.Config

mainApp *kratos.App
debugApp *kratos.App

compactionDaemon background.CompactionDaemon
}

func main() {
config.NewLoader().MustLoad()

Expand Down Expand Up @@ -51,8 +61,29 @@ func main() {
),
)

err = app.Run()
debugApp := kratos.New(
kratos.ID(id),
kratos.Name(Name),
kratos.Version(Version),
kratos.Metadata(map[string]string{}),
kratos.Logger(logger),
kratos.Server(
server.NewDebugServer(&config.Cfg.Server, logger),
),
)

launcher := &Launcher{
config: config.Cfg,

mainApp: app,
debugApp: debugApp,

compactionDaemon: background.NewCompactionDaemon(registryRepository, logger),
}

err = CreateRootCommand(launcher).Execute()
if err != nil {
logHelper.Errorf("failed to run application: %v", err)
logHelper.Errorf("failed to execute command: %v", err)
return
}
}
64 changes: 64 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"time"

"github.com/go-co-op/gocron"
"github.com/go-kratos/kratos/v2/log"
"github.com/spf13/cobra"
)

func CreateRootCommand(launcher *Launcher) *cobra.Command {
rootCommand := &cobra.Command{
Use: "pbuf-registry",
Short: "Default command to launch main application",
RunE: func(cmd *cobra.Command, args []string) error {
err := launcher.mainApp.Run()
if err != nil {
return err
}

return nil
},
}

rootCommand.AddCommand(CreateCompactionDaemon(launcher))

return rootCommand
}

func CreateCompactionDaemon(launcher *Launcher) *cobra.Command {
compactionDaemonCommand := &cobra.Command{
Use: "compaction",
Short: "Run compaction daemon",
Run: func(cmd *cobra.Command, args []string) {
s := gocron.NewScheduler(time.UTC)

// start every hour
_, err := s.Cron(launcher.config.Daemons.Compaction.CronSchedule).Do(func() {
err := launcher.compactionDaemon.Run()
if err != nil {
log.Fatalf("failed to run compaction daemon: %v", err)
}
})

if err != nil {
log.Fatalf("failed to create cron job: %v", err)
}

// start the scheduler
s.StartAsync()

err = launcher.debugApp.Run()
if err != nil {
log.Fatalf("failed to run debug app: %v", err)
}

s.Stop()

log.Infof("Compaction daemon stopped")
},
}

return compactionDaemonCommand
}
20 changes: 19 additions & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,22 @@ services:
environment:
DATA_DATABASE_DSN: "postgres://pbuf:pbuf@db:5432/pbuf_registry?sslmode=disable"
command: >
sh -c "/app/pbuf-migrations && /app/pbuf-registry"
sh -c "/app/pbuf-migrations && /app/pbuf-registry"
pbuf-registry-compaction:
build:
context: .
restart: always
depends_on:
- db
- pbuf-registry
ports:
- "8083:8082"
healthcheck:
test: wget -O - http://localhost:8082/healthz || exit 1
interval: 5s
timeout: 10s
retries: 5
environment:
DATA_DATABASE_DSN: "postgres://pbuf:pbuf@db:5432/pbuf_registry?sslmode=disable"
command: >
sh -c "/app/pbuf-registry compaction"
19 changes: 18 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
timeout: 10s
retries: 5
pbuf-registry:
image: ghcr.io/pbufio/registry:v0.3.0
image: ghcr.io/pbufio/registry:v0.4.0-wip.1
restart: always
depends_on:
- db
Expand Down Expand Up @@ -48,6 +48,23 @@ services:
SERVER_STATIC_TOKEN: ${SERVER_STATIC_TOKEN}
command: >
sh -c "/app/pbuf-migrations && /app/pbuf-registry"
pbuf-registry-compaction:
image: ghcr.io/pbufio/registry:v0.4.0-wip.1
restart: always
depends_on:
- db
- pbuf-registry
ports:
- "127.0.0.1:8083:8082"
healthcheck:
test: wget -O - http://localhost:8082/healthz || exit 1
interval: 5s
timeout: 10s
retries: 5
environment:
DATA_DATABASE_DSN: "postgres://pbuf:pbuf@db:5432/pbuf_registry?sslmode=disable"
command: >
sh -c "/app/pbuf-registry compaction"
networks:
internal:
33 changes: 22 additions & 11 deletions gen/pbuf-registry/v1/entities.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 680db23

Please sign in to comment.