From ae98cc992f6e968091cab2bb8aed6cd31bddf629 Mon Sep 17 00:00:00 2001 From: MohitKatare-protean Date: Tue, 29 Apr 2025 15:45:26 +0530 Subject: [PATCH 01/75] Publisher plugin implementation --- go.mod | 1 + go.sum | 2 + .../implementation/publisher/cmd/plugin.go | 96 ++++++++++++++ .../implementation/publisher/publisher.go | 119 ++++++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 pkg/plugin/implementation/publisher/cmd/plugin.go create mode 100644 pkg/plugin/implementation/publisher/publisher.go diff --git a/go.mod b/go.mod index 12fad60..29412d4 100644 --- a/go.mod +++ b/go.mod @@ -32,6 +32,7 @@ require ( require ( github.com/hashicorp/go-retryablehttp v0.7.7 + github.com/rabbitmq/amqp091-go v1.10.0 github.com/rs/zerolog v1.34.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 821e117..d6ddf7e 100644 --- a/go.sum +++ b/go.sum @@ -30,6 +30,8 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw= +github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= diff --git a/pkg/plugin/implementation/publisher/cmd/plugin.go b/pkg/plugin/implementation/publisher/cmd/plugin.go new file mode 100644 index 0000000..647edaf --- /dev/null +++ b/pkg/plugin/implementation/publisher/cmd/plugin.go @@ -0,0 +1,96 @@ +package main + +import ( + "context" + "fmt" + + "github.com/beckn/beckn-onix/pkg/log" + "github.com/beckn/beckn-onix/pkg/plugin/definition" + "github.com/beckn/beckn-onix/pkg/plugin/implementation/publisher" + "github.com/rabbitmq/amqp091-go" +) + +// publisherProvider implements the PublisherProvider interface. +// It is responsible for creating a new Publisher instance. +type publisherProvider struct{} + +// New creates a new Publisher instance based on the provided configuration map. +// It also returns a cleanup function to close resources and any potential errors encountered. +func (p *publisherProvider) New(ctx context.Context, config map[string]string) (definition.Publisher, func() error, error) { + // Step 1: Map config + cfg := &publisher.Config{ + Addr: config["addr"], + Exchange: config["exchange"], + RoutingKey: config["routing_key"], + Durable: config["durable"] == "true", + UseTLS: config["use_tls"] == "true", + } + log.Debugf(ctx, "Publisher config mapped: %+v", cfg) + + // Step 2: Validate + if err := publisher.Validate(cfg); err != nil { + log.Errorf(ctx, err, "Publisher config validation failed") + return nil, nil, err + } + log.Infof(ctx, "Publisher config validated successfully") + + // Step 3:URL + connURL, err := publisher.GetConnURL(cfg) + if err != nil { + log.Errorf(ctx, err, "Failed to build RabbitMQ connection URL") + return nil, nil, fmt.Errorf("failed to build connection URL: %w", err) + } + log.Debugf(ctx, "RabbitMQ connection URL built: %s", connURL) + // Step 4: Connect + conn, err := amqp091.Dial(connURL) + if err != nil { + log.Errorf(ctx, err, "Failed to connect to RabbitMQ") + return nil, nil, fmt.Errorf("%w: %v", publisher.ErrConnectionFailed, err) + } + log.Infof(ctx, "Connected to RabbitMQ") + + ch, err := conn.Channel() + if err != nil { + conn.Close() + log.Errorf(ctx, err, "Failed to open RabbitMQ channel") + return nil, nil, fmt.Errorf("%w: %v", publisher.ErrChannelFailed, err) + } + log.Infof(ctx, "RabbitMQ channel opened successfully") + + // Step 5: Declare Exchange + err = ch.ExchangeDeclare( + cfg.Exchange, + "topic", + cfg.Durable, + false, + false, + false, + nil, + ) + if err != nil { + ch.Close() + conn.Close() + log.Errorf(ctx, err, "Failed to declare exchange: %s", cfg.Exchange) + return nil, nil, fmt.Errorf("%w: %v", publisher.ErrExchangeDeclare, err) + } + log.Infof(ctx, "RabbitMQ exchange declared successfully: %s", cfg.Exchange) + + // Step 6: Create publisher instance + publisher := &publisher.Publisher{ + Conn: conn, + Channel: ch, + Config: cfg, + } + + cleanup := func() error { + log.Infof(ctx, "Cleaning up RabbitMQ resources") + _ = ch.Close() + return conn.Close() + } + + log.Infof(ctx, "Publisher instance created successfully") + return publisher, cleanup, nil +} + +// Provider is the instance of publisherProvider that implements the PublisherProvider interface. +var Provider = publisherProvider{} diff --git a/pkg/plugin/implementation/publisher/publisher.go b/pkg/plugin/implementation/publisher/publisher.go new file mode 100644 index 0000000..a861caf --- /dev/null +++ b/pkg/plugin/implementation/publisher/publisher.go @@ -0,0 +1,119 @@ +package publisher + +import ( + "context" + "errors" + "fmt" + "net/url" + "os" + "strings" + + "github.com/beckn/beckn-onix/pkg/log" + "github.com/beckn/beckn-onix/pkg/model" + "github.com/rabbitmq/amqp091-go" +) + +// Config holds the configuration required to establish a connection with RabbitMQ. +type Config struct { + Addr string + Exchange string + RoutingKey string + Durable bool + UseTLS bool +} + +// Publisher manages the RabbitMQ connection and channel to publish messages. +type Publisher struct { + Conn *amqp091.Connection + Channel *amqp091.Channel + Config *Config +} + +// Error variables representing different failure scenarios. +var ( + ErrEmptyConfig = errors.New("empty config") + ErrAddrMissing = errors.New("missing required field 'Addr'") + ErrExchangeMissing = errors.New("missing required field 'Exchange'") + ErrCredentialMissing = errors.New("missing RabbitMQ credentials in environment") + ErrConnectionFailed = errors.New("failed to connect to RabbitMQ") + ErrChannelFailed = errors.New("failed to open channel") + ErrExchangeDeclare = errors.New("failed to declare exchange") +) + +// Validate checks whether the provided Config is valid for connecting to RabbitMQ. +func Validate(cfg *Config) error { + if cfg == nil { + return model.NewBadReqErr(fmt.Errorf("config is nil")) + } + if strings.TrimSpace(cfg.Addr) == "" { + return model.NewBadReqErr(fmt.Errorf("missing config.Addr")) + } + if strings.TrimSpace(cfg.Exchange) == "" { + return model.NewBadReqErr(fmt.Errorf("missing config.Exchange")) + } + return nil +} + +// GetConnURL constructs the RabbitMQ connection URL using the config and environment credentials. +func GetConnURL(cfg *Config) (string, error) { + user := os.Getenv("RABBITMQ_USERNAME") + pass := os.Getenv("RABBITMQ_PASSWORD") + if user == "" || pass == "" { + return "", model.NewBadReqErr(fmt.Errorf("missing RabbitMQ credentials in environment")) + } + + parts := strings.SplitN(cfg.Addr, "/", 2) + hostPort := parts[0] + vhost := "/" + if len(parts) > 1 { + vhost = parts[1] + } + + if !strings.Contains(hostPort, ":") { + if cfg.UseTLS { + hostPort += ":5671" + } else { + hostPort += ":5672" + } + } + + encodedUser := url.QueryEscape(user) + encodedPass := url.QueryEscape(pass) + encodedVHost := url.QueryEscape(vhost) + protocol := "amqp" + if cfg.UseTLS { + protocol = "amqps" + } + + connURL := fmt.Sprintf("%s://%s:%s@%s/%s", protocol, encodedUser, encodedPass, hostPort, encodedVHost) + log.Debugf(context.Background(), "Generated RabbitMQ connection URL: %s", connURL) + return connURL, nil +} + +// Publish sends a message to the configured RabbitMQ exchange with the specified routing key. +// If routingKey is empty, the default routing key from Config is used. +func (p *Publisher) Publish(ctx context.Context, routingKey string, msg []byte) error { + if routingKey == "" { + routingKey = p.Config.RoutingKey + } + log.Debugf(ctx, "Attempting to publish message. Exchange: %s, RoutingKey: %s", p.Config.Exchange, routingKey) + err := p.Channel.PublishWithContext( + ctx, + p.Config.Exchange, + routingKey, + false, + false, + amqp091.Publishing{ + ContentType: "application/json", + Body: msg, + }, + ) + + if err != nil { + log.Errorf(ctx, err, "Publish failed for Exchange: %s, RoutingKey: %s", p.Config.Exchange, routingKey) + return model.NewBadReqErr(fmt.Errorf("publish message failed: %w", err)) + } + + log.Infof(ctx, "Message published successfully to Exchange: %s, RoutingKey: %s", p.Config.Exchange, routingKey) + return nil +} From 72f8be52faa42dd45ed904448e659bc57fea6d0e Mon Sep 17 00:00:00 2001 From: MohitKatare-protean Date: Tue, 6 May 2025 10:29:23 +0530 Subject: [PATCH 02/75] added test case --- pkg/plugin/definition/publisher.go | 1 + .../publisher/publisher_test.go | 150 ++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 pkg/plugin/implementation/publisher/publisher_test.go diff --git a/pkg/plugin/definition/publisher.go b/pkg/plugin/definition/publisher.go index 1e744da..55ed217 100644 --- a/pkg/plugin/definition/publisher.go +++ b/pkg/plugin/definition/publisher.go @@ -8,6 +8,7 @@ type Publisher interface { Publish(context.Context, string, []byte) error } +// PublisherProvider is the interface for creating new Publisher instances. type PublisherProvider interface { // New initializes a new publisher instance with the given configuration. New(ctx context.Context, config map[string]string) (Publisher, func() error, error) diff --git a/pkg/plugin/implementation/publisher/publisher_test.go b/pkg/plugin/implementation/publisher/publisher_test.go new file mode 100644 index 0000000..175bafb --- /dev/null +++ b/pkg/plugin/implementation/publisher/publisher_test.go @@ -0,0 +1,150 @@ +package publisher + +import ( + "os" + "testing" +) + +func TestGetConnURLSuccess(t *testing.T) { + tests := []struct { + name string + config *Config + }{ + { + name: "Valid config with credentials", + config: &Config{ + Addr: "localhost:5672", + UseTLS: false, + }, + }, + { + name: "Valid config with vhost", + config: &Config{ + Addr: "localhost:5672/myvhost", + UseTLS: false, + }, + }, + } + + // Set valid credentials + os.Setenv("RABBITMQ_USERNAME", "guest") + os.Setenv("RABBITMQ_PASSWORD", "guest") + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + url, err := GetConnURL(tt.config) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if url == "" { + t.Error("expected non-empty URL, got empty string") + } + }) + } +} + +func TestGetConnURLFailure(t *testing.T) { + tests := []struct { + name string + username string + password string + config *Config + wantErr bool + }{ + { + name: "Missing credentials", + username: "", + password: "", + config: &Config{Addr: "localhost:5672"}, + wantErr: true, + }, + { + name: "Missing config address", + username: "guest", + password: "guest", + config: &Config{}, // this won't error unless Validate() is called separately + wantErr: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.username == "" { + os.Unsetenv("RABBITMQ_USERNAME") + } else { + os.Setenv("RABBITMQ_USERNAME", tt.username) + } + + if tt.password == "" { + os.Unsetenv("RABBITMQ_PASSWORD") + } else { + os.Setenv("RABBITMQ_PASSWORD", tt.password) + } + + url, err := GetConnURL(tt.config) + if (err != nil) != tt.wantErr { + t.Errorf("unexpected error. gotErr = %v, wantErr = %v", err != nil, tt.wantErr) + } + + if err == nil && url == "" { + t.Errorf("expected non-empty URL, got empty string") + } + }) + } +} + +func TestValidateSuccess(t *testing.T) { + tests := []struct { + name string + config *Config + }{ + { + name: "Valid config with Addr and Exchange", + config: &Config{ + Addr: "localhost:5672", + Exchange: "ex", + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := Validate(tt.config); err != nil { + t.Errorf("expected no error, got: %v", err) + } + }) + } +} + +func TestValidateFailure(t *testing.T) { + tests := []struct { + name string + config *Config + }{ + { + name: "Nil config", + config: nil, + }, + { + name: "Missing Addr", + config: &Config{Exchange: "ex"}, + }, + { + name: "Missing Exchange", + config: &Config{Addr: "localhost:5672"}, + }, + { + name: "Empty Addr and Exchange", + config: &Config{Addr: " ", Exchange: " "}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := Validate(tt.config) + if err == nil { + t.Errorf("expected error for invalid config, got nil") + } + }) + } +} From 2e0b5834d7d3335897feafd65bf7cc3d6be952f8 Mon Sep 17 00:00:00 2001 From: MohitKatare-protean Date: Tue, 6 May 2025 12:08:56 +0530 Subject: [PATCH 03/75] added updated test case for the publisher implementation --- .../implementation/publisher/publisher.go | 7 +- .../publisher/publisher_test.go | 70 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/pkg/plugin/implementation/publisher/publisher.go b/pkg/plugin/implementation/publisher/publisher.go index a861caf..5623775 100644 --- a/pkg/plugin/implementation/publisher/publisher.go +++ b/pkg/plugin/implementation/publisher/publisher.go @@ -22,10 +22,15 @@ type Config struct { UseTLS bool } +// Channel defines the interface for publishing messages to RabbitMQ. +type Channel interface { + PublishWithContext(ctx context.Context, exchange, key string, mandatory, immediate bool, msg amqp091.Publishing) error +} + // Publisher manages the RabbitMQ connection and channel to publish messages. type Publisher struct { Conn *amqp091.Connection - Channel *amqp091.Channel + Channel Channel Config *Config } diff --git a/pkg/plugin/implementation/publisher/publisher_test.go b/pkg/plugin/implementation/publisher/publisher_test.go index 175bafb..5002f29 100644 --- a/pkg/plugin/implementation/publisher/publisher_test.go +++ b/pkg/plugin/implementation/publisher/publisher_test.go @@ -1,8 +1,12 @@ package publisher import ( + "context" + "errors" "os" "testing" + + "github.com/rabbitmq/amqp091-go" ) func TestGetConnURLSuccess(t *testing.T) { @@ -148,3 +152,69 @@ func TestValidateFailure(t *testing.T) { }) } } + +type mockChannel struct { + published bool + args amqp091.Publishing + exchange string + key string + fail bool +} + +func (m *mockChannel) PublishWithContext( + _ context.Context, + exchange, key string, + mandatory, immediate bool, + msg amqp091.Publishing, +) error { + if m.fail { + return errors.New("mock publish failure") + } + m.published = true + m.args = msg + m.exchange = exchange + m.key = key + return nil +} + +func TestPublishSuccess(t *testing.T) { + mockCh := &mockChannel{} + + p := &Publisher{ + Channel: mockCh, + Config: &Config{ + Exchange: "mock.exchange", + RoutingKey: "mock.key", + }, + } + + err := p.Publish(context.Background(), "", []byte(`{"test": true}`)) + if err != nil { + t.Errorf("expected no error, got: %v", err) + } + + if !mockCh.published { + t.Error("expected message to be published, but it wasn't") + } + + if mockCh.exchange != "mock.exchange" || mockCh.key != "mock.key" { + t.Errorf("unexpected exchange or key. got (%s, %s)", mockCh.exchange, mockCh.key) + } +} + +func TestPublishFailure(t *testing.T) { + mockCh := &mockChannel{fail: true} + + p := &Publisher{ + Channel: mockCh, + Config: &Config{ + Exchange: "mock.exchange", + RoutingKey: "mock.key", + }, + } + + err := p.Publish(context.Background(), "", []byte(`{"test": true}`)) + if err == nil { + t.Error("expected error from failed publish, got nil") + } +} From e5cccc30f85617c91ab8b54bdeeaad7ede1c192e Mon Sep 17 00:00:00 2001 From: MohitKatare-protean Date: Tue, 13 May 2025 12:30:34 +0530 Subject: [PATCH 04/75] Resolved PR Review comments --- .../implementation/publisher/cmd/plugin.go | 69 +------ .../publisher/cmd/plugin_test.go | 106 +++++++++++ .../implementation/publisher/publisher.go | 72 ++++++++ .../publisher/publisher_test.go | 174 ++++++++++++++++-- 4 files changed, 344 insertions(+), 77 deletions(-) create mode 100644 pkg/plugin/implementation/publisher/cmd/plugin_test.go diff --git a/pkg/plugin/implementation/publisher/cmd/plugin.go b/pkg/plugin/implementation/publisher/cmd/plugin.go index 647edaf..ccf87fa 100644 --- a/pkg/plugin/implementation/publisher/cmd/plugin.go +++ b/pkg/plugin/implementation/publisher/cmd/plugin.go @@ -2,22 +2,18 @@ package main import ( "context" - "fmt" "github.com/beckn/beckn-onix/pkg/log" "github.com/beckn/beckn-onix/pkg/plugin/definition" "github.com/beckn/beckn-onix/pkg/plugin/implementation/publisher" - "github.com/rabbitmq/amqp091-go" ) // publisherProvider implements the PublisherProvider interface. // It is responsible for creating a new Publisher instance. type publisherProvider struct{} -// New creates a new Publisher instance based on the provided configuration map. -// It also returns a cleanup function to close resources and any potential errors encountered. +// New creates a new Publisher instance based on the provided configuration. func (p *publisherProvider) New(ctx context.Context, config map[string]string) (definition.Publisher, func() error, error) { - // Step 1: Map config cfg := &publisher.Config{ Addr: config["addr"], Exchange: config["exchange"], @@ -27,69 +23,14 @@ func (p *publisherProvider) New(ctx context.Context, config map[string]string) ( } log.Debugf(ctx, "Publisher config mapped: %+v", cfg) - // Step 2: Validate - if err := publisher.Validate(cfg); err != nil { - log.Errorf(ctx, err, "Publisher config validation failed") + pub, cleanup, err := publisher.New(cfg) + if err != nil { + log.Errorf(ctx, err, "Failed to create publisher instance") return nil, nil, err } - log.Infof(ctx, "Publisher config validated successfully") - - // Step 3:URL - connURL, err := publisher.GetConnURL(cfg) - if err != nil { - log.Errorf(ctx, err, "Failed to build RabbitMQ connection URL") - return nil, nil, fmt.Errorf("failed to build connection URL: %w", err) - } - log.Debugf(ctx, "RabbitMQ connection URL built: %s", connURL) - // Step 4: Connect - conn, err := amqp091.Dial(connURL) - if err != nil { - log.Errorf(ctx, err, "Failed to connect to RabbitMQ") - return nil, nil, fmt.Errorf("%w: %v", publisher.ErrConnectionFailed, err) - } - log.Infof(ctx, "Connected to RabbitMQ") - - ch, err := conn.Channel() - if err != nil { - conn.Close() - log.Errorf(ctx, err, "Failed to open RabbitMQ channel") - return nil, nil, fmt.Errorf("%w: %v", publisher.ErrChannelFailed, err) - } - log.Infof(ctx, "RabbitMQ channel opened successfully") - - // Step 5: Declare Exchange - err = ch.ExchangeDeclare( - cfg.Exchange, - "topic", - cfg.Durable, - false, - false, - false, - nil, - ) - if err != nil { - ch.Close() - conn.Close() - log.Errorf(ctx, err, "Failed to declare exchange: %s", cfg.Exchange) - return nil, nil, fmt.Errorf("%w: %v", publisher.ErrExchangeDeclare, err) - } - log.Infof(ctx, "RabbitMQ exchange declared successfully: %s", cfg.Exchange) - - // Step 6: Create publisher instance - publisher := &publisher.Publisher{ - Conn: conn, - Channel: ch, - Config: cfg, - } - - cleanup := func() error { - log.Infof(ctx, "Cleaning up RabbitMQ resources") - _ = ch.Close() - return conn.Close() - } log.Infof(ctx, "Publisher instance created successfully") - return publisher, cleanup, nil + return pub, cleanup, nil } // Provider is the instance of publisherProvider that implements the PublisherProvider interface. diff --git a/pkg/plugin/implementation/publisher/cmd/plugin_test.go b/pkg/plugin/implementation/publisher/cmd/plugin_test.go new file mode 100644 index 0000000..e3f9837 --- /dev/null +++ b/pkg/plugin/implementation/publisher/cmd/plugin_test.go @@ -0,0 +1,106 @@ +package main + +import ( + "context" + "errors" + "strings" + "testing" + + "github.com/beckn/beckn-onix/pkg/plugin/implementation/publisher" + "github.com/rabbitmq/amqp091-go" +) + +type mockChannel struct{} + +func (m *mockChannel) PublishWithContext(ctx context.Context, exchange, key string, mandatory, immediate bool, msg amqp091.Publishing) error { + return nil +} +func (m *mockChannel) ExchangeDeclare(name, kind string, durable, autoDelete, internal, noWait bool, args amqp091.Table) error { + return nil +} +func (m *mockChannel) Close() error { + return nil +} + +func TestPublisherProvider_New_Success(t *testing.T) { + // Save original dialFunc and channelFunc + originalDialFunc := publisher.DialFunc + originalChannelFunc := publisher.ChannelFunc + defer func() { + publisher.DialFunc = originalDialFunc + publisher.ChannelFunc = originalChannelFunc + }() + + // Override mocks + publisher.DialFunc = func(url string) (*amqp091.Connection, error) { + return nil, nil + } + publisher.ChannelFunc = func(conn *amqp091.Connection) (publisher.Channel, error) { + return &mockChannel{}, nil + } + + t.Setenv("RABBITMQ_USERNAME", "guest") + t.Setenv("RABBITMQ_PASSWORD", "guest") + + config := map[string]string{ + "addr": "localhost", + "exchange": "test-exchange", + "routing_key": "test.key", + "durable": "true", + "use_tls": "false", + } + + ctx := context.Background() + pub, cleanup, err := Provider.New(ctx, config) + + if err != nil { + t.Fatalf("Provider.New returned error: %v", err) + } + if pub == nil { + t.Fatal("Expected non-nil publisher") + } + if cleanup == nil { + t.Fatal("Expected non-nil cleanup function") + } + + if err := cleanup(); err != nil { + t.Errorf("Cleanup returned error: %v", err) + } +} + +func TestPublisherProvider_New_Failure(t *testing.T) { + // Save and restore dialFunc + originalDialFunc := publisher.DialFunc + defer func() { publisher.DialFunc = originalDialFunc }() + + // Simulate dial failure + publisher.DialFunc = func(url string) (*amqp091.Connection, error) { + return nil, errors.New("dial failed") + } + + t.Setenv("RABBITMQ_USERNAME", "guest") + t.Setenv("RABBITMQ_PASSWORD", "guest") + + config := map[string]string{ + "addr": "localhost", + "exchange": "test-exchange", + "routing_key": "test.key", + "durable": "true", + } + + ctx := context.Background() + pub, cleanup, err := Provider.New(ctx, config) + + if err == nil { + t.Fatal("Expected error from Provider.New but got nil") + } + if !strings.Contains(err.Error(), "dial failed") { + t.Errorf("Expected 'dial failed' error, got: %v", err) + } + if pub != nil { + t.Errorf("Expected nil publisher, got: %v", pub) + } + if cleanup != nil { + t.Error("Expected nil cleanup, got non-nil") + } +} diff --git a/pkg/plugin/implementation/publisher/publisher.go b/pkg/plugin/implementation/publisher/publisher.go index 5623775..60f531d 100644 --- a/pkg/plugin/implementation/publisher/publisher.go +++ b/pkg/plugin/implementation/publisher/publisher.go @@ -25,6 +25,8 @@ type Config struct { // Channel defines the interface for publishing messages to RabbitMQ. type Channel interface { PublishWithContext(ctx context.Context, exchange, key string, mandatory, immediate bool, msg amqp091.Publishing) error + ExchangeDeclare(name, kind string, durable, autoDelete, internal, noWait bool, args amqp091.Table) error + Close() error } // Publisher manages the RabbitMQ connection and channel to publish messages. @@ -122,3 +124,73 @@ func (p *Publisher) Publish(ctx context.Context, routingKey string, msg []byte) log.Infof(ctx, "Message published successfully to Exchange: %s, RoutingKey: %s", p.Config.Exchange, routingKey) return nil } + +// DialFunc is a function variable used to establish a connection to RabbitMQ. +var DialFunc = amqp091.Dial + +// ChannelFunc is a function variable used to open a channel on the given RabbitMQ connection. +var ChannelFunc = func(conn *amqp091.Connection) (Channel, error) { + return conn.Channel() +} + +// New initializes a new Publisher with the given config, opens a connection, +// channel, and declares the exchange. Returns the publisher and a cleanup function. +func New(cfg *Config) (*Publisher, func() error, error) { + // Step 1: Validate config + if err := Validate(cfg); err != nil { + return nil, nil, err + } + + // Step 2: Build connection URL + connURL, err := GetConnURL(cfg) + if err != nil { + return nil, nil, fmt.Errorf("%w: %v", ErrConnectionFailed, err) + } + + // Step 3: Dial connection + conn, err := DialFunc(connURL) + if err != nil { + return nil, nil, fmt.Errorf("%w: %v", ErrConnectionFailed, err) + } + + // Step 4: Open channel + ch, err := ChannelFunc(conn) + if err != nil { + conn.Close() + return nil, nil, fmt.Errorf("%w: %v", ErrChannelFailed, err) + } + + // Step 5: Declare exchange + if err := ch.ExchangeDeclare( + cfg.Exchange, + "topic", + cfg.Durable, + false, + false, + false, + nil, + ); err != nil { + ch.Close() + conn.Close() + return nil, nil, fmt.Errorf("%w: %v", ErrExchangeDeclare, err) + } + + // Step 6: Construct publisher + pub := &Publisher{ + Conn: conn, + Channel: ch, + Config: cfg, + } + + cleanup := func() error { + if ch != nil { + _ = ch.Close() + } + if conn != nil { + return conn.Close() + } + return nil + } + + return pub, cleanup, nil +} diff --git a/pkg/plugin/implementation/publisher/publisher_test.go b/pkg/plugin/implementation/publisher/publisher_test.go index 5002f29..b54fa9b 100644 --- a/pkg/plugin/implementation/publisher/publisher_test.go +++ b/pkg/plugin/implementation/publisher/publisher_test.go @@ -2,8 +2,9 @@ package publisher import ( "context" - "errors" + "fmt" "os" + "strings" "testing" "github.com/rabbitmq/amqp091-go" @@ -153,32 +154,35 @@ func TestValidateFailure(t *testing.T) { } } -type mockChannel struct { +type mockChannelForPublish struct { published bool - args amqp091.Publishing exchange string key string + body []byte fail bool } -func (m *mockChannel) PublishWithContext( - _ context.Context, - exchange, key string, - mandatory, immediate bool, - msg amqp091.Publishing, -) error { +func (m *mockChannelForPublish) PublishWithContext(ctx context.Context, exchange, key string, mandatory, immediate bool, msg amqp091.Publishing) error { if m.fail { - return errors.New("mock publish failure") + return fmt.Errorf("simulated publish failure") } m.published = true - m.args = msg m.exchange = exchange m.key = key + m.body = msg.Body + return nil +} + +func (m *mockChannelForPublish) ExchangeDeclare(name, kind string, durable, autoDelete, internal, noWait bool, args amqp091.Table) error { + return nil +} + +func (m *mockChannelForPublish) Close() error { return nil } func TestPublishSuccess(t *testing.T) { - mockCh := &mockChannel{} + mockCh := &mockChannelForPublish{} p := &Publisher{ Channel: mockCh, @@ -203,7 +207,7 @@ func TestPublishSuccess(t *testing.T) { } func TestPublishFailure(t *testing.T) { - mockCh := &mockChannel{fail: true} + mockCh := &mockChannelForPublish{fail: true} p := &Publisher{ Channel: mockCh, @@ -218,3 +222,147 @@ func TestPublishFailure(t *testing.T) { t.Error("expected error from failed publish, got nil") } } + +type mockChannel struct{} + +func (m *mockChannel) PublishWithContext(ctx context.Context, exchange, key string, mandatory, immediate bool, msg amqp091.Publishing) error { + return nil +} +func (m *mockChannel) ExchangeDeclare(name, kind string, durable, autoDelete, internal, noWait bool, args amqp091.Table) error { + return nil +} +func (m *mockChannel) Close() error { + return nil +} + +type mockConnection struct{} + +func (m *mockConnection) Close() error { + return nil +} + +func TestNewPublisherSucess(t *testing.T) { + originalDialFunc := DialFunc + originalChannelFunc := ChannelFunc + defer func() { + DialFunc = originalDialFunc + ChannelFunc = originalChannelFunc + }() + + // mockedConn := &mockConnection{} + + DialFunc = func(url string) (*amqp091.Connection, error) { + return nil, nil + } + + ChannelFunc = func(conn *amqp091.Connection) (Channel, error) { + return &mockChannel{}, nil + } + + cfg := &Config{ + Addr: "localhost", + Exchange: "test-ex", + Durable: true, + RoutingKey: "test.key", + } + + t.Setenv("RABBITMQ_USERNAME", "user") + t.Setenv("RABBITMQ_PASSWORD", "pass") + + pub, cleanup, err := New(cfg) + if err != nil { + t.Fatalf("New() failed: %v", err) + } + if pub == nil { + t.Fatal("Publisher should not be nil") + } + if cleanup == nil { + t.Fatal("Cleanup should not be nil") + } + if err := cleanup(); err != nil { + t.Errorf("Cleanup failed: %v", err) + } +} + +type mockChannelFailDeclare struct{} + +func (m *mockChannelFailDeclare) PublishWithContext(ctx context.Context, exchange, key string, mandatory, immediate bool, msg amqp091.Publishing) error { + return nil +} +func (m *mockChannelFailDeclare) ExchangeDeclare(name, kind string, durable, autoDelete, internal, noWait bool, args amqp091.Table) error { + return fmt.Errorf("simulated exchange declare error") +} +func (m *mockChannelFailDeclare) Close() error { + return nil +} + +func TestNewPublisherFailures(t *testing.T) { + tests := []struct { + name string + cfg *Config + dialFunc func(url string) (*amqp091.Connection, error) // Mocked dial function + envVars map[string]string + expectedError string + }{ + { + name: "ValidateFailure", + cfg: &Config{}, // invalid config + expectedError: "missing config.Addr", + }, + { + name: "GetConnURLFailure", + cfg: &Config{ + Addr: "localhost", + Exchange: "test-ex", + Durable: true, + RoutingKey: "test.key", + }, + envVars: map[string]string{ + "RABBITMQ_USERNAME": "", + "RABBITMQ_PASSWORD": "", + }, + expectedError: "missing RabbitMQ credentials in environment", + }, + { + name: "ConnectionFailure", + cfg: &Config{ + Addr: "localhost", + Exchange: "test-ex", + Durable: true, + RoutingKey: "test.key", + }, + dialFunc: func(url string) (*amqp091.Connection, error) { + return nil, fmt.Errorf("simulated connection failure") + }, + envVars: map[string]string{ + "RABBITMQ_USERNAME": "user", + "RABBITMQ_PASSWORD": "pass", + }, + expectedError: "failed to connect to RabbitMQ", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Set environment variables + for key, value := range tt.envVars { + t.Setenv(key, value) + } + + // Mock dialFunc if needed + originalDialFunc := DialFunc + if tt.dialFunc != nil { + DialFunc = tt.dialFunc + defer func() { + DialFunc = originalDialFunc + }() + } + + _, _, err := New(tt.cfg) + + if err == nil || (tt.expectedError != "" && !strings.Contains(err.Error(), tt.expectedError)) { + t.Errorf("Test %s failed: expected error containing %v, got: %v", tt.name, tt.expectedError, err) + } + }) + } +} From ed32b57a8052d53bdf7721498ffa9c3ef2746e4c Mon Sep 17 00:00:00 2001 From: MohitKatare-protean Date: Tue, 13 May 2025 12:33:32 +0530 Subject: [PATCH 05/75] fixed linting issues --- .../implementation/publisher/publisher_test.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/pkg/plugin/implementation/publisher/publisher_test.go b/pkg/plugin/implementation/publisher/publisher_test.go index b54fa9b..2c5915c 100644 --- a/pkg/plugin/implementation/publisher/publisher_test.go +++ b/pkg/plugin/implementation/publisher/publisher_test.go @@ -235,12 +235,6 @@ func (m *mockChannel) Close() error { return nil } -type mockConnection struct{} - -func (m *mockConnection) Close() error { - return nil -} - func TestNewPublisherSucess(t *testing.T) { originalDialFunc := DialFunc originalChannelFunc := ChannelFunc @@ -284,18 +278,6 @@ func TestNewPublisherSucess(t *testing.T) { } } -type mockChannelFailDeclare struct{} - -func (m *mockChannelFailDeclare) PublishWithContext(ctx context.Context, exchange, key string, mandatory, immediate bool, msg amqp091.Publishing) error { - return nil -} -func (m *mockChannelFailDeclare) ExchangeDeclare(name, kind string, durable, autoDelete, internal, noWait bool, args amqp091.Table) error { - return fmt.Errorf("simulated exchange declare error") -} -func (m *mockChannelFailDeclare) Close() error { - return nil -} - func TestNewPublisherFailures(t *testing.T) { tests := []struct { name string From 20883902fba4c4d3b345fe5fc20a571b50500689 Mon Sep 17 00:00:00 2001 From: MohitKatare-protean Date: Wed, 14 May 2025 16:11:28 +0530 Subject: [PATCH 06/75] Resolved review comments --- .../implementation/publisher/publisher.go | 6 +- .../publisher/publisher_test.go | 56 +++++++++++-------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/pkg/plugin/implementation/publisher/publisher.go b/pkg/plugin/implementation/publisher/publisher.go index 60f531d..db3e577 100644 --- a/pkg/plugin/implementation/publisher/publisher.go +++ b/pkg/plugin/implementation/publisher/publisher.go @@ -68,8 +68,7 @@ func GetConnURL(cfg *Config) (string, error) { if user == "" || pass == "" { return "", model.NewBadReqErr(fmt.Errorf("missing RabbitMQ credentials in environment")) } - - parts := strings.SplitN(cfg.Addr, "/", 2) + parts := strings.SplitN(strings.TrimSpace(cfg.Addr), "/", 2) hostPort := parts[0] vhost := "/" if len(parts) > 1 { @@ -93,7 +92,8 @@ func GetConnURL(cfg *Config) (string, error) { } connURL := fmt.Sprintf("%s://%s:%s@%s/%s", protocol, encodedUser, encodedPass, hostPort, encodedVHost) - log.Debugf(context.Background(), "Generated RabbitMQ connection URL: %s", connURL) + log.Debugf(context.Background(), "Generated RabbitMQ connection details: protocol=%s, hostPort=%s, vhost=%s", protocol, hostPort, vhost) + return connURL, nil } diff --git a/pkg/plugin/implementation/publisher/publisher_test.go b/pkg/plugin/implementation/publisher/publisher_test.go index 2c5915c..82b8404 100644 --- a/pkg/plugin/implementation/publisher/publisher_test.go +++ b/pkg/plugin/implementation/publisher/publisher_test.go @@ -3,7 +3,6 @@ package publisher import ( "context" "fmt" - "os" "strings" "testing" @@ -16,12 +15,13 @@ func TestGetConnURLSuccess(t *testing.T) { config *Config }{ { - name: "Valid config with credentials", + name: "Valid config with connection address", config: &Config{ Addr: "localhost:5672", UseTLS: false, }, }, + { name: "Valid config with vhost", config: &Config{ @@ -29,11 +29,18 @@ func TestGetConnURLSuccess(t *testing.T) { UseTLS: false, }, }, + { + name: "Addr with leading and trailing spaces", + config: &Config{ + Addr: " localhost:5672/myvhost ", + UseTLS: false, + }, + }, } // Set valid credentials - os.Setenv("RABBITMQ_USERNAME", "guest") - os.Setenv("RABBITMQ_PASSWORD", "guest") + t.Setenv("RABBITMQ_USERNAME", "guest") + t.Setenv("RABBITMQ_PASSWORD", "guest") for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -74,16 +81,12 @@ func TestGetConnURLFailure(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if tt.username == "" { - os.Unsetenv("RABBITMQ_USERNAME") - } else { - os.Setenv("RABBITMQ_USERNAME", tt.username) + if tt.username != "" { + t.Setenv("RABBITMQ_USERNAME", tt.username) } - if tt.password == "" { - os.Unsetenv("RABBITMQ_PASSWORD") - } else { - os.Setenv("RABBITMQ_PASSWORD", tt.password) + if tt.password != "" { + t.Setenv("RABBITMQ_PASSWORD", tt.password) } url, err := GetConnURL(tt.config) @@ -123,24 +126,29 @@ func TestValidateSuccess(t *testing.T) { func TestValidateFailure(t *testing.T) { tests := []struct { - name string - config *Config + name string + config *Config + expectedErrr string }{ { - name: "Nil config", - config: nil, + name: "Nil config", + config: nil, + expectedErrr: "config is nil", }, { - name: "Missing Addr", - config: &Config{Exchange: "ex"}, + name: "Missing Addr", + config: &Config{Exchange: "ex"}, + expectedErrr: "missing config.Addr", }, { - name: "Missing Exchange", - config: &Config{Addr: "localhost:5672"}, + name: "Missing Exchange", + config: &Config{Addr: "localhost:5672"}, + expectedErrr: "missing config.Exchange", }, { - name: "Empty Addr and Exchange", - config: &Config{Addr: " ", Exchange: " "}, + name: "Empty Addr and Exchange", + config: &Config{Addr: " ", Exchange: " "}, + expectedErrr: "missing config.Addr", }, } @@ -149,6 +157,10 @@ func TestValidateFailure(t *testing.T) { err := Validate(tt.config) if err == nil { t.Errorf("expected error for invalid config, got nil") + return + } + if !strings.Contains(err.Error(), tt.expectedErrr) { + t.Errorf("expected error to contain %q, got: %v", tt.expectedErrr, err) } }) } From bc6d21d7a0be7ef4968d2fc07b7d7e668e4f1fa0 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:16:21 +0530 Subject: [PATCH 07/75] Create build-and-deploy-plugins.yml --- .../workflows/build-and-deploy-plugins.yml | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/build-and-deploy-plugins.yml diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml new file mode 100644 index 0000000..2b8f2db --- /dev/null +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -0,0 +1,71 @@ +name: Build and Upload Plugins + +on: + workflow_dispatch: + +jobs: + build-and-upload: + runs-on: ubuntu-latest + env: + PLUGIN_OUTPUT_DIR: ./generated + ZIP_FILE: plugins_bundle.zip + + steps: + - name: Checkout this repo + uses: actions/checkout@v4 + + - name: Set up Git + run: | + git config --global url."https://${{ secrets.PAT_GITHUB }}:@github.com/beckn/beckn-onix.git".insteadOf "https://github.com/" + git config --global url."https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev/".insteadOf "https://gerrit.example.com/" + + - name: Clone GitHub and Gerrit plugin repos + run: | + # Example GitHub clone + git -b beckn-onix-v1.0-develop clone https://github.com/beckn/beckn-onix.git github-repo + + # Example Gerrit clone + git clone https://open-networks.googlesource.com/onix-dev/ + + - name: Build Go plugins in Docker + run: | + set -e + mkdir -p $PLUGIN_OUTPUT_DIR + BUILD_CMDS="" + + # GitHub plugins + for dir in beckn-onix-v1.0-develop/pkg/plugin/implementation/*; do + plugin=$(basename "$dir") + BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + done + + # Gerrit plugins + for dir in onix-dev/plugins/*; do + plugin=$(basename "$dir") + BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + done + + BUILD_CMDS=${BUILD_CMDS%" && "} + docker run --rm -v "$(pwd)":/app -w /app golang:1.24-bullseye sh -c "$BUILD_CMDS" + + - name: Zip the plugin binaries + run: | + cd $PLUGIN_OUTPUT_DIR + zip -r ../$ZIP_FILE *.so + cd .. + + - name: Authenticate to GCP + run: | + echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > gcloud-key.json + gcloud auth activate-service-account --key-file=gcloud-key.json + gcloud config set project trusty-relic-370809 + env: + GOOGLE_APPLICATION_CREDENTIALS: gcloud-key.json + + - name: Upload to GCS + run: | + gsutil -m cp -r $ZIP_FILE gs://${GCS_BUCKET}/ + + - name: Cleanup + run: | + rm -rf $PLUGIN_OUTPUT_DIR $ZIP_FILE gcloud-key.json From 981b0017c4dafd117e34365540de40ae0d5f2c5e Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:17:24 +0530 Subject: [PATCH 08/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 2b8f2db..ac716c4 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -1,6 +1,7 @@ name: Build and Upload Plugins on: + push: workflow_dispatch: jobs: From df61e55d7b3d9f568736d291142f010091b9074b Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:18:19 +0530 Subject: [PATCH 09/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index ac716c4..488657f 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -23,7 +23,7 @@ jobs: - name: Clone GitHub and Gerrit plugin repos run: | # Example GitHub clone - git -b beckn-onix-v1.0-develop clone https://github.com/beckn/beckn-onix.git github-repo + git clone -b beckn-onix-v1.0-develop clone https://github.com/beckn/beckn-onix.git github-repo # Example Gerrit clone git clone https://open-networks.googlesource.com/onix-dev/ From 229cf731423a022566f562feefcef5dffd7ada84 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:21:02 +0530 Subject: [PATCH 10/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 488657f..d28bcc1 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -23,7 +23,7 @@ jobs: - name: Clone GitHub and Gerrit plugin repos run: | # Example GitHub clone - git clone -b beckn-onix-v1.0-develop clone https://github.com/beckn/beckn-onix.git github-repo + git clone -b beckn-onix-v1.0-develop https://github.com/beckn/beckn-onix.git github-repo # Example Gerrit clone git clone https://open-networks.googlesource.com/onix-dev/ From 53653fc7bb302aca5e8160c844d2bb4b988f2f3a Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:24:44 +0530 Subject: [PATCH 11/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index d28bcc1..1740fb7 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -17,8 +17,8 @@ jobs: - name: Set up Git run: | - git config --global url."https://${{ secrets.PAT_GITHUB }}:@github.com/beckn/beckn-onix.git".insteadOf "https://github.com/" - git config --global url."https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev/".insteadOf "https://gerrit.example.com/" + git config --global url."https://${{ secrets.PAT_GITHUB }}:@github.com/".insteadOf "https://github.com/" + git config --global url."https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/".insteadOf "https://open-networks.googlesource.com/" - name: Clone GitHub and Gerrit plugin repos run: | @@ -26,7 +26,7 @@ jobs: git clone -b beckn-onix-v1.0-develop https://github.com/beckn/beckn-onix.git github-repo # Example Gerrit clone - git clone https://open-networks.googlesource.com/onix-dev/ + git clone https://open-networks.googlesource.com/onix-dev gerrit-repo - name: Build Go plugins in Docker run: | From ad9540c261718670d016129b9453eaabace2ef5f Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:27:36 +0530 Subject: [PATCH 12/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 1740fb7..f85b053 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -35,7 +35,7 @@ jobs: BUILD_CMDS="" # GitHub plugins - for dir in beckn-onix-v1.0-develop/pkg/plugin/implementation/*; do + for dir in pkg/plugin/implementation/*; do plugin=$(basename "$dir") BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " done From 98b0fc3e77b55e7746c474a8f507343c9668a46d Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:31:37 +0530 Subject: [PATCH 13/75] Update build-and-deploy-plugins.yml --- .../workflows/build-and-deploy-plugins.yml | 56 +++++-------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index f85b053..5d0a8b3 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -28,45 +28,19 @@ jobs: # Example Gerrit clone git clone https://open-networks.googlesource.com/onix-dev gerrit-repo - - name: Build Go plugins in Docker + - name: List directory structure run: | - set -e - mkdir -p $PLUGIN_OUTPUT_DIR - BUILD_CMDS="" - - # GitHub plugins - for dir in pkg/plugin/implementation/*; do - plugin=$(basename "$dir") - BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " - done - - # Gerrit plugins - for dir in onix-dev/plugins/*; do - plugin=$(basename "$dir") - BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " - done - - BUILD_CMDS=${BUILD_CMDS%" && "} - docker run --rm -v "$(pwd)":/app -w /app golang:1.24-bullseye sh -c "$BUILD_CMDS" - - - name: Zip the plugin binaries - run: | - cd $PLUGIN_OUTPUT_DIR - zip -r ../$ZIP_FILE *.so - cd .. - - - name: Authenticate to GCP - run: | - echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > gcloud-key.json - gcloud auth activate-service-account --key-file=gcloud-key.json - gcloud config set project trusty-relic-370809 - env: - GOOGLE_APPLICATION_CREDENTIALS: gcloud-key.json - - - name: Upload to GCS - run: | - gsutil -m cp -r $ZIP_FILE gs://${GCS_BUCKET}/ - - - name: Cleanup - run: | - rm -rf $PLUGIN_OUTPUT_DIR $ZIP_FILE gcloud-key.json + echo "📂 Contents of root:" + ls -alh + + echo "📂 Contents of GitHub repo:" + ls -alh github-repo + + echo "📂 Deep list of GitHub repo:" + find github-repo + + echo "📂 Contents of Gerrit repo:" + ls -alh gerrit-repo + + echo "📂 Deep list of Gerrit repo:" + find gerrit-repo From 9eb9b74c8a5397925c40bd2757e7778f4e4fee4c Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:37:28 +0530 Subject: [PATCH 14/75] Update build-and-deploy-plugins.yml --- .../workflows/build-and-deploy-plugins.yml | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 5d0a8b3..12cd6e4 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -44,3 +44,46 @@ jobs: echo "📂 Deep list of Gerrit repo:" find gerrit-repo + + - name: Build Go plugins in Docker + run: | + set -e + mkdir -p $PLUGIN_OUTPUT_DIR + BUILD_CMDS="" + + # GitHub plugins + for dir in github-repo/pkg/plugin/implementation/*; do + plugin=$(basename "$dir") + BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + done + + # Gerrit plugins + for dir in gerrit-repo/plugins/*; do + plugin=$(basename "$dir") + BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + done + + BUILD_CMDS=${BUILD_CMDS%" && "} + docker run --rm -v "$(pwd)":/app -w /app golang:1.24-bullseye sh -c "$BUILD_CMDS" + + - name: Zip the plugin binaries + run: | + cd $PLUGIN_OUTPUT_DIR + zip -r ../$ZIP_FILE *.so + cd .. + + - name: Authenticate to GCP + run: | + echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > gcloud-key.json + gcloud auth activate-service-account --key-file=gcloud-key.json + gcloud config set project trusty-relic-370809 + env: + GOOGLE_APPLICATION_CREDENTIALS: gcloud-key.json + + - name: Upload to GCS + run: | + gsutil -m cp -r *.zip gs://${GCS_BUCKET}/ + + - name: Cleanup + run: | + rm -rf $PLUGIN_OUTPUT_DIR $ZIP_FILE gcloud-key.json From f8248f3a52e1ad69b828906a1fe4d76c9c11bdd1 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:38:56 +0530 Subject: [PATCH 15/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 12cd6e4..78de5fe 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -52,13 +52,13 @@ jobs: BUILD_CMDS="" # GitHub plugins - for dir in github-repo/pkg/plugin/implementation/*; do + for dir in pkg/plugin/implementation/*; do plugin=$(basename "$dir") BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " done # Gerrit plugins - for dir in gerrit-repo/plugins/*; do + for dir in plugins/*; do plugin=$(basename "$dir") BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " done From 6074a8ed8e3955b213974e1ae46216a6e6191f1f Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:41:49 +0530 Subject: [PATCH 16/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 78de5fe..da3b2d1 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -15,18 +15,13 @@ jobs: - name: Checkout this repo uses: actions/checkout@v4 - - name: Set up Git - run: | - git config --global url."https://${{ secrets.PAT_GITHUB }}:@github.com/".insteadOf "https://github.com/" - git config --global url."https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/".insteadOf "https://open-networks.googlesource.com/" - - name: Clone GitHub and Gerrit plugin repos run: | # Example GitHub clone - git clone -b beckn-onix-v1.0-develop https://github.com/beckn/beckn-onix.git github-repo + git clone -b beckn-onix-v1.0-develop https://${{ secrets.PAT_GITHUB }}:@github.com/beckn/beckn-onix.git github-repo # Example Gerrit clone - git clone https://open-networks.googlesource.com/onix-dev gerrit-repo + git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo - name: List directory structure run: | From 91c0154fff03202a919bfd3191485eaaa5693ec1 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:47:06 +0530 Subject: [PATCH 17/75] Update build-and-deploy-plugins.yml --- .../workflows/build-and-deploy-plugins.yml | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index da3b2d1..6a57afa 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -46,20 +46,22 @@ jobs: mkdir -p $PLUGIN_OUTPUT_DIR BUILD_CMDS="" - # GitHub plugins - for dir in pkg/plugin/implementation/*; do - plugin=$(basename "$dir") - BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + # GitHub Plugins (confirmed path: github-repo/pkg/plugin/implementation/*/cmd) + for dir in github-repo/pkg/plugin/implementation/*; do + if [ -d "$dir/cmd" ]; then + plugin=$(basename "$dir") + BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + fi + done + + # Gerrit Plugins (confirmed path: gerrit-repo/plugins/*/cmd) + for dir in gerrit-repo/plugins/*; do + if [ -d "$dir/cmd" ]; then + plugin=$(basename "$dir") + BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + fi done - # Gerrit plugins - for dir in plugins/*; do - plugin=$(basename "$dir") - BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " - done - - BUILD_CMDS=${BUILD_CMDS%" && "} - docker run --rm -v "$(pwd)":/app -w /app golang:1.24-bullseye sh -c "$BUILD_CMDS" - name: Zip the plugin binaries run: | From bab3a90476b7b0bf0dd712a303610ec05fb8cce4 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:48:12 +0530 Subject: [PATCH 18/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 6a57afa..2bf84aa 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -79,7 +79,7 @@ jobs: - name: Upload to GCS run: | - gsutil -m cp -r *.zip gs://${GCS_BUCKET}/ + gsutil -m cp -r $ZIP_FILE gs://${GCS_BUCKET}/ - name: Cleanup run: | From 457ea09dd3c7c70520b09a6528594582e1a98a64 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:51:48 +0530 Subject: [PATCH 19/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 2bf84aa..44368b3 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -62,12 +62,16 @@ jobs: fi done + BUILD_CMDS=${BUILD_CMDS%" && "} + echo "🛠️ Running build commands inside Docker:" + echo "$BUILD_CMDS" + + docker run --rm -v "$(pwd)":/app -w /app golang:1.24-bullseye sh -c "$BUILD_CMDS" - - name: Zip the plugin binaries + - name: List zip output run: | - cd $PLUGIN_OUTPUT_DIR - zip -r ../$ZIP_FILE *.so - cd .. + ls -lh plugins_bundle.zip + - name: Authenticate to GCP run: | From 80ae5ca394899e05a2f4b4011c8eae41a718d6ae Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:53:29 +0530 Subject: [PATCH 20/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 44368b3..4577020 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -46,11 +46,11 @@ jobs: mkdir -p $PLUGIN_OUTPUT_DIR BUILD_CMDS="" - # GitHub Plugins (confirmed path: github-repo/pkg/plugin/implementation/*/cmd) + # GitHub Plugins for dir in github-repo/pkg/plugin/implementation/*; do if [ -d "$dir/cmd" ]; then plugin=$(basename "$dir") - BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + BUILD_CMDS+="cd github-repo && go build -buildmode=plugin -buildvcs=false -o ../${PLUGIN_OUTPUT_DIR}/${plugin}.so ./pkg/plugin/implementation/${plugin}/cmd && cd - && " fi done From 70c9e04af731be258ada845ad8c2753605839bd9 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:57:12 +0530 Subject: [PATCH 21/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 4577020..731a42e 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -53,15 +53,22 @@ jobs: BUILD_CMDS+="cd github-repo && go build -buildmode=plugin -buildvcs=false -o ../${PLUGIN_OUTPUT_DIR}/${plugin}.so ./pkg/plugin/implementation/${plugin}/cmd && cd - && " fi done - - # Gerrit Plugins (confirmed path: gerrit-repo/plugins/*/cmd) + for dir in gerrit-repo/plugins/*; do if [ -d "$dir/cmd" ]; then plugin=$(basename "$dir") - BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + BUILD_CMDS+="cd $dir/cmd && go mod init temp/$plugin && go build -buildmode=plugin -o /app/${PLUGIN_OUTPUT_DIR}/${plugin}.so && cd - && " fi done + # Gerrit Plugins (confirmed path: gerrit-repo/plugins/*/cmd) + #for dir in gerrit-repo/plugins/*; do + # if [ -d "$dir/cmd" ]; then + # plugin=$(basename "$dir") + # BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " + # fi + #done + BUILD_CMDS=${BUILD_CMDS%" && "} echo "🛠️ Running build commands inside Docker:" echo "$BUILD_CMDS" From 14d3f42ec0515a00a5562141693ba8fc05bb4a46 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 15:59:47 +0530 Subject: [PATCH 22/75] Update build-and-deploy-plugins.yml --- .../workflows/build-and-deploy-plugins.yml | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 731a42e..aa44d2f 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -40,41 +40,43 @@ jobs: echo "📂 Deep list of Gerrit repo:" find gerrit-repo + - name: Build Go plugins in Docker run: | set -e - mkdir -p $PLUGIN_OUTPUT_DIR + mkdir -p $PLUGIN_OUTPUT_DIR github-repo/plugins-temp + BUILD_CMDS="" - - # GitHub Plugins + + # GitHub plugins for dir in github-repo/pkg/plugin/implementation/*; do if [ -d "$dir/cmd" ]; then plugin=$(basename "$dir") BUILD_CMDS+="cd github-repo && go build -buildmode=plugin -buildvcs=false -o ../${PLUGIN_OUTPUT_DIR}/${plugin}.so ./pkg/plugin/implementation/${plugin}/cmd && cd - && " fi done - + + # Copy Gerrit plugins into GitHub repo so they inherit its go.mod for dir in gerrit-repo/plugins/*; do + plugin=$(basename "$dir") + cp -r "$dir" "github-repo/plugins-temp/$plugin" + done + + # Build copied Gerrit plugins + for dir in github-repo/plugins-temp/*; do if [ -d "$dir/cmd" ]; then plugin=$(basename "$dir") - BUILD_CMDS+="cd $dir/cmd && go mod init temp/$plugin && go build -buildmode=plugin -o /app/${PLUGIN_OUTPUT_DIR}/${plugin}.so && cd - && " + BUILD_CMDS+="cd github-repo && go build -buildmode=plugin -buildvcs=false -o ../${PLUGIN_OUTPUT_DIR}/${plugin}.so ./plugins-temp/${plugin}/cmd && cd - && " fi done - - # Gerrit Plugins (confirmed path: gerrit-repo/plugins/*/cmd) - #for dir in gerrit-repo/plugins/*; do - # if [ -d "$dir/cmd" ]; then - # plugin=$(basename "$dir") - # BUILD_CMDS+="go build -buildmode=plugin -buildvcs=false -o ${PLUGIN_OUTPUT_DIR}/${plugin}.so ./${dir}/cmd && " - # fi - #done - + BUILD_CMDS=${BUILD_CMDS%" && "} echo "🛠️ Running build commands inside Docker:" echo "$BUILD_CMDS" docker run --rm -v "$(pwd)":/app -w /app golang:1.24-bullseye sh -c "$BUILD_CMDS" + - name: List zip output run: | ls -lh plugins_bundle.zip From f5a47cf30fc8b3bf4520d870ffa680e324e77127 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 16:03:05 +0530 Subject: [PATCH 23/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index aa44d2f..86a57c9 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -44,7 +44,7 @@ jobs: - name: Build Go plugins in Docker run: | set -e - mkdir -p $PLUGIN_OUTPUT_DIR github-repo/plugins-temp + mkdir -p $PLUGIN_OUTPUT_DIR BUILD_CMDS="" @@ -56,17 +56,11 @@ jobs: fi done - # Copy Gerrit plugins into GitHub repo so they inherit its go.mod + # Gerrit plugins — build in their own repo/module context for dir in gerrit-repo/plugins/*; do - plugin=$(basename "$dir") - cp -r "$dir" "github-repo/plugins-temp/$plugin" - done - - # Build copied Gerrit plugins - for dir in github-repo/plugins-temp/*; do if [ -d "$dir/cmd" ]; then plugin=$(basename "$dir") - BUILD_CMDS+="cd github-repo && go build -buildmode=plugin -buildvcs=false -o ../${PLUGIN_OUTPUT_DIR}/${plugin}.so ./plugins-temp/${plugin}/cmd && cd - && " + BUILD_CMDS+="cd gerrit-repo && go build -buildmode=plugin -buildvcs=false -o ../${PLUGIN_OUTPUT_DIR}/${plugin}.so ./plugins/${plugin}/cmd && cd - && " fi done @@ -77,6 +71,7 @@ jobs: docker run --rm -v "$(pwd)":/app -w /app golang:1.24-bullseye sh -c "$BUILD_CMDS" + - name: List zip output run: | ls -lh plugins_bundle.zip From 8d47756b9e635b6fa39aac845f1122f60533097c Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 16:06:27 +0530 Subject: [PATCH 24/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 86a57c9..491f667 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -70,6 +70,13 @@ jobs: docker run --rm -v "$(pwd)":/app -w /app golang:1.24-bullseye sh -c "$BUILD_CMDS" + - name: List built plugin files + run: | + echo "Looking in $PLUGIN_OUTPUT_DIR" + ls -lh $PLUGIN_OUTPUT_DIR || echo "⚠️ Directory does not exist" + find $PLUGIN_OUTPUT_DIR -name '*.so' || echo "⚠️ No .so files found" + + - name: List zip output From 4713eaec0557c580279e8b481e43300d170eefa5 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 16:10:48 +0530 Subject: [PATCH 25/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 491f667..c7e23ed 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -79,9 +79,9 @@ jobs: - - name: List zip output - run: | - ls -lh plugins_bundle.zip + #- name: List zip output + # run: | + # ls -lh plugins_bundle.zip - name: Authenticate to GCP From 5eff6a27be222f91493aeff324f543945ac5839b Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 16:15:51 +0530 Subject: [PATCH 26/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index c7e23ed..8417ff5 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -86,7 +86,7 @@ jobs: - name: Authenticate to GCP run: | - echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > gcloud-key.json + echo '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}' > gcloud-key.json gcloud auth activate-service-account --key-file=gcloud-key.json gcloud config set project trusty-relic-370809 env: From 76d63260beb0bd738e186ca66db97ba6376fd820 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 16:20:22 +0530 Subject: [PATCH 27/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 8417ff5..8187730 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -8,6 +8,7 @@ jobs: build-and-upload: runs-on: ubuntu-latest env: + GCS_BUCKET: ${{ secrets.GCS_BUCKET }} PLUGIN_OUTPUT_DIR: ./generated ZIP_FILE: plugins_bundle.zip From bc9d2fe8ab99d27f301d86cb5b7a0df0dbb75685 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 16:22:52 +0530 Subject: [PATCH 28/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 8187730..0870ff9 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -78,11 +78,9 @@ jobs: find $PLUGIN_OUTPUT_DIR -name '*.so' || echo "⚠️ No .so files found" - - - #- name: List zip output - # run: | - # ls -lh plugins_bundle.zip + - name: List zip output + run: | + ls -lh plugins_bundle.zip - name: Authenticate to GCP From 8cb521f5fbb7e547921013552cd620f7d466b28b Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 20 May 2025 16:33:47 +0530 Subject: [PATCH 29/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 0870ff9..3b76121 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -77,6 +77,11 @@ jobs: ls -lh $PLUGIN_OUTPUT_DIR || echo "⚠️ Directory does not exist" find $PLUGIN_OUTPUT_DIR -name '*.so' || echo "⚠️ No .so files found" + echo "Creating zip archive..." + cd "$PLUGIN_OUTPUT_DIR" + zip -r "../$ZIP_FILE" *.so + echo "Created $ZIP_FILE" + cd .. - name: List zip output run: | From bea28cc8de9ac2c101499cc163efc083e480cd70 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Thu, 22 May 2025 14:49:29 +0530 Subject: [PATCH 30/75] Create deploy-to-gke.yml Deploy image in GKE Cluster --- .github/workflows/deploy-to-gke.yml | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/deploy-to-gke.yml diff --git a/.github/workflows/deploy-to-gke.yml b/.github/workflows/deploy-to-gke.yml new file mode 100644 index 0000000..bcb43ef --- /dev/null +++ b/.github/workflows/deploy-to-gke.yml @@ -0,0 +1,44 @@ +name: Deploy to GKE + +on: + workflow_dispatch: + inputs: + service_name: + description: 'Name of the Kubernetes service to deploy' + required: true + type: string + cluster_name: + description: 'Name of the GKE cluster' + required: true + type: string + +jobs: + deploy: + runs-on: ubuntu-latest + + env: + PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }} + REGION: ${{ secrets.GCP_REGION }} + GKE_CLUSTER: ${{ github.event.inputs.cluster_name }} + SERVICE_NAME: ${{ github.event.inputs.service_name }} + + steps: + - name: Checkout source + uses: actions/checkout@v3 + + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_SA_KEY }} + + - name: Set up GKE credentials + uses: google-github-actions/get-gke-credentials@v1 + with: + cluster_name: ${{ env.GKE_CLUSTER }} + location: ${{ env.REGION }} + project_id: ${{ env.PROJECT_ID }} + + - name: Deploy to GKE + run: | + echo "Deploying service $SERVICE_NAME to cluster $GKE_CLUSTER" + kubectl set image deployment/$SERVICE_NAME $SERVICE_NAME=gcr.io/$PROJECT_ID/$SERVICE_NAME:latest --record From 9a5541f16bd63e83a144c2e644b4ae9560498416 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Sun, 25 May 2025 10:04:01 +0530 Subject: [PATCH 31/75] Create deploy-to-gke-updated.yaml Adding build and Deploy logic in same code --- .github/workflows/deploy-to-gke-updated.yaml | 47 ++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/deploy-to-gke-updated.yaml diff --git a/.github/workflows/deploy-to-gke-updated.yaml b/.github/workflows/deploy-to-gke-updated.yaml new file mode 100644 index 0000000..58007f4 --- /dev/null +++ b/.github/workflows/deploy-to-gke-updated.yaml @@ -0,0 +1,47 @@ +name: CI/CD to GKE + +on: + push: + branches: + - beckn-onix-v1.0-develop + +jobs: + deploy: + name: Build and Deploy to GKE + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v2 + with: + credentials_json: '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}' + + - name: Set up gcloud CLI + uses: google-github-actions/setup-gcloud@v1 + with: + project_id: ${{ secrets.GCP_PROJECT }} + export_default_credentials: true + + - name: Configure Docker to use Artifact Registry + run: gcloud auth configure-docker ${{ secrets.GCP_REGION }}-docker.pkg.dev + + - name: Build Docker Image + run: | + IMAGE_NAME=${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_REPO }}/beckn-onix:${{ github.sha }} + docker build -t $IMAGE_NAME . + docker push $IMAGE_NAME + + - name: Get GKE Credentials + run: | + gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER }} \ + --zone ${{ secrets.GKE_ZONE }} \ + --project ${{ secrets.GCP_PROJECT }} + + - name: Deploy to GKE + run: | + IMAGE_NAME=${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_REPO }}/beckn-onix:${{ github.sha }} + kubectl set image deployment/${{ secrets.DEPLOYMENT_NAME }} ${{ secrets.DEPLOYMENT_NAME }}=$IMAGE_NAME + kubectl rollout status deployment/${{ secrets.DEPLOYMENT_NAME }} From c4580fa13159058bc3ac5e1c3706337fa7eaf4ee Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Sun, 25 May 2025 20:49:13 +0530 Subject: [PATCH 32/75] Update and rename deploy-to-gke-updated.yaml to deploy-to-gke-BS.yaml fixed some errors --- .../{deploy-to-gke-updated.yaml => deploy-to-gke-BS.yaml} | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) rename .github/workflows/{deploy-to-gke-updated.yaml => deploy-to-gke-BS.yaml} (96%) diff --git a/.github/workflows/deploy-to-gke-updated.yaml b/.github/workflows/deploy-to-gke-BS.yaml similarity index 96% rename from .github/workflows/deploy-to-gke-updated.yaml rename to .github/workflows/deploy-to-gke-BS.yaml index 58007f4..0564abe 100644 --- a/.github/workflows/deploy-to-gke-updated.yaml +++ b/.github/workflows/deploy-to-gke-BS.yaml @@ -1,9 +1,7 @@ name: CI/CD to GKE on: - push: - branches: - - beckn-onix-v1.0-develop + workflow_dispatch: jobs: deploy: From 88bc3654f2fa15172754bc252785c737c039d700 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Sun, 25 May 2025 21:16:34 +0530 Subject: [PATCH 33/75] Update deploy-to-gke-BS.yaml dockerfile error fixed --- .github/workflows/deploy-to-gke-BS.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-gke-BS.yaml b/.github/workflows/deploy-to-gke-BS.yaml index 0564abe..8b60c90 100644 --- a/.github/workflows/deploy-to-gke-BS.yaml +++ b/.github/workflows/deploy-to-gke-BS.yaml @@ -29,7 +29,7 @@ jobs: - name: Build Docker Image run: | IMAGE_NAME=${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_REPO }}/beckn-onix:${{ github.sha }} - docker build -t $IMAGE_NAME . + docker build -f Dockerfile.adapter -t $IMAGE_NAME . docker push $IMAGE_NAME - name: Get GKE Credentials From 92c81b6d07576e9bc49a3dcceb83b68c38099e36 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Sun, 25 May 2025 21:23:11 +0530 Subject: [PATCH 34/75] Update and rename deploy-to-gke-BS.yaml to deploy-to-gke-BS.yml name change --- .../workflows/{deploy-to-gke-BS.yaml => deploy-to-gke-BS.yml} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename .github/workflows/{deploy-to-gke-BS.yaml => deploy-to-gke-BS.yml} (97%) diff --git a/.github/workflows/deploy-to-gke-BS.yaml b/.github/workflows/deploy-to-gke-BS.yml similarity index 97% rename from .github/workflows/deploy-to-gke-BS.yaml rename to .github/workflows/deploy-to-gke-BS.yml index 8b60c90..4765302 100644 --- a/.github/workflows/deploy-to-gke-BS.yaml +++ b/.github/workflows/deploy-to-gke-BS.yml @@ -1,6 +1,7 @@ -name: CI/CD to GKE +name: CI/CD to GKE updated on: + push: workflow_dispatch: jobs: From fc7088a48336be52d25a99ae7aefdc7696fd7111 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Sun, 25 May 2025 22:24:09 +0530 Subject: [PATCH 35/75] Update deploy-to-gke-BS.yml fixed the error --- .github/workflows/deploy-to-gke-BS.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-gke-BS.yml b/.github/workflows/deploy-to-gke-BS.yml index 4765302..e1ea771 100644 --- a/.github/workflows/deploy-to-gke-BS.yml +++ b/.github/workflows/deploy-to-gke-BS.yml @@ -36,7 +36,7 @@ jobs: - name: Get GKE Credentials run: | gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER }} \ - --zone ${{ secrets.GKE_ZONE }} \ + --zone ${{ secrets.GCP_REGION }} \ --project ${{ secrets.GCP_PROJECT }} - name: Deploy to GKE From a36ae1f6884905bb27dde05fa0f51c8509719748 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 26 May 2025 09:45:33 +0530 Subject: [PATCH 36/75] Create deployment.yaml --- Deployment/deployment.yaml | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Deployment/deployment.yaml diff --git a/Deployment/deployment.yaml b/Deployment/deployment.yaml new file mode 100644 index 0000000..6443e69 --- /dev/null +++ b/Deployment/deployment.yaml @@ -0,0 +1,40 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: onix-demo-adapter + namespace: onix-demo-saksham #------ +spec: + replicas: 1 + selector: + matchLabels: + app: onix-demo-adapter + template: + metadata: + labels: + app: onix-demo-adapter + annotations: + gke-gcsfuse/volumes: "true" + spec: + serviceAccountName: "onix-adapter-sa" #----------- + containers: + - name: onix-adapter + image: "asia-south1-docker.pkg.dev/trusty-relic-370809/onix-adapter-beta/adapter:latest" #------ + ports: + - containerPort: 8080 + env: + - name: CONFIG_FILE + value: "/mnt/gcs/configs/onix-adapter.yaml" # Updated to GCS path + + volumeMounts: + - name: gcs-bucket + mountPath: /mnt/gcs + readOnly: false + + volumes: + - name: gcs-bucket + csi: + driver: gcsfuse.csi.storage.gke.io + readOnly: false + volumeAttributes: + bucketName: "beckn-onix-demo" #---------- + mountOptions: "implicit-dirs" From b1437d84727d925e8f64f860fb47e6d3fbe705e7 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 26 May 2025 09:46:21 +0530 Subject: [PATCH 37/75] Create service.yaml --- Deployment/service.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Deployment/service.yaml diff --git a/Deployment/service.yaml b/Deployment/service.yaml new file mode 100644 index 0000000..c4be0d8 --- /dev/null +++ b/Deployment/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: onix-adapter-service + namespace: onix-adapter # Namespace +spec: + selector: + app: onix-adapter # This should match the app name in deployment.yaml + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + type: LoadBalancer #NodePort or LoadBalancer From 552a4b1ea9f27602e808eecf2de5667893b4d353 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Mon, 26 May 2025 09:53:30 +0530 Subject: [PATCH 38/75] Update deployment.yaml fixed pointers --- Deployment/deployment.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Deployment/deployment.yaml b/Deployment/deployment.yaml index 6443e69..561fdb5 100644 --- a/Deployment/deployment.yaml +++ b/Deployment/deployment.yaml @@ -2,23 +2,23 @@ apiVersion: apps/v1 kind: Deployment metadata: name: onix-demo-adapter - namespace: onix-demo-saksham #------ + namespace: onix-adapter #------ spec: replicas: 1 selector: matchLabels: - app: onix-demo-adapter + app: onix-adapter template: metadata: labels: - app: onix-demo-adapter + app: onix-adapter annotations: gke-gcsfuse/volumes: "true" spec: - serviceAccountName: "onix-adapter-sa" #----------- + serviceAccountName: "onix-adapter-ksa" #----------- containers: - name: onix-adapter - image: "asia-south1-docker.pkg.dev/trusty-relic-370809/onix-adapter-beta/adapter:latest" #------ + image: "asia-south1-docker.pkg.dev/trusty-relic-370809/onix-adapter-cicd/beckn-onix:latest" #------ ports: - containerPort: 8080 env: @@ -36,5 +36,5 @@ spec: driver: gcsfuse.csi.storage.gke.io readOnly: false volumeAttributes: - bucketName: "beckn-onix-demo" #---------- + bucketName: "beckn-cicd-bucket" #---------- mountOptions: "implicit-dirs" From e1f9a0f9408563fd4059b60655e77f17f00484cc Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Mon, 26 May 2025 10:03:10 +0530 Subject: [PATCH 39/75] Update deploy-to-gke-BS.yml fixed errors --- .github/workflows/deploy-to-gke-BS.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-to-gke-BS.yml b/.github/workflows/deploy-to-gke-BS.yml index e1ea771..c54deaf 100644 --- a/.github/workflows/deploy-to-gke-BS.yml +++ b/.github/workflows/deploy-to-gke-BS.yml @@ -39,8 +39,16 @@ jobs: --zone ${{ secrets.GCP_REGION }} \ --project ${{ secrets.GCP_PROJECT }} - - name: Deploy to GKE + - name: Deploy to GKE using Kubernetes Manifests run: | IMAGE_NAME=${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_REPO }}/beckn-onix:${{ github.sha }} - kubectl set image deployment/${{ secrets.DEPLOYMENT_NAME }} ${{ secrets.DEPLOYMENT_NAME }}=$IMAGE_NAME - kubectl rollout status deployment/${{ secrets.DEPLOYMENT_NAME }} + + # Replace image in deployment YAML + sed -i "s|image: .*|image: $IMAGE_NAME|g" Deployment/deployment.yaml + + # Apply Kubernetes manifests + kubectl apply -f Deployment/deployment.yaml + kubectl apply -f Deployment/service.yaml + + # Wait for rollout to complete + kubectl rollout status Deployment/${{ secrets.DEPLOYMENT_NAME }} From d69cb93f32d29bbaa30c05ab0367327011afd788 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Mon, 26 May 2025 10:08:48 +0530 Subject: [PATCH 40/75] Update deploy-to-gke-BS.yml fixed errors --- .github/workflows/deploy-to-gke-BS.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/deploy-to-gke-BS.yml b/.github/workflows/deploy-to-gke-BS.yml index c54deaf..935f99e 100644 --- a/.github/workflows/deploy-to-gke-BS.yml +++ b/.github/workflows/deploy-to-gke-BS.yml @@ -39,6 +39,11 @@ jobs: --zone ${{ secrets.GCP_REGION }} \ --project ${{ secrets.GCP_PROJECT }} + - name: Install gke-gcloud-auth-plugin + run: | + sudo apt-get update + sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin + - name: Deploy to GKE using Kubernetes Manifests run: | IMAGE_NAME=${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_REPO }}/beckn-onix:${{ github.sha }} From 18fe77d016c60d5d7bd3f49890093b63dff2c79b Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Mon, 26 May 2025 10:15:04 +0530 Subject: [PATCH 41/75] Update deploy-to-gke-BS.yml fixed the errors --- .github/workflows/deploy-to-gke-BS.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-to-gke-BS.yml b/.github/workflows/deploy-to-gke-BS.yml index 935f99e..ef713eb 100644 --- a/.github/workflows/deploy-to-gke-BS.yml +++ b/.github/workflows/deploy-to-gke-BS.yml @@ -24,6 +24,9 @@ jobs: project_id: ${{ secrets.GCP_PROJECT }} export_default_credentials: true + - name: Install GKE Auth Plugin + run: gcloud components install gke-gcloud-auth-plugin --quiet + - name: Configure Docker to use Artifact Registry run: gcloud auth configure-docker ${{ secrets.GCP_REGION }}-docker.pkg.dev @@ -39,11 +42,6 @@ jobs: --zone ${{ secrets.GCP_REGION }} \ --project ${{ secrets.GCP_PROJECT }} - - name: Install gke-gcloud-auth-plugin - run: | - sudo apt-get update - sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin - - name: Deploy to GKE using Kubernetes Manifests run: | IMAGE_NAME=${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT }}/${{ secrets.GCP_REPO }}/beckn-onix:${{ github.sha }} From 87876924b9dffd4e281ac90ef78feeac3475cf27 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Mon, 26 May 2025 14:18:41 +0530 Subject: [PATCH 42/75] Update deploy-to-gke-BS.yml fixed the error --- .github/workflows/deploy-to-gke-BS.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-gke-BS.yml b/.github/workflows/deploy-to-gke-BS.yml index ef713eb..d75dac7 100644 --- a/.github/workflows/deploy-to-gke-BS.yml +++ b/.github/workflows/deploy-to-gke-BS.yml @@ -54,4 +54,4 @@ jobs: kubectl apply -f Deployment/service.yaml # Wait for rollout to complete - kubectl rollout status Deployment/${{ secrets.DEPLOYMENT_NAME }} + kubectl rollout status Deployment/onix-demo-adapter From 9581c3f8acbd3147038491b2086c7ae61e799e73 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Mon, 26 May 2025 14:29:48 +0530 Subject: [PATCH 43/75] Update deploy-to-gke-BS.yml add namespace name --- .github/workflows/deploy-to-gke-BS.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-to-gke-BS.yml b/.github/workflows/deploy-to-gke-BS.yml index d75dac7..2ff81aa 100644 --- a/.github/workflows/deploy-to-gke-BS.yml +++ b/.github/workflows/deploy-to-gke-BS.yml @@ -50,8 +50,8 @@ jobs: sed -i "s|image: .*|image: $IMAGE_NAME|g" Deployment/deployment.yaml # Apply Kubernetes manifests - kubectl apply -f Deployment/deployment.yaml - kubectl apply -f Deployment/service.yaml + kubectl apply -f Deployment/deployment.yaml --namespace=onix-adapter + kubectl apply -f Deployment/service.yaml --namespace=onix-adapter # Wait for rollout to complete - kubectl rollout status Deployment/onix-demo-adapter + kubectl rollout status Deployment/onix-demo-adapter --namespace=onix-adapter From bfda2a1d4226260efc599ba7d0470860f90146cf Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Mon, 26 May 2025 14:42:41 +0530 Subject: [PATCH 44/75] Update build-and-deploy-plugins.yml updated the Plugins path --- .github/workflows/build-and-deploy-plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index 3b76121..c6a1935 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -98,7 +98,7 @@ jobs: - name: Upload to GCS run: | - gsutil -m cp -r $ZIP_FILE gs://${GCS_BUCKET}/ + gsutil -m cp -r $ZIP_FILE gs://${GCS_BUCKET}/plugins/ - name: Cleanup run: | From bb5d7a7f15966e322e1ea1e961d445dec6545cfd Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 27 May 2025 11:48:20 +0530 Subject: [PATCH 45/75] Update build-and-deploy-plugins.yml added input parameter --- .github/workflows/build-and-deploy-plugins.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index c6a1935..c1bbf68 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -3,6 +3,12 @@ name: Build and Upload Plugins on: push: workflow_dispatch: + inputs: + target_branch: + description: 'Branch to deploy' + required: true + default: 'beckn-onix-v1.0-develop' + jobs: build-and-upload: @@ -15,6 +21,12 @@ jobs: steps: - name: Checkout this repo uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.target_branch }} + + - name: Show selected branch + run: echo "Deploying branch:${{ github.event.inputs.target_branch }}" + - name: Clone GitHub and Gerrit plugin repos run: | From 11a3affa180836d31a9a8ee98323504d805b29a3 Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Tue, 27 May 2025 11:51:17 +0530 Subject: [PATCH 46/75] Update build-and-deploy-plugins.yml --- .github/workflows/build-and-deploy-plugins.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-and-deploy-plugins.yml b/.github/workflows/build-and-deploy-plugins.yml index c1bbf68..79c33e0 100644 --- a/.github/workflows/build-and-deploy-plugins.yml +++ b/.github/workflows/build-and-deploy-plugins.yml @@ -1,7 +1,6 @@ name: Build and Upload Plugins on: - push: workflow_dispatch: inputs: target_branch: From 5c5a8b67264c9fd77bcc4fafce1f6d2de3d3bd8e Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Thu, 29 May 2025 11:33:40 +0530 Subject: [PATCH 47/75] Create Terraform Deploy to GCP.yaml initial setup --- .../workflows/Terraform Deploy to GCP.yaml | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/Terraform Deploy to GCP.yaml diff --git a/.github/workflows/Terraform Deploy to GCP.yaml b/.github/workflows/Terraform Deploy to GCP.yaml new file mode 100644 index 0000000..86a5080 --- /dev/null +++ b/.github/workflows/Terraform Deploy to GCP.yaml @@ -0,0 +1,41 @@ +name: Terraform Deploy to GCP + +on: + push: + branches: + - main + +jobs: + terraform: + name: Deploy with Terraform on GCP + runs-on: ubuntu-latest + env: + GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcp-key.json + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.5.0 + + - name: Authenticate to Google Cloud + run: echo "${{ secrets.GCP_CREDENTIALS }}" > gcp-key.json + shell: bash + + - name: Terraform Init + run: terraform init -var="credentials_file=gcp-key.json" + + - name: Terraform Validate + run: terraform validate + + - name: Terraform Plan + run: terraform plan -var="credentials_file=gcp-key.json" -out=tfplan + + - name: Terraform Apply + run: terraform apply -auto-approve tfplan + + - name: Clean up credentials file + run: rm -f gcp-key.json From 3717ea9a23dbcd6f4ad32c2b7db183c3343a5d6b Mon Sep 17 00:00:00 2001 From: BushraS-Protean Date: Mon, 2 Jun 2025 11:28:58 +0530 Subject: [PATCH 48/75] Update Terraform Deploy to GCP.yaml Fixed errors --- .../workflows/Terraform Deploy to GCP.yaml | 59 +++++++++++-------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/.github/workflows/Terraform Deploy to GCP.yaml b/.github/workflows/Terraform Deploy to GCP.yaml index 86a5080..8b524a5 100644 --- a/.github/workflows/Terraform Deploy to GCP.yaml +++ b/.github/workflows/Terraform Deploy to GCP.yaml @@ -1,41 +1,54 @@ name: Terraform Deploy to GCP - + on: - push: - branches: - - main - + workflow_dispatch: # Manual trigger + jobs: terraform: - name: Deploy with Terraform on GCP + name: Deploy GCP Infrastructure runs-on: ubuntu-latest env: GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcp-key.json - + steps: - - name: Checkout repository + - name: Checkout this repository uses: actions/checkout@v3 + + - name: Clone Terraform repo from Gerrit + run: | + git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo + - name: Set up Terraform uses: hashicorp/setup-terraform@v3 with: terraform_version: 1.5.0 - + - name: Authenticate to Google Cloud - run: echo "${{ secrets.GCP_CREDENTIALS }}" > gcp-key.json - shell: bash - - - name: Terraform Init - run: terraform init -var="credentials_file=gcp-key.json" - - - name: Terraform Validate - run: terraform validate - + run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > gcp-key.json + + - name: Terraform Init with backend + working-directory: ./onix-dev/Terraform + run: | + terraform init \ + -backend-config="bucket=your-backend-bucket-name" \ + -backend-config="prefix=terraform/state" \ + -backend-config="credentials=${{ github.workspace }}/gcp-key.json" + + - name: Terraform Plan - run: terraform plan -var="credentials_file=gcp-key.json" -out=tfplan - + working-directory: ./onix-dev/Terraform + run: terraform plan -out=tfplan -var="credentials_file=${{ github.workspace }}/gcp-key.json" + + - name: Wait for Manual Approval + uses: hmarr/auto-approve-action@v2 + if: false # prevents automatic approval + with: + github-token: ${{ secrets.PAT_GITHUB }} + - name: Terraform Apply - run: terraform apply -auto-approve tfplan - - - name: Clean up credentials file + working-directory: ./onix-dev/Terraform + run: terraform apply tfplan + + - name: Clean up credentials run: rm -f gcp-key.json From dbf00b7939d9b2d16e352ad3ff69e9ca6bea8e4a Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 12:14:54 +0530 Subject: [PATCH 49/75] Update Terraform Deploy to GCP.yaml --- .github/workflows/Terraform Deploy to GCP.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Terraform Deploy to GCP.yaml b/.github/workflows/Terraform Deploy to GCP.yaml index 8b524a5..827352e 100644 --- a/.github/workflows/Terraform Deploy to GCP.yaml +++ b/.github/workflows/Terraform Deploy to GCP.yaml @@ -7,8 +7,8 @@ jobs: terraform: name: Deploy GCP Infrastructure runs-on: ubuntu-latest - env: - GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcp-key.json + #env: + # GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcp-key.json steps: - name: Checkout this repository From 681f1846a6629882cf20065057ee611e9fb47c91 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 12:17:48 +0530 Subject: [PATCH 50/75] Rename Terraform Deploy to GCP.yaml to onix-gcp-terraform-deploy.yml --- ...Terraform Deploy to GCP.yaml => onix-gcp-terraform-deploy.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{Terraform Deploy to GCP.yaml => onix-gcp-terraform-deploy.yml} (100%) diff --git a/.github/workflows/Terraform Deploy to GCP.yaml b/.github/workflows/onix-gcp-terraform-deploy.yml similarity index 100% rename from .github/workflows/Terraform Deploy to GCP.yaml rename to .github/workflows/onix-gcp-terraform-deploy.yml From 29ac7111b722556b3eb0caf0806af90498801635 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 12:38:28 +0530 Subject: [PATCH 51/75] Update onix-gcp-terraform-deploy.yml --- .../workflows/onix-gcp-terraform-deploy.yml | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 827352e..96be4b1 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -1,54 +1,40 @@ name: Terraform Deploy to GCP - + on: workflow_dispatch: # Manual trigger - + jobs: - terraform: - name: Deploy GCP Infrastructure + plan: + name: Terraform Plan Only runs-on: ubuntu-latest - #env: - # GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcp-key.json - + steps: - name: Checkout this repository uses: actions/checkout@v3 - + - name: Clone Terraform repo from Gerrit run: | git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo - - name: Set up Terraform uses: hashicorp/setup-terraform@v3 with: terraform_version: 1.5.0 - + - name: Authenticate to Google Cloud - run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > gcp-key.json - + run: echo '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}' > gcp-key.json + - name: Terraform Init with backend - working-directory: ./onix-dev/Terraform + working-directory: ./gerrit-repo/Terraform run: | terraform init \ - -backend-config="bucket=your-backend-bucket-name" \ - -backend-config="prefix=terraform/state" \ + -backend-config="bucket=beckn-state-bucket-bs" \ + -backend-config="prefix=onix-terraform/state" \ -backend-config="credentials=${{ github.workspace }}/gcp-key.json" - - + - name: Terraform Plan - working-directory: ./onix-dev/Terraform - run: terraform plan -out=tfplan -var="credentials_file=${{ github.workspace }}/gcp-key.json" - - - name: Wait for Manual Approval - uses: hmarr/auto-approve-action@v2 - if: false # prevents automatic approval - with: - github-token: ${{ secrets.PAT_GITHUB }} - - - name: Terraform Apply - working-directory: ./onix-dev/Terraform - run: terraform apply tfplan - + working-directory: ./gerrit-repo/Terraform + run: terraform plan -var="credentials_file=${{ github.workspace }}/gcp-key.json" + - name: Clean up credentials run: rm -f gcp-key.json From b714c2470e8992e75a373686c6656a9463e14543 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 13:24:09 +0530 Subject: [PATCH 52/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 96be4b1..6f6c8c7 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -1,7 +1,8 @@ name: Terraform Deploy to GCP on: - workflow_dispatch: # Manual trigger + push: + workflow_dispatch: # Manual trigger jobs: plan: From 358066c5860f9614c8591547664a45edfd3bb5cc Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 13:30:03 +0530 Subject: [PATCH 53/75] Update deploy-to-gke-BS.yml --- .github/workflows/deploy-to-gke-BS.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-to-gke-BS.yml b/.github/workflows/deploy-to-gke-BS.yml index 2ff81aa..d068829 100644 --- a/.github/workflows/deploy-to-gke-BS.yml +++ b/.github/workflows/deploy-to-gke-BS.yml @@ -1,7 +1,7 @@ name: CI/CD to GKE updated on: - push: + #push: workflow_dispatch: jobs: From 1d23dc2e4edde9a460d5b714353ff333b55c2f01 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 13:30:09 +0530 Subject: [PATCH 54/75] Update onix-gcp-terraform-deploy.yml --- .../workflows/onix-gcp-terraform-deploy.yml | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 6f6c8c7..6e6a034 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -16,26 +16,7 @@ jobs: - name: Clone Terraform repo from Gerrit run: | git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo - - - name: Set up Terraform - uses: hashicorp/setup-terraform@v3 - with: - terraform_version: 1.5.0 - - - name: Authenticate to Google Cloud - run: echo '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}' > gcp-key.json - - - name: Terraform Init with backend - working-directory: ./gerrit-repo/Terraform - run: | - terraform init \ - -backend-config="bucket=beckn-state-bucket-bs" \ - -backend-config="prefix=onix-terraform/state" \ - -backend-config="credentials=${{ github.workspace }}/gcp-key.json" - - - name: Terraform Plan - working-directory: ./gerrit-repo/Terraform - run: terraform plan -var="credentials_file=${{ github.workspace }}/gcp-key.json" - - - name: Clean up credentials - run: rm -f gcp-key.json + echo "==== Directory contents after clone ====" + ls -la + echo "==== Contents of gerrit-repo ====" + ls -la gerrit-repo From cbe900f0eea5c20c66d61ad0ecdb755a906b75f2 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 13:31:05 +0530 Subject: [PATCH 55/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 6e6a034..01873a4 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -15,7 +15,7 @@ jobs: - name: Clone Terraform repo from Gerrit run: | - git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo + git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev/Terraform gerrit-repo echo "==== Directory contents after clone ====" ls -la echo "==== Contents of gerrit-repo ====" From 738310b92ebf014dcebb34bf4431c11103d0e13e Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 13:33:33 +0530 Subject: [PATCH 56/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 01873a4..c6611b0 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -15,8 +15,13 @@ jobs: - name: Clone Terraform repo from Gerrit run: | - git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev/Terraform gerrit-repo + git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo echo "==== Directory contents after clone ====" ls -la echo "==== Contents of gerrit-repo ====" ls -la gerrit-repo + echo "==== Contents of Terraform-dir ====" + pwd + cd Terraform + pwd + la -la From 3f8f2ee4395cbb8010a775a8ba55bd6b1b771f77 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 13:36:09 +0530 Subject: [PATCH 57/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index c6611b0..6a81631 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -17,8 +17,10 @@ jobs: run: | git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo echo "==== Directory contents after clone ====" + pwd ls -la echo "==== Contents of gerrit-repo ====" + pwd ls -la gerrit-repo echo "==== Contents of Terraform-dir ====" pwd From 16e892cb21cf2c8bd7e91f54441b26845120fa4f Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 13:38:55 +0530 Subject: [PATCH 58/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 6a81631..d0a1e9e 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -15,7 +15,7 @@ jobs: - name: Clone Terraform repo from Gerrit run: | - git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo + git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev echo "==== Directory contents after clone ====" pwd ls -la From 0f6fa91b15e04d385c6b8a24cb6f6c062597dfd8 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 13:40:47 +0530 Subject: [PATCH 59/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index d0a1e9e..8bd5174 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -15,7 +15,7 @@ jobs: - name: Clone Terraform repo from Gerrit run: | - git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev + git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo echo "==== Directory contents after clone ====" pwd ls -la @@ -24,6 +24,6 @@ jobs: ls -la gerrit-repo echo "==== Contents of Terraform-dir ====" pwd - cd Terraform + cd gerrit-repo/Terraform pwd la -la From 46ad7a74fb9b17c01c378f91f2bf4c5fce1a0b08 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Mon, 2 Jun 2025 13:41:48 +0530 Subject: [PATCH 60/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 8bd5174..82b4183 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -26,4 +26,4 @@ jobs: pwd cd gerrit-repo/Terraform pwd - la -la + ls -la From d9cdedad05afd23600f76891ffa9fef7f7730d76 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 10:39:31 +0530 Subject: [PATCH 61/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 82b4183..6961294 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -16,12 +16,12 @@ jobs: - name: Clone Terraform repo from Gerrit run: | git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo - echo "==== Directory contents after clone ====" - pwd - ls -la - echo "==== Contents of gerrit-repo ====" - pwd - ls -la gerrit-repo + #echo "==== Directory contents after clone ====" + #pwd + #ls -la + #echo "==== Contents of gerrit-repo ====" + #pwd + #ls -la gerrit-repo echo "==== Contents of Terraform-dir ====" pwd cd gerrit-repo/Terraform From 5333b98f2b1ba136370b5c3ceaebe6247c0650fb Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 10:41:27 +0530 Subject: [PATCH 62/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 6961294..01d8d4d 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -24,6 +24,6 @@ jobs: #ls -la gerrit-repo echo "==== Contents of Terraform-dir ====" pwd - cd gerrit-repo/Terraform + cd gerrit-repo/Terraform-CICD pwd ls -la From 3d90ea8cd258325442c017bb8d272147572a23b1 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 10:58:04 +0530 Subject: [PATCH 63/75] Update onix-gcp-terraform-deploy.yml --- .../workflows/onix-gcp-terraform-deploy.yml | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 01d8d4d..1540c3f 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -16,14 +16,28 @@ jobs: - name: Clone Terraform repo from Gerrit run: | git clone https://${{ secrets.GERRIT_USERNAME }}:${{ secrets.GERRIT_PAT }}@open-networks.googlesource.com/onix-dev gerrit-repo - #echo "==== Directory contents after clone ====" - #pwd - #ls -la - #echo "==== Contents of gerrit-repo ====" - #pwd - #ls -la gerrit-repo echo "==== Contents of Terraform-dir ====" pwd cd gerrit-repo/Terraform-CICD pwd ls -la + + - name: Authenticate to Google Cloud + run: echo '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}' > gcp-key.json + + - name: Terraform Init with backend + working-directory: ./gerrit-repo/Terraform-CICD + run: | + terraform init \ + -backend-config="beckn-cicd-tf-state-bucket" \ + -backend-config="prefix=terraform/state" \ + -backend-config="credentials=${{ github.workspace }}/gcp-key.json" + + - name: Terraform Plan + working-directory: ./gerrit-repo/Terraform-CICD + run: terraform plan -var="credentials_file=${{ github.workspace }}/gcp-key.json" + + #- name: Terraform Apply + # working-directory: ./gerrit-repo/Terraform + # run: terraform apply -auto-approve tfplan + From bc4f38b26fc5c4758b0d853d1d615b8e380cad1e Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:00:22 +0530 Subject: [PATCH 64/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 1540c3f..49fd1ac 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -25,11 +25,16 @@ jobs: - name: Authenticate to Google Cloud run: echo '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}' > gcp-key.json + - name: Set up Terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.5.0 + - name: Terraform Init with backend working-directory: ./gerrit-repo/Terraform-CICD run: | terraform init \ - -backend-config="beckn-cicd-tf-state-bucket" \ + -backend-config="bucket=beckn-cicd-tf-state-bucket" \ -backend-config="prefix=terraform/state" \ -backend-config="credentials=${{ github.workspace }}/gcp-key.json" From 067030d58efd0099640644b68ab9273ad231856d Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:05:09 +0530 Subject: [PATCH 65/75] Update onix-gcp-terraform-deploy.yml --- .../workflows/onix-gcp-terraform-deploy.yml | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 49fd1ac..3ffeec2 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -30,13 +30,23 @@ jobs: with: terraform_version: 1.5.0 - - name: Terraform Init with backend + - name: Create backend.tf and Terraform Init working-directory: ./gerrit-repo/Terraform-CICD + env: + GCS_BUCKET: beckn-cicd-tf-state-bucket run: | - terraform init \ - -backend-config="bucket=beckn-cicd-tf-state-bucket" \ - -backend-config="prefix=terraform/state" \ - -backend-config="credentials=${{ github.workspace }}/gcp-key.json" + cat < backend.tf + terraform { + backend "gcs" { + bucket = "${GCS_BUCKET}" + prefix = "terraform/state" + credentials = "${{ github.workspace }}/gcp-key.json" + } + } + EOF + + terraform init + - name: Terraform Plan working-directory: ./gerrit-repo/Terraform-CICD From b4e2e18464e1d3be59ca9e7dbfc1665276c42a6a Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:06:16 +0530 Subject: [PATCH 66/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 3ffeec2..1fce25f 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -50,7 +50,7 @@ jobs: - name: Terraform Plan working-directory: ./gerrit-repo/Terraform-CICD - run: terraform plan -var="credentials_file=${{ github.workspace }}/gcp-key.json" + run: terraform plan #- name: Terraform Apply # working-directory: ./gerrit-repo/Terraform From c5635523675f7d17b4f716986a91b15fac90c114 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:10:06 +0530 Subject: [PATCH 67/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 1fce25f..d1e01d9 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -47,6 +47,18 @@ jobs: terraform init + - name: Create provider.tf with credentials + working-directory: ./gerrit-repo/Terraform-CICD + run: | + cat < provider.tf + provider "google" { + credentials = "${{ github.workspace }}/gcp-key.json" + project = trusty-relic-370809" + region = "asia-south1" + } + EOF + + - name: Terraform Plan working-directory: ./gerrit-repo/Terraform-CICD From bd3a998eb948945d38dd45e39d9558a262229873 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:11:11 +0530 Subject: [PATCH 68/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index d1e01d9..f37932a 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -53,7 +53,7 @@ jobs: cat < provider.tf provider "google" { credentials = "${{ github.workspace }}/gcp-key.json" - project = trusty-relic-370809" + project = "trusty-relic-370809" region = "asia-south1" } EOF From 8792a3cbddb5bd762b71b4f91d26bacda26f5e96 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:15:11 +0530 Subject: [PATCH 69/75] Update onix-gcp-terraform-deploy.yml --- .../workflows/onix-gcp-terraform-deploy.yml | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index f37932a..a0544c4 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -30,6 +30,12 @@ jobs: with: terraform_version: 1.5.0 + - name: Authenticate to Google Cloud + run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > gcp-key.json + + - name: Export GCP Credentials to Terraform + run: echo "GOOGLE_APPLICATION_CREDENTIALS=$GITHUB_WORKSPACE/gcp-key.json" >> $GITHUB_ENV + - name: Create backend.tf and Terraform Init working-directory: ./gerrit-repo/Terraform-CICD env: @@ -46,19 +52,6 @@ jobs: EOF terraform init - - - name: Create provider.tf with credentials - working-directory: ./gerrit-repo/Terraform-CICD - run: | - cat < provider.tf - provider "google" { - credentials = "${{ github.workspace }}/gcp-key.json" - project = "trusty-relic-370809" - region = "asia-south1" - } - EOF - - - name: Terraform Plan working-directory: ./gerrit-repo/Terraform-CICD From e80dff2681fba5268a3082636ac091e0a0355cd0 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:18:00 +0530 Subject: [PATCH 70/75] Update onix-gcp-terraform-deploy.yml sa key --- .github/workflows/onix-gcp-terraform-deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index a0544c4..d68615c 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -30,11 +30,11 @@ jobs: with: terraform_version: 1.5.0 - - name: Authenticate to Google Cloud - run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" > gcp-key.json + - name: Write GCP credentials to file + run: echo '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}' > gcp-key.json - - name: Export GCP Credentials to Terraform - run: echo "GOOGLE_APPLICATION_CREDENTIALS=$GITHUB_WORKSPACE/gcp-key.json" >> $GITHUB_ENV + - name: Export GCP credentials environment variable + run: echo "GOOGLE_APPLICATION_CREDENTIALS=$GITHUB_WORKSPACE/gcp-key.json" >> $GITHUB_ENV - name: Create backend.tf and Terraform Init working-directory: ./gerrit-repo/Terraform-CICD From 47097b9cf68bdc4c8df464ed452644491c9d2bc5 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:19:57 +0530 Subject: [PATCH 71/75] performing terraform appply --- .github/workflows/onix-gcp-terraform-deploy.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index d68615c..9722b55 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -57,7 +57,10 @@ jobs: working-directory: ./gerrit-repo/Terraform-CICD run: terraform plan - #- name: Terraform Apply - # working-directory: ./gerrit-repo/Terraform - # run: terraform apply -auto-approve tfplan + - name: Terraform Apply + working-directory: ./gerrit-repo/Terraform + run: terraform apply -auto-approve tfplan + + - name: Clean up credentials + run: rm -f gcp-key.json From ca4e6215b44c6163a214efac2ec7d44ee6876808 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:20:49 +0530 Subject: [PATCH 72/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 9722b55..744a142 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -59,7 +59,7 @@ jobs: - name: Terraform Apply working-directory: ./gerrit-repo/Terraform - run: terraform apply -auto-approve tfplan + run: terraform apply -auto-approve - name: Clean up credentials run: rm -f gcp-key.json From d06e0b0b995b54cfb3cc32f5a0489b06b6f6b354 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:22:52 +0530 Subject: [PATCH 73/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 744a142..b30efa8 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -58,7 +58,7 @@ jobs: run: terraform plan - name: Terraform Apply - working-directory: ./gerrit-repo/Terraform + working-directory: ./gerrit-repo/Terraform-CICD run: terraform apply -auto-approve - name: Clean up credentials From 18280038ed1f1de07b9bc37d2d686281a68573e5 Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:35:09 +0530 Subject: [PATCH 74/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index b30efa8..41b1998 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -59,7 +59,7 @@ jobs: - name: Terraform Apply working-directory: ./gerrit-repo/Terraform-CICD - run: terraform apply -auto-approve + run: terraform apply -var="subnet_name=onix-gke-subnet" -auto-approve - name: Clean up credentials run: rm -f gcp-key.json From d68db24ff5abaf2bcaf368dc8141872c8afaac8c Mon Sep 17 00:00:00 2001 From: AbhishekHS220 Date: Wed, 4 Jun 2025 11:52:39 +0530 Subject: [PATCH 75/75] Update onix-gcp-terraform-deploy.yml --- .github/workflows/onix-gcp-terraform-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/onix-gcp-terraform-deploy.yml b/.github/workflows/onix-gcp-terraform-deploy.yml index 41b1998..478979b 100644 --- a/.github/workflows/onix-gcp-terraform-deploy.yml +++ b/.github/workflows/onix-gcp-terraform-deploy.yml @@ -2,7 +2,7 @@ name: Terraform Deploy to GCP on: push: - workflow_dispatch: # Manual trigger + workflow_dispatch: # Manual triggerr jobs: plan: