From 5ea35f8e24991a816af6c216ff08e0c2957ae8bd Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 17:48:38 +0100 Subject: [PATCH 01/82] Add client server example --- example/client-server/client/main.go | 135 ++++++++++ example/client-server/proto/proto.pb.go | 259 +++++++++++++++++++ example/client-server/proto/proto.proto | 20 ++ example/client-server/proto/proto_grpc.pb.go | 110 ++++++++ example/client-server/server/main.go | 125 +++++++++ example/client-server/util/env.go | 10 + go.mod | 3 +- go.sum | 8 + 8 files changed, 669 insertions(+), 1 deletion(-) create mode 100644 example/client-server/client/main.go create mode 100644 example/client-server/proto/proto.pb.go create mode 100644 example/client-server/proto/proto.proto create mode 100644 example/client-server/proto/proto_grpc.pb.go create mode 100644 example/client-server/server/main.go create mode 100644 example/client-server/util/env.go diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go new file mode 100644 index 0000000..2de9e51 --- /dev/null +++ b/example/client-server/client/main.go @@ -0,0 +1,135 @@ +package main + +import ( + "context" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" + + "github.com/gruntwork-io/terragrunt-engine-go/engine" + "github.com/hashicorp/go-plugin" + log "github.com/sirupsen/logrus" + "time" + + pb "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/proto" + tgengine "github.com/gruntwork-io/terragrunt-engine-go/proto" + "google.golang.org/grpc" +) + +type Command struct { + Command string + WorkingDir string + EnvVars map[string]string +} + +type CommandOutput struct { + Output string + Error string + ExitCode int32 +} + +func Run(command *Command) (*CommandOutput, error) { + connectAddress := util.GetEnv("CONNECT_ADDRESS", "localhost:50051") + log.Printf("Connecting to %s", connectAddress) + conn, err := grpc.Dial(connectAddress, grpc.WithInsecure(), grpc.WithBlock()) + if err != nil { + return nil, err + } + defer conn.Close() + + client := pb.NewShellServiceClient(conn) + + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + resp, err := client.RunCommand(ctx, &pb.CommandRequest{ + Command: command.Command, + WorkingDir: command.WorkingDir, + EnvVars: command.EnvVars, + }) + if err != nil { + return nil, err + } + + output := &CommandOutput{ + Output: resp.Output, + Error: resp.Error, + ExitCode: resp.ExitCode, + } + return output, nil +} + +type ClientServerEngine struct { + tgengine.UnimplementedEngineServer +} + +func (c *ClientServerEngine) Init(req *tgengine.InitRequest, stream tgengine.Engine_InitServer) error { + err := stream.Send(&tgengine.InitResponse{Stdout: "Client server engine initialized\n", Stderr: "", ResultCode: 0}) + if err != nil { + return err + } + return nil +} + +func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engine_RunServer) error { + log.Infof("Run client server plugin %v", req.WorkingDir) + + iacCommand := util.GetEnv("IAC_COMMAND", "tofu") + + // build run command + command := iacCommand + "" + for _, value := range req.Args { + command += " " + value + } + req.EnvVars["TF_IN_AUTOMATION"] = "true" + + output, err := Run(&Command{ + Command: command, + WorkingDir: req.WorkingDir, + EnvVars: req.EnvVars, + }) + if err != nil { + return err + } + err = stream.Send(&tgengine.RunResponse{ + Stdout: output.Output, + Stderr: output.Error, + ResultCode: output.ExitCode, + }) + if err != nil { + return err + } + + return nil +} + +func (c *ClientServerEngine) Shutdown(req *tgengine.ShutdownRequest, stream tgengine.Engine_ShutdownServer) error { + err := stream.Send(&tgengine.ShutdownResponse{Stdout: "Client server engine shutdown\n", Stderr: "", ResultCode: 0}) + if err != nil { + return err + } + return nil +} + +// GRPCServer is used to register the TofuEngine with the gRPC server +func (c *ClientServerEngine) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { + tgengine.RegisterEngineServer(s, c) + return nil +} + +// GRPCClient is used to create a client that connects to the TofuEngine +func (c *ClientServerEngine) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, client *grpc.ClientConn) (interface{}, error) { + return tgengine.NewEngineClient(client), nil +} + +func main() { + plugin.Serve(&plugin.ServeConfig{ + HandshakeConfig: plugin.HandshakeConfig{ + ProtocolVersion: 1, + MagicCookieKey: "engine", + MagicCookieValue: "terragrunt", + }, + Plugins: map[string]plugin.Plugin{ + "client-server-engine": &engine.TerragruntGRPCEngine{Impl: &ClientServerEngine{}}, + }, + GRPCServer: plugin.DefaultGRPCServer, + }) +} diff --git a/example/client-server/proto/proto.pb.go b/example/client-server/proto/proto.pb.go new file mode 100644 index 0000000..444d9d2 --- /dev/null +++ b/example/client-server/proto/proto.pb.go @@ -0,0 +1,259 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.34.2 +// protoc v3.12.4 +// source: proto/proto.proto + +package proto + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type CommandRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Command string `protobuf:"bytes,1,opt,name=command,proto3" json:"command,omitempty"` + WorkingDir string `protobuf:"bytes,2,opt,name=working_dir,json=workingDir,proto3" json:"working_dir,omitempty"` + EnvVars map[string]string `protobuf:"bytes,3,rep,name=env_vars,json=envVars,proto3" json:"env_vars,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *CommandRequest) Reset() { + *x = CommandRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_proto_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CommandRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CommandRequest) ProtoMessage() {} + +func (x *CommandRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_proto_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CommandRequest.ProtoReflect.Descriptor instead. +func (*CommandRequest) Descriptor() ([]byte, []int) { + return file_proto_proto_proto_rawDescGZIP(), []int{0} +} + +func (x *CommandRequest) GetCommand() string { + if x != nil { + return x.Command + } + return "" +} + +func (x *CommandRequest) GetWorkingDir() string { + if x != nil { + return x.WorkingDir + } + return "" +} + +func (x *CommandRequest) GetEnvVars() map[string]string { + if x != nil { + return x.EnvVars + } + return nil +} + +type CommandResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Output string `protobuf:"bytes,1,opt,name=output,proto3" json:"output,omitempty"` + ExitCode int32 `protobuf:"varint,2,opt,name=exit_code,json=exitCode,proto3" json:"exit_code,omitempty"` + Error string `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"` +} + +func (x *CommandResponse) Reset() { + *x = CommandResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_proto_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CommandResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CommandResponse) ProtoMessage() {} + +func (x *CommandResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_proto_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CommandResponse.ProtoReflect.Descriptor instead. +func (*CommandResponse) Descriptor() ([]byte, []int) { + return file_proto_proto_proto_rawDescGZIP(), []int{1} +} + +func (x *CommandResponse) GetOutput() string { + if x != nil { + return x.Output + } + return "" +} + +func (x *CommandResponse) GetExitCode() int32 { + if x != nil { + return x.ExitCode + } + return 0 +} + +func (x *CommandResponse) GetError() string { + if x != nil { + return x.Error + } + return "" +} + +var File_proto_proto_proto protoreflect.FileDescriptor + +var file_proto_proto_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc6, 0x01, 0x0a, 0x0e, 0x43, + 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, + 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x69, + 0x6e, 0x67, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x77, 0x6f, + 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x44, 0x69, 0x72, 0x12, 0x3d, 0x0a, 0x08, 0x65, 0x6e, 0x76, 0x5f, + 0x76, 0x61, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x2e, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, + 0x65, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x1a, 0x3a, 0x0a, 0x0c, 0x45, 0x6e, 0x76, 0x56, 0x61, + 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, + 0x02, 0x38, 0x01, 0x22, 0x5c, 0x0a, 0x0f, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x1b, + 0x0a, 0x09, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x08, 0x65, 0x78, 0x69, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, + 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, + 0x72, 0x32, 0x4b, 0x0a, 0x0c, 0x53, 0x68, 0x65, 0x6c, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x3b, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, + 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, + 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x09, + 0x5a, 0x07, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, +} + +var ( + file_proto_proto_proto_rawDescOnce sync.Once + file_proto_proto_proto_rawDescData = file_proto_proto_proto_rawDesc +) + +func file_proto_proto_proto_rawDescGZIP() []byte { + file_proto_proto_proto_rawDescOnce.Do(func() { + file_proto_proto_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_proto_proto_rawDescData) + }) + return file_proto_proto_proto_rawDescData +} + +var file_proto_proto_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_proto_proto_proto_goTypes = []any{ + (*CommandRequest)(nil), // 0: proto.CommandRequest + (*CommandResponse)(nil), // 1: proto.CommandResponse + nil, // 2: proto.CommandRequest.EnvVarsEntry +} +var file_proto_proto_proto_depIdxs = []int32{ + 2, // 0: proto.CommandRequest.env_vars:type_name -> proto.CommandRequest.EnvVarsEntry + 0, // 1: proto.ShellService.RunCommand:input_type -> proto.CommandRequest + 1, // 2: proto.ShellService.RunCommand:output_type -> proto.CommandResponse + 2, // [2:3] is the sub-list for method output_type + 1, // [1:2] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_proto_proto_proto_init() } +func file_proto_proto_proto_init() { + if File_proto_proto_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_proto_proto_msgTypes[0].Exporter = func(v any, i int) any { + switch v := v.(*CommandRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_proto_proto_msgTypes[1].Exporter = func(v any, i int) any { + switch v := v.(*CommandResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_proto_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_proto_proto_goTypes, + DependencyIndexes: file_proto_proto_proto_depIdxs, + MessageInfos: file_proto_proto_proto_msgTypes, + }.Build() + File_proto_proto_proto = out.File + file_proto_proto_proto_rawDesc = nil + file_proto_proto_proto_goTypes = nil + file_proto_proto_proto_depIdxs = nil +} diff --git a/example/client-server/proto/proto.proto b/example/client-server/proto/proto.proto new file mode 100644 index 0000000..7957055 --- /dev/null +++ b/example/client-server/proto/proto.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package proto; +option go_package = "./proto"; + +service ShellService { + rpc RunCommand (CommandRequest) returns (CommandResponse); +} + +message CommandRequest { + string command = 1; + string working_dir = 2; + map env_vars = 3; +} + +message CommandResponse { + string output = 1; + int32 exit_code = 2; + string error = 3; +} diff --git a/example/client-server/proto/proto_grpc.pb.go b/example/client-server/proto/proto_grpc.pb.go new file mode 100644 index 0000000..c2dc9cf --- /dev/null +++ b/example/client-server/proto/proto_grpc.pb.go @@ -0,0 +1,110 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.4.0 +// - protoc v3.12.4 +// source: proto/proto.proto + +package proto + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.62.0 or later. +const _ = grpc.SupportPackageIsVersion8 + +const ( + ShellService_RunCommand_FullMethodName = "/proto.ShellService/RunCommand" +) + +// ShellServiceClient is the client API for ShellService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ShellServiceClient interface { + RunCommand(ctx context.Context, in *CommandRequest, opts ...grpc.CallOption) (*CommandResponse, error) +} + +type shellServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewShellServiceClient(cc grpc.ClientConnInterface) ShellServiceClient { + return &shellServiceClient{cc} +} + +func (c *shellServiceClient) RunCommand(ctx context.Context, in *CommandRequest, opts ...grpc.CallOption) (*CommandResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(CommandResponse) + err := c.cc.Invoke(ctx, ShellService_RunCommand_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ShellServiceServer is the server API for ShellService service. +// All implementations must embed UnimplementedShellServiceServer +// for forward compatibility +type ShellServiceServer interface { + RunCommand(context.Context, *CommandRequest) (*CommandResponse, error) + mustEmbedUnimplementedShellServiceServer() +} + +// UnimplementedShellServiceServer must be embedded to have forward compatible implementations. +type UnimplementedShellServiceServer struct { +} + +func (UnimplementedShellServiceServer) RunCommand(context.Context, *CommandRequest) (*CommandResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RunCommand not implemented") +} +func (UnimplementedShellServiceServer) mustEmbedUnimplementedShellServiceServer() {} + +// UnsafeShellServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ShellServiceServer will +// result in compilation errors. +type UnsafeShellServiceServer interface { + mustEmbedUnimplementedShellServiceServer() +} + +func RegisterShellServiceServer(s grpc.ServiceRegistrar, srv ShellServiceServer) { + s.RegisterService(&ShellService_ServiceDesc, srv) +} + +func _ShellService_RunCommand_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CommandRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ShellServiceServer).RunCommand(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ShellService_RunCommand_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ShellServiceServer).RunCommand(ctx, req.(*CommandRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ShellService_ServiceDesc is the grpc.ServiceDesc for ShellService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ShellService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "proto.ShellService", + HandlerType: (*ShellServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "RunCommand", + Handler: _ShellService_RunCommand_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "proto/proto.proto", +} diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go new file mode 100644 index 0000000..32c4f61 --- /dev/null +++ b/example/client-server/server/main.go @@ -0,0 +1,125 @@ +package main + +import ( + "context" + "google.golang.org/grpc" + "io" + "net" + "os" + "os/exec" + + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" + + pb "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/proto" + log "github.com/sirupsen/logrus" +) + +// ShellServiceServer implements the ShellService defined in the proto file. +type ShellServiceServer struct { + pb.UnimplementedShellServiceServer +} + +func (s *ShellServiceServer) RunCommand(ctx context.Context, req *pb.CommandRequest) (*pb.CommandResponse, error) { + log.Infof("Running command: %s in %s", req.Command, req.WorkingDir) + for key, value := range req.EnvVars { + log.Infof("Env: %s=%s", key, value) + } + cmd := exec.Command("bash", "-c", req.Command) + + // Set the working directory if provided + if req.WorkingDir != "" { + cmd.Dir = req.WorkingDir + } + + // Set the environment variables if provided + if len(req.EnvVars) > 0 { + env := os.Environ() + for key, value := range req.EnvVars { + env = append(env, key+"="+value) + } + cmd.Env = env + } + + // Create pipes for stdin, stdout, and stderr + stdin, err := cmd.StdinPipe() + if err != nil { + return nil, err + } + stdout, err := cmd.StdoutPipe() + if err != nil { + return nil, err + } + stderr, err := cmd.StderrPipe() + if err != nil { + return nil, err + } + + // Start the command + if err := cmd.Start(); err != nil { + return nil, err + } + + // Close stdin as we're not sending any input + stdin.Close() + + // Read stdout and stderr + outputChan := make(chan string) + errorChan := make(chan string) + + go readOutput(stdout, outputChan) + go readOutput(stderr, errorChan) + + // Wait for the command to finish + err = cmd.Wait() + + // Collect output and error + output := <-outputChan + errorOutput := <-errorChan + + exitCode := 0 + if err != nil { + if exitError, ok := err.(*exec.ExitError); ok { + exitCode = exitError.ExitCode() + } + } + + return &pb.CommandResponse{ + Output: output, + ExitCode: int32(exitCode), + Error: errorOutput, + }, nil +} + +func readOutput(r io.Reader, ch chan<- string) { + var output string + buf := make([]byte, 1024) + for { + n, err := r.Read(buf) + if n > 0 { + output += string(buf[:n]) + } + if err != nil { + break + } + } + ch <- output +} + +// Serve starts the gRPC server +func Serve() { + listenAddress := util.GetEnv("LISTEN_ADDRESS", ":50051") + listener, err := net.Listen("tcp", listenAddress) + if err != nil { + log.Fatalf("Failed to listen: %v", err) + } + grpcServer := grpc.NewServer() + pb.RegisterShellServiceServer(grpcServer, &ShellServiceServer{}) + log.Println("Server is running on port " + listenAddress) + if err := grpcServer.Serve(listener); err != nil { + log.Fatalf("Failed to serve: %v", err) + } +} + +func main() { + Serve() +} diff --git a/example/client-server/util/env.go b/example/client-server/util/env.go new file mode 100644 index 0000000..0cdb1a3 --- /dev/null +++ b/example/client-server/util/env.go @@ -0,0 +1,10 @@ +package util + +import "os" + +func GetEnv(key, defaultValue string) string { + if value, exists := os.LookupEnv(key); exists { + return value + } + return defaultValue +} diff --git a/go.mod b/go.mod index 589b654..7c95340 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/golang/protobuf v1.5.4 github.com/hashicorp/go-plugin v1.6.1 - github.com/stretchr/testify v1.2.2 + github.com/stretchr/testify v1.7.0 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 ) @@ -20,6 +20,7 @@ require ( github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect github.com/oklog/run v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/sirupsen/logrus v1.9.3 // indirect golang.org/x/net v0.27.0 // indirect golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect diff --git a/go.sum b/go.sum index e5bcf35..7ad9dbd 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= @@ -27,14 +28,19 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= 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/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= @@ -51,3 +57,5 @@ google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From a9cdc21f0292f62a20015ed31b7d82a0439e3b7f Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 18:13:54 +0100 Subject: [PATCH 02/82] Examples update --- example/client-server/client/main.go | 4 +++- example/client-server/proto/proto.pb.go | 5 +++-- example/client-server/proto/proto_grpc.pb.go | 1 + example/client-server/server/main.go | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index 2de9e51..93811ed 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -2,12 +2,14 @@ package main import ( "context" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" + "time" + "github.com/gruntwork-io/terragrunt-engine-go/engine" "github.com/hashicorp/go-plugin" log "github.com/sirupsen/logrus" - "time" pb "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/proto" tgengine "github.com/gruntwork-io/terragrunt-engine-go/proto" diff --git a/example/client-server/proto/proto.pb.go b/example/client-server/proto/proto.pb.go index 444d9d2..5df0171 100644 --- a/example/client-server/proto/proto.pb.go +++ b/example/client-server/proto/proto.pb.go @@ -7,10 +7,11 @@ package proto import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const ( diff --git a/example/client-server/proto/proto_grpc.pb.go b/example/client-server/proto/proto_grpc.pb.go index c2dc9cf..8e2db3d 100644 --- a/example/client-server/proto/proto_grpc.pb.go +++ b/example/client-server/proto/proto_grpc.pb.go @@ -8,6 +8,7 @@ package proto import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go index 32c4f61..4da47c3 100644 --- a/example/client-server/server/main.go +++ b/example/client-server/server/main.go @@ -2,12 +2,13 @@ package main import ( "context" - "google.golang.org/grpc" "io" "net" "os" "os/exec" + "google.golang.org/grpc" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" pb "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/proto" From 744ee90802ef5594a2c748194242efd0d660300c Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 18:14:18 +0100 Subject: [PATCH 03/82] Dependencies update --- go.mod | 3 ++- go.sum | 12 +++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 7c95340..618dbbf 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.21 require ( github.com/golang/protobuf v1.5.4 github.com/hashicorp/go-plugin v1.6.1 + github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.7.0 google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 @@ -20,9 +21,9 @@ require ( github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect github.com/oklog/run v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/sirupsen/logrus v1.9.3 // indirect golang.org/x/net v0.27.0 // indirect golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect ) diff --git a/go.sum b/go.sum index 7ad9dbd..52ed98a 100644 --- a/go.sum +++ b/go.sum @@ -31,31 +31,25 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 h1:Di6ANFilr+S60a4S61ZM00vLdw0IrQOSMS2/6mrnOU0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:JU0iKnSg02Gmb5ZdV8nYsKEKsP6o/FGVWTrw4i1DA9A= google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= -google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= -google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From d2c63185946e4af351419d69ef913113f096f196 Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 18:20:01 +0100 Subject: [PATCH 04/82] proto engine build --- Makefile | 6 +- example/client-server/proto/proto.pb.go | 117 ++++++++++--------- example/client-server/proto/proto_grpc.pb.go | 4 +- example/client-server/server/main.go | 1 + 4 files changed, 67 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index 6e8fe48..e75e7f2 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,14 @@ tools: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.4.0 go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2 -protoc: $(shell find . -name '*.proto') +protoc: $(shell find ./proto -name '*.proto') protoc --go_out=. --go_opt=paths=source_relative proto/engine.proto protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/engine.proto +protoc-examples: $(shell find ./example/client-server -name '*.proto') + protoc --go_out=. --go_opt=paths=source_relative example/client-server/proto/proto.proto + protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative example/client-server/proto/proto.proto + pre-commit: pre-commit run --all-files diff --git a/example/client-server/proto/proto.pb.go b/example/client-server/proto/proto.pb.go index 5df0171..69afc2d 100644 --- a/example/client-server/proto/proto.pb.go +++ b/example/client-server/proto/proto.pb.go @@ -2,7 +2,7 @@ // versions: // protoc-gen-go v1.34.2 // protoc v3.12.4 -// source: proto/proto.proto +// source: example/client-server/proto/proto.proto package proto @@ -34,7 +34,7 @@ type CommandRequest struct { func (x *CommandRequest) Reset() { *x = CommandRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_proto_proto_msgTypes[0] + mi := &file_example_client_server_proto_proto_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -47,7 +47,7 @@ func (x *CommandRequest) String() string { func (*CommandRequest) ProtoMessage() {} func (x *CommandRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_proto_proto_msgTypes[0] + mi := &file_example_client_server_proto_proto_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -60,7 +60,7 @@ func (x *CommandRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandRequest.ProtoReflect.Descriptor instead. func (*CommandRequest) Descriptor() ([]byte, []int) { - return file_proto_proto_proto_rawDescGZIP(), []int{0} + return file_example_client_server_proto_proto_proto_rawDescGZIP(), []int{0} } func (x *CommandRequest) GetCommand() string { @@ -97,7 +97,7 @@ type CommandResponse struct { func (x *CommandResponse) Reset() { *x = CommandResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_proto_proto_msgTypes[1] + mi := &file_example_client_server_proto_proto_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -110,7 +110,7 @@ func (x *CommandResponse) String() string { func (*CommandResponse) ProtoMessage() {} func (x *CommandResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_proto_proto_msgTypes[1] + mi := &file_example_client_server_proto_proto_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -123,7 +123,7 @@ func (x *CommandResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandResponse.ProtoReflect.Descriptor instead. func (*CommandResponse) Descriptor() ([]byte, []int) { - return file_proto_proto_proto_rawDescGZIP(), []int{1} + return file_example_client_server_proto_proto_proto_rawDescGZIP(), []int{1} } func (x *CommandResponse) GetOutput() string { @@ -147,57 +147,58 @@ func (x *CommandResponse) GetError() string { return "" } -var File_proto_proto_proto protoreflect.FileDescriptor +var File_example_client_server_proto_proto_proto protoreflect.FileDescriptor -var file_proto_proto_proto_rawDesc = []byte{ - 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc6, 0x01, 0x0a, 0x0e, 0x43, - 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, - 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x69, - 0x6e, 0x67, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x77, 0x6f, - 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x44, 0x69, 0x72, 0x12, 0x3d, 0x0a, 0x08, 0x65, 0x6e, 0x76, 0x5f, - 0x76, 0x61, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x2e, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, - 0x65, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x1a, 0x3a, 0x0a, 0x0c, 0x45, 0x6e, 0x76, 0x56, 0x61, - 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, - 0x02, 0x38, 0x01, 0x22, 0x5c, 0x0a, 0x0f, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x1b, - 0x0a, 0x09, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x08, 0x65, 0x78, 0x69, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, - 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, - 0x72, 0x32, 0x4b, 0x0a, 0x0c, 0x53, 0x68, 0x65, 0x6c, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x12, 0x3b, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, - 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, - 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x09, - 0x5a, 0x07, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, +var file_example_client_server_proto_proto_proto_rawDesc = []byte{ + 0x0a, 0x27, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, + 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x22, 0xc6, 0x01, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x1f, 0x0a, + 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x44, 0x69, 0x72, 0x12, 0x3d, + 0x0a, 0x08, 0x65, 0x6e, 0x76, 0x5f, 0x76, 0x61, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x65, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x1a, 0x3a, 0x0a, + 0x0c, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x5c, 0x0a, 0x0f, 0x43, 0x6f, 0x6d, + 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x65, 0x78, 0x69, 0x74, 0x43, 0x6f, 0x64, + 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x32, 0x4b, 0x0a, 0x0c, 0x53, 0x68, 0x65, 0x6c, 0x6c, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, + 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, + 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_proto_proto_proto_rawDescOnce sync.Once - file_proto_proto_proto_rawDescData = file_proto_proto_proto_rawDesc + file_example_client_server_proto_proto_proto_rawDescOnce sync.Once + file_example_client_server_proto_proto_proto_rawDescData = file_example_client_server_proto_proto_proto_rawDesc ) -func file_proto_proto_proto_rawDescGZIP() []byte { - file_proto_proto_proto_rawDescOnce.Do(func() { - file_proto_proto_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_proto_proto_rawDescData) +func file_example_client_server_proto_proto_proto_rawDescGZIP() []byte { + file_example_client_server_proto_proto_proto_rawDescOnce.Do(func() { + file_example_client_server_proto_proto_proto_rawDescData = protoimpl.X.CompressGZIP(file_example_client_server_proto_proto_proto_rawDescData) }) - return file_proto_proto_proto_rawDescData + return file_example_client_server_proto_proto_proto_rawDescData } -var file_proto_proto_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_proto_proto_proto_goTypes = []any{ +var file_example_client_server_proto_proto_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_example_client_server_proto_proto_proto_goTypes = []any{ (*CommandRequest)(nil), // 0: proto.CommandRequest (*CommandResponse)(nil), // 1: proto.CommandResponse nil, // 2: proto.CommandRequest.EnvVarsEntry } -var file_proto_proto_proto_depIdxs = []int32{ +var file_example_client_server_proto_proto_proto_depIdxs = []int32{ 2, // 0: proto.CommandRequest.env_vars:type_name -> proto.CommandRequest.EnvVarsEntry 0, // 1: proto.ShellService.RunCommand:input_type -> proto.CommandRequest 1, // 2: proto.ShellService.RunCommand:output_type -> proto.CommandResponse @@ -208,13 +209,13 @@ var file_proto_proto_proto_depIdxs = []int32{ 0, // [0:1] is the sub-list for field type_name } -func init() { file_proto_proto_proto_init() } -func file_proto_proto_proto_init() { - if File_proto_proto_proto != nil { +func init() { file_example_client_server_proto_proto_proto_init() } +func file_example_client_server_proto_proto_proto_init() { + if File_example_client_server_proto_proto_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_proto_proto_proto_msgTypes[0].Exporter = func(v any, i int) any { + file_example_client_server_proto_proto_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*CommandRequest); i { case 0: return &v.state @@ -226,7 +227,7 @@ func file_proto_proto_proto_init() { return nil } } - file_proto_proto_proto_msgTypes[1].Exporter = func(v any, i int) any { + file_example_client_server_proto_proto_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*CommandResponse); i { case 0: return &v.state @@ -243,18 +244,18 @@ func file_proto_proto_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_proto_proto_proto_rawDesc, + RawDescriptor: file_example_client_server_proto_proto_proto_rawDesc, NumEnums: 0, NumMessages: 3, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_proto_proto_proto_goTypes, - DependencyIndexes: file_proto_proto_proto_depIdxs, - MessageInfos: file_proto_proto_proto_msgTypes, + GoTypes: file_example_client_server_proto_proto_proto_goTypes, + DependencyIndexes: file_example_client_server_proto_proto_proto_depIdxs, + MessageInfos: file_example_client_server_proto_proto_proto_msgTypes, }.Build() - File_proto_proto_proto = out.File - file_proto_proto_proto_rawDesc = nil - file_proto_proto_proto_goTypes = nil - file_proto_proto_proto_depIdxs = nil + File_example_client_server_proto_proto_proto = out.File + file_example_client_server_proto_proto_proto_rawDesc = nil + file_example_client_server_proto_proto_proto_goTypes = nil + file_example_client_server_proto_proto_proto_depIdxs = nil } diff --git a/example/client-server/proto/proto_grpc.pb.go b/example/client-server/proto/proto_grpc.pb.go index 8e2db3d..5b09cda 100644 --- a/example/client-server/proto/proto_grpc.pb.go +++ b/example/client-server/proto/proto_grpc.pb.go @@ -2,7 +2,7 @@ // versions: // - protoc-gen-go-grpc v1.4.0 // - protoc v3.12.4 -// source: proto/proto.proto +// source: example/client-server/proto/proto.proto package proto @@ -107,5 +107,5 @@ var ShellService_ServiceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "proto/proto.proto", + Metadata: "example/client-server/proto/proto.proto", } diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go index 4da47c3..0468264 100644 --- a/example/client-server/server/main.go +++ b/example/client-server/server/main.go @@ -25,6 +25,7 @@ func (s *ShellServiceServer) RunCommand(ctx context.Context, req *pb.CommandRequ for key, value := range req.EnvVars { log.Infof("Env: %s=%s", key, value) } + // run command in bash cmd := exec.Command("bash", "-c", req.Command) // Set the working directory if provided From 901f5637d1999112785af33a17b88b9ef80076c0 Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 19:21:11 +0100 Subject: [PATCH 05/82] Examples building --- .gitignore | 2 ++ Makefile | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/.gitignore b/.gitignore index 2bc21d7..d2c1226 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,6 @@ vendor .DS_Store mocks/ .go-version +terragrunt-engine-client +terragrunt-engine-server diff --git a/Makefile b/Makefile index e75e7f2..88e1ef9 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,17 @@ protoc-examples: $(shell find ./example/client-server -name '*.proto') protoc --go_out=. --go_opt=paths=source_relative example/client-server/proto/proto.proto protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative example/client-server/proto/proto.proto +examples: + set -xe ;\ + vtag=$$(git describe --tags --abbrev=12 --dirty --broken) ;\ + cd example/client-server ;\ + cd client ;\ + go build -o terragrunt-engine-client -ldflags "-X github.com/gruntwork-io/go-commons/version.Version=$${vtag} -extldflags '-static'" . ;\ + cd .. ;\ + cd server ;\ + go build -o terragrunt-engine-server -ldflags "-X github.com/gruntwork-io/go-commons/version.Version=$${vtag} -extldflags '-static'" . + + pre-commit: pre-commit run --all-files From 7260c1e2736513671a6bb1deab8e8afa180b888c Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 19:41:42 +0100 Subject: [PATCH 06/82] Add meta printing --- example/client-server/client/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index 93811ed..6855914 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -73,7 +73,7 @@ func (c *ClientServerEngine) Init(req *tgengine.InitRequest, stream tgengine.Eng func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engine_RunServer) error { log.Infof("Run client server plugin %v", req.WorkingDir) - + log.Infof("Run client with meta %v", req.Meta) iacCommand := util.GetEnv("IAC_COMMAND", "tofu") // build run command From 1313f5f6bd724da599b5046b11a403a85af6d703 Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 19:43:24 +0100 Subject: [PATCH 07/82] Update debug command --- example/client-server/client/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index 6855914..0f990c0 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -72,8 +72,10 @@ func (c *ClientServerEngine) Init(req *tgengine.InitRequest, stream tgengine.Eng } func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engine_RunServer) error { - log.Infof("Run client server plugin %v", req.WorkingDir) - log.Infof("Run client with meta %v", req.Meta) + log.Infof("Run client command: %v", req.Command) + log.Infof("Run client args: %v", req.Args) + log.Infof("Run client dir: %v", req.WorkingDir) + log.Infof("Run client meta: %v", req.Meta) iacCommand := util.GetEnv("IAC_COMMAND", "tofu") // build run command From ea108dc7198a20b2ca9ce0a4d5d7edac70b733c6 Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 19:48:15 +0100 Subject: [PATCH 08/82] Add example cicd --- .circleci/config.yml | 72 +++++++++++++++++++++++++++++++++++++++++++- .gon_amd64.hcl | 18 +++++++++++ .gon_arm64.hcl | 18 +++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 .gon_amd64.hcl create mode 100644 .gon_arm64.hcl diff --git a/.circleci/config.yml b/.circleci/config.yml index 7a91342..8e8ae99 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ env: &env environment: GO111MODULE: auto GRUNTWORK_INSTALLER_VERSION: v0.0.36 - MODULE_CI_VERSION: v0.54.0 + MODULE_CI_VERSION: v0.57.0 TERRATEST_LOG_PARSER_VERSION: v0.37.0 GOLANG_VERSION: 1.21.1 defaults: &defaults @@ -80,6 +80,62 @@ jobs: path: logs - store_test_results: path: logs + release: + <<: *env + macos: + xcode: 15.3.0 + resource_class: macos.m1.medium.gen1 + steps: + - checkout + - attach_workspace: + at: . + - go/install: + version: "1.21.1" + - run: + name: Install sign-binary-helpers + command: | + curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}" + gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" + gruntwork-install --module-name "sign-binary-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" + - run: + name: Compile and sign the binaries + command: | + export AC_PASSWORD=${MACOS_AC_PASSWORD} + export AC_PROVIDER=${MACOS_AC_PROVIDER} + + sign-binary --os mac --install-macos-sign-dependencies .gon_amd64.hcl + sign-binary --os mac .gon_arm64.hcl + echo "Done signing the binary" + mkdir -p bin + + # Replace the files in bin. These are the same file names generated from .gon_amd64.hcl and .gon_arm64.hcl + unzip terragrunt-iac-engine-opentofu_amd64.zip + mv terragrunt-iac-engine-opentofu_darwin_amd64 bin/ + + unzip terragrunt-iac-engine-opentofu_arm64.zip + mv terragrunt-iac-engine-opentofu_darwin_arm64 bin/ + - run: + name: Install required packages + command: | + brew install coreutils gpg gh + # setting sign key + echo "${GW_ENGINE_GPG_KEY}" | base64 --decode > privatekey.asc + echo "${GW_ENGINE_GPG_KEY_PW}" | gpg --batch --yes --import privatekey.asc + KEY_ID=$(gpg --list-keys --with-colons | awk -F: '/^pub/{print $5}') + echo -e "trust\n5\ny\n" | gpg --command-fd 0 --edit-key $KEY_ID trust + mkdir -p ~/.gnupg + echo "default-key $KEY_ID" >> ~/.gnupg/gpg.conf + - run: + name: Package release files + command: | + export TAG="${CIRCLE_TAG}" + ./.circleci/sign-files.sh + ./.circleci/create-release.sh + - persist_to_workspace: + root: . + paths: [release] + - store_artifacts: + path: release #---------------------------------------------------------------------------------------------------------------------- # WORKFLOWS #---------------------------------------------------------------------------------------------------------------------- @@ -106,3 +162,17 @@ workflows: filters: tags: only: /^v.*/ + - release: + requires: + - precommit +# filters: +# tags: +# only: /^.*-rc.*$/ +# branches: +# ignore: /.*/ + context: + - AWS__PHXDEVOPS__circle-ci-test + - GCP__automated-tests + - GITHUB__PAT__gruntwork-ci + - APPLE__OSX__code-signing + - TERRAGRUNT_ENGINE__circle-ci \ No newline at end of file diff --git a/.gon_amd64.hcl b/.gon_amd64.hcl new file mode 100644 index 0000000..e40be57 --- /dev/null +++ b/.gon_amd64.hcl @@ -0,0 +1,18 @@ +# See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ +# for further instructions on how to sign the binary + submitting for notarization. + +source = ["./bin/terragrunt-iac-engine-opentofu_darwin_amd64"] + +bundle_id = "io.gruntwork.app.terragrunt" + +apple_id { + username = "machine.apple@gruntwork.io" +} + +sign { + application_identity = "Developer ID Application: Gruntwork, Inc." +} + +zip { + output_path = "terragrunt-iac-engine-opentofu_amd64.zip" +} diff --git a/.gon_arm64.hcl b/.gon_arm64.hcl new file mode 100644 index 0000000..6e74b96 --- /dev/null +++ b/.gon_arm64.hcl @@ -0,0 +1,18 @@ +# See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ +# for further instructions on how to sign the binary + submitting for notarization. + +source = ["./bin/terragrunt-iac-engine-opentofu_darwin_arm64"] + +bundle_id = "io.gruntwork.app.terragrunt" + +apple_id { + username = "machine.apple@gruntwork.io" +} + +sign { + application_identity = "Developer ID Application: Gruntwork, Inc." +} + +zip { + output_path = "terragrunt-iac-engine-opentofu_arm64.zip" +} From 57f129d72d98ca099f8fe37f6b1afbfc2d82dbe6 Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 20:17:13 +0100 Subject: [PATCH 09/82] Cleanup update --- .circleci/config.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8e8ae99..a793c64 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,3 +1,10 @@ +version: 2.1 + +orbs: + win: circleci/windows@5.0 + go: circleci/go@1.11 + + env: &env environment: GO111MODULE: auto @@ -6,9 +13,8 @@ env: &env TERRATEST_LOG_PARSER_VERSION: v0.37.0 GOLANG_VERSION: 1.21.1 defaults: &defaults - machine: - enabled: true - image: ubuntu-2004:2022.10.1 + docker: + - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg58.8-pck1.8-ci56.0 <<: *env run_precommit: &run_precommit # Fail the build if the pre-commit hooks don't pass. Note: if you run $ pre-commit install locally within this repo, these hooks will @@ -30,7 +36,7 @@ install_gruntwork_utils: &install_gruntwork_utils --terragrunt-version "NONE" \ --packer-version "NONE" \ --go-version ${GOLANG_VERSION} -version: 2.1 + #---------------------------------------------------------------------------------------------------------------------- # BUILD JOBS #---------------------------------------------------------------------------------------------------------------------- From 741230f3896d6f9d30725b75b903f4571ac4b728 Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 20:30:30 +0100 Subject: [PATCH 10/82] add client server building --- .circleci/config.yml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a793c64..bff5e15 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -86,6 +86,30 @@ jobs: path: logs - store_test_results: path: logs + build: + resource_class: xlarge + <<: *defaults + steps: + - checkout + - run: + <<: *install_gruntwork_utils + - run: | + go mod tidy + pushd . + cd example/client-server/client + build-go-binaries --app-name terragrunt-iac-engine-client --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" + popd + cd example/client-server/server + build-go-binaries --app-name terragrunt-iac-engine-server --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" + - persist_to_workspace: + root: . + paths: + - example/client-server/client/bin + - example/client-server/server/bin + - store_artifacts: + path: example/client-server/client/bin + - store_artifacts: + path: example/client-server/server/bin release: <<: *env macos: @@ -168,10 +192,13 @@ workflows: filters: tags: only: /^v.*/ - - release: + - build: requires: - precommit -# filters: + - release: + requires: + - build + # filters: # tags: # only: /^.*-rc.*$/ # branches: From e45ec61cb9332ffbb334d4ca4d592ae256b4290b Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 21:03:54 +0100 Subject: [PATCH 11/82] Error check --- example/client-server/client/main.go | 21 ++++++++++++++------- example/client-server/server/main.go | 14 ++++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index 0f990c0..2aa3e93 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -2,9 +2,7 @@ package main import ( "context" - "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" - "time" "github.com/gruntwork-io/terragrunt-engine-go/engine" @@ -35,7 +33,12 @@ func Run(command *Command) (*CommandOutput, error) { if err != nil { return nil, err } - defer conn.Close() + defer func() { + err := conn.Close() + if err != nil { + log.Errorf("Error closing connection: %v", err) + } + }() client := pb.NewShellServiceClient(conn) @@ -113,14 +116,18 @@ func (c *ClientServerEngine) Shutdown(req *tgengine.ShutdownRequest, stream tgen return nil } -// GRPCServer is used to register the TofuEngine with the gRPC server -func (c *ClientServerEngine) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error { +// GRPCServer is used to register with the gRPC server +// +//nolint:unparam // result 0 (error) is always nil +func (c *ClientServerEngine) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error { tgengine.RegisterEngineServer(s, c) return nil } -// GRPCClient is used to create a client that connects to the TofuEngine -func (c *ClientServerEngine) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, client *grpc.ClientConn) (interface{}, error) { +// GRPCClient is used to create a client that connects to the +// +//nolint:unparam // result 0 (error) is always nil +func (c *ClientServerEngine) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, client *grpc.ClientConn) (interface{}, error) { return tgengine.NewEngineClient(client), nil } diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go index 0468264..9359a1e 100644 --- a/example/client-server/server/main.go +++ b/example/client-server/server/main.go @@ -15,12 +15,14 @@ import ( log "github.com/sirupsen/logrus" ) +const readBufferSize = 1024 + // ShellServiceServer implements the ShellService defined in the proto file. type ShellServiceServer struct { pb.UnimplementedShellServiceServer } -func (s *ShellServiceServer) RunCommand(ctx context.Context, req *pb.CommandRequest) (*pb.CommandResponse, error) { +func (s *ShellServiceServer) RunCommand(_ context.Context, req *pb.CommandRequest) (*pb.CommandResponse, error) { log.Infof("Running command: %s in %s", req.Command, req.WorkingDir) for key, value := range req.EnvVars { log.Infof("Env: %s=%s", key, value) @@ -61,8 +63,12 @@ func (s *ShellServiceServer) RunCommand(ctx context.Context, req *pb.CommandRequ return nil, err } - // Close stdin as we're not sending any input - stdin.Close() + defer func() { + err := stdin.Close() + if err != nil { + log.Errorf("Error closing stdin: %v", err) + } + }() // Read stdout and stderr outputChan := make(chan string) @@ -94,7 +100,7 @@ func (s *ShellServiceServer) RunCommand(ctx context.Context, req *pb.CommandRequ func readOutput(r io.Reader, ch chan<- string) { var output string - buf := make([]byte, 1024) + buf := make([]byte, readBufferSize) for { n, err := r.Read(buf) if n > 0 { From 9abcfa94c5bd469234c2ae6aa78b71381b63168e Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 21:04:24 +0100 Subject: [PATCH 12/82] import update --- example/client-server/client/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index 2aa3e93..b8e176d 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -2,9 +2,10 @@ package main import ( "context" - "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" "time" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" + "github.com/gruntwork-io/terragrunt-engine-go/engine" "github.com/hashicorp/go-plugin" log "github.com/sirupsen/logrus" From 5ec6c80876848b7d9375b698bda3598149c6cc59 Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 21:11:08 +0100 Subject: [PATCH 13/82] Add examples --- example/client-server/client/main.go | 9 ++++----- example/client-server/server/main.go | 5 +---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index b8e176d..5baa79b 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -4,6 +4,8 @@ import ( "context" "time" + "google.golang.org/grpc/credentials/insecure" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" "github.com/gruntwork-io/terragrunt-engine-go/engine" @@ -30,15 +32,12 @@ type CommandOutput struct { func Run(command *Command) (*CommandOutput, error) { connectAddress := util.GetEnv("CONNECT_ADDRESS", "localhost:50051") log.Printf("Connecting to %s", connectAddress) - conn, err := grpc.Dial(connectAddress, grpc.WithInsecure(), grpc.WithBlock()) + conn, err := grpc.NewClient(connectAddress, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, err } defer func() { - err := conn.Close() - if err != nil { - log.Errorf("Error closing connection: %v", err) - } + _ = conn.Close() }() client := pb.NewShellServiceClient(conn) diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go index 9359a1e..a3aab32 100644 --- a/example/client-server/server/main.go +++ b/example/client-server/server/main.go @@ -64,10 +64,7 @@ func (s *ShellServiceServer) RunCommand(_ context.Context, req *pb.CommandReques } defer func() { - err := stdin.Close() - if err != nil { - log.Errorf("Error closing stdin: %v", err) - } + _ = stdin.Close() }() // Read stdout and stderr From 6a3cc587294a85d819f82063c7988e95ef33ae36 Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 21:17:18 +0100 Subject: [PATCH 14/82] circle ci update --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bff5e15..fa41999 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,6 @@ orbs: win: circleci/windows@5.0 go: circleci/go@1.11 - env: &env environment: GO111MODULE: auto @@ -12,10 +11,12 @@ env: &env MODULE_CI_VERSION: v0.57.0 TERRATEST_LOG_PARSER_VERSION: v0.37.0 GOLANG_VERSION: 1.21.1 + defaults: &defaults docker: - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg58.8-pck1.8-ci56.0 <<: *env + run_precommit: &run_precommit # Fail the build if the pre-commit hooks don't pass. Note: if you run $ pre-commit install locally within this repo, these hooks will # execute automatically every time before you commit, ensuring the build never fails at this step! From 9ab3c68ad97634f60ba37cdb2017ab09d49a2e30 Mon Sep 17 00:00:00 2001 From: Denis O Date: Thu, 15 Aug 2024 21:20:40 +0100 Subject: [PATCH 15/82] build update --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fa41999..a01d2aa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ orbs: env: &env environment: GO111MODULE: auto - GRUNTWORK_INSTALLER_VERSION: v0.0.36 + GRUNTWORK_INSTALLER_VERSION: v0.0.39 MODULE_CI_VERSION: v0.57.0 TERRATEST_LOG_PARSER_VERSION: v0.37.0 GOLANG_VERSION: 1.21.1 From e0ae75567ab397431066c9d459e13e2e20e80319 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 12:51:54 +0100 Subject: [PATCH 16/82] Circle ci build update --- .circleci/config.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a01d2aa..c16d7e9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,10 +12,17 @@ env: &env TERRATEST_LOG_PARSER_VERSION: v0.37.0 GOLANG_VERSION: 1.21.1 +machine: + enabled: true + image: ubuntu-2004:2022.10.1 + docker: + - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg39.1-pck1.8-ci54.0 + <<: *env + defaults: &defaults docker: - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg58.8-pck1.8-ci56.0 - <<: *env + run_precommit: &run_precommit # Fail the build if the pre-commit hooks don't pass. Note: if you run $ pre-commit install locally within this repo, these hooks will @@ -44,8 +51,6 @@ install_gruntwork_utils: &install_gruntwork_utils jobs: precommit: <<: *env - docker: - - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg39.1-pck1.8-ci54.0 steps: - checkout # Fail the build if the pre-commit hooks don't pass. Note: if you run pre-commit install locally, these hooks will From 11ec4b8e9f42320054273142abf60f013ad0ec65 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 13:00:47 +0100 Subject: [PATCH 17/82] Circle ci cleanup --- .circleci/config.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c16d7e9..d31200f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 orbs: win: circleci/windows@5.0 - go: circleci/go@1.11 + go: circleci/go@1.22 env: &env environment: @@ -20,6 +20,7 @@ machine: <<: *env defaults: &defaults + <<: *env docker: - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg58.8-pck1.8-ci56.0 @@ -31,6 +32,7 @@ run_precommit: &run_precommit command: | pre-commit install pre-commit run --all-files + install_gruntwork_utils: &install_gruntwork_utils name: install gruntwork utils command: | @@ -38,6 +40,7 @@ install_gruntwork_utils: &install_gruntwork_utils gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" gruntwork-install --module-name "git-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" gruntwork-install --binary-name "terratest_log_parser" --repo "https://github.com/gruntwork-io/terratest" --tag "${TERRATEST_LOG_PARSER_VERSION}" + gruntwork-install --module-name "sign-binary-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" configure-environment-for-gruntwork-module \ --mise-version "NONE" \ --terraform-version "NONE" \ @@ -50,7 +53,7 @@ install_gruntwork_utils: &install_gruntwork_utils #---------------------------------------------------------------------------------------------------------------------- jobs: precommit: - <<: *env + <<: *defaults steps: - checkout # Fail the build if the pre-commit hooks don't pass. Note: if you run pre-commit install locally, these hooks will @@ -117,7 +120,7 @@ jobs: - store_artifacts: path: example/client-server/server/bin release: - <<: *env + <<: *defaults macos: xcode: 15.3.0 resource_class: macos.m1.medium.gen1 @@ -128,11 +131,7 @@ jobs: - go/install: version: "1.21.1" - run: - name: Install sign-binary-helpers - command: | - curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}" - gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" - gruntwork-install --module-name "sign-binary-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" + <<: *install_gruntwork_utils - run: name: Compile and sign the binaries command: | From 940ffab59eed87bb335eb9e95fa43f5c80007ecb Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 13:06:36 +0100 Subject: [PATCH 18/82] Cleanup --- .circleci/config.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d31200f..2ae77f6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,8 +15,6 @@ env: &env machine: enabled: true image: ubuntu-2004:2022.10.1 - docker: - - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg39.1-pck1.8-ci54.0 <<: *env defaults: &defaults From e8652d12d6e838f619dfc0b02d106cd6c4c9aa5d Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 13:19:06 +0100 Subject: [PATCH 19/82] Circle ci update --- .circleci/config.yml | 111 ++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ae77f6..5b2091f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,6 +15,8 @@ env: &env machine: enabled: true image: ubuntu-2004:2022.10.1 + docker: + - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg39.1-pck1.8-ci54.0 <<: *env defaults: &defaults @@ -117,58 +119,57 @@ jobs: path: example/client-server/client/bin - store_artifacts: path: example/client-server/server/bin - release: - <<: *defaults - macos: - xcode: 15.3.0 - resource_class: macos.m1.medium.gen1 - steps: - - checkout - - attach_workspace: - at: . - - go/install: - version: "1.21.1" - - run: - <<: *install_gruntwork_utils - - run: - name: Compile and sign the binaries - command: | - export AC_PASSWORD=${MACOS_AC_PASSWORD} - export AC_PROVIDER=${MACOS_AC_PROVIDER} - - sign-binary --os mac --install-macos-sign-dependencies .gon_amd64.hcl - sign-binary --os mac .gon_arm64.hcl - echo "Done signing the binary" - mkdir -p bin - - # Replace the files in bin. These are the same file names generated from .gon_amd64.hcl and .gon_arm64.hcl - unzip terragrunt-iac-engine-opentofu_amd64.zip - mv terragrunt-iac-engine-opentofu_darwin_amd64 bin/ - - unzip terragrunt-iac-engine-opentofu_arm64.zip - mv terragrunt-iac-engine-opentofu_darwin_arm64 bin/ - - run: - name: Install required packages - command: | - brew install coreutils gpg gh - # setting sign key - echo "${GW_ENGINE_GPG_KEY}" | base64 --decode > privatekey.asc - echo "${GW_ENGINE_GPG_KEY_PW}" | gpg --batch --yes --import privatekey.asc - KEY_ID=$(gpg --list-keys --with-colons | awk -F: '/^pub/{print $5}') - echo -e "trust\n5\ny\n" | gpg --command-fd 0 --edit-key $KEY_ID trust - mkdir -p ~/.gnupg - echo "default-key $KEY_ID" >> ~/.gnupg/gpg.conf - - run: - name: Package release files - command: | - export TAG="${CIRCLE_TAG}" - ./.circleci/sign-files.sh - ./.circleci/create-release.sh - - persist_to_workspace: - root: . - paths: [release] - - store_artifacts: - path: release +# release: +# macos: +# xcode: 15.3.0 +# resource_class: macos.m1.medium.gen1 +# steps: +# - checkout +# - attach_workspace: +# at: . +# - go/install: +# version: "1.21.1" +# - run: +# <<: *install_gruntwork_utils +# - run: +# name: Compile and sign the binaries +# command: | +# export AC_PASSWORD=${MACOS_AC_PASSWORD} +# export AC_PROVIDER=${MACOS_AC_PROVIDER} +# +# sign-binary --os mac --install-macos-sign-dependencies .gon_amd64.hcl +# sign-binary --os mac .gon_arm64.hcl +# echo "Done signing the binary" +# mkdir -p bin +# +# # Replace the files in bin. These are the same file names generated from .gon_amd64.hcl and .gon_arm64.hcl +# unzip terragrunt-iac-engine-opentofu_amd64.zip +# mv terragrunt-iac-engine-opentofu_darwin_amd64 bin/ +# +# unzip terragrunt-iac-engine-opentofu_arm64.zip +# mv terragrunt-iac-engine-opentofu_darwin_arm64 bin/ +# - run: +# name: Install required packages +# command: | +# brew install coreutils gpg gh +# # setting sign key +# echo "${GW_ENGINE_GPG_KEY}" | base64 --decode > privatekey.asc +# echo "${GW_ENGINE_GPG_KEY_PW}" | gpg --batch --yes --import privatekey.asc +# KEY_ID=$(gpg --list-keys --with-colons | awk -F: '/^pub/{print $5}') +# echo -e "trust\n5\ny\n" | gpg --command-fd 0 --edit-key $KEY_ID trust +# mkdir -p ~/.gnupg +# echo "default-key $KEY_ID" >> ~/.gnupg/gpg.conf +# - run: +# name: Package release files +# command: | +# export TAG="${CIRCLE_TAG}" +# ./.circleci/sign-files.sh +# ./.circleci/create-release.sh +# - persist_to_workspace: +# root: . +# paths: [release] +# - store_artifacts: +# path: release #---------------------------------------------------------------------------------------------------------------------- # WORKFLOWS #---------------------------------------------------------------------------------------------------------------------- @@ -198,9 +199,9 @@ workflows: - build: requires: - precommit - - release: - requires: - - build +# - release: +# requires: +# - build # filters: # tags: # only: /^.*-rc.*$/ From f8ebe563bae6ac3a680f95195a0142590c0904da Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 13:20:40 +0100 Subject: [PATCH 20/82] circleci/go@1.11 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5b2091f..a697dad 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 orbs: win: circleci/windows@5.0 - go: circleci/go@1.22 + go: circleci/go@1.11 env: &env environment: From 1c33f066c00bf7ec3bce3b4a1b9fffead85208dd Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 15:07:48 +0100 Subject: [PATCH 21/82] updated signing --- .circleci/config.yml | 107 +++++++++++++++++++++---------------------- .gon_amd64.hcl | 4 +- .gon_arm64.hcl | 4 +- 3 files changed, 56 insertions(+), 59 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a697dad..19dc216 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,8 +15,6 @@ env: &env machine: enabled: true image: ubuntu-2004:2022.10.1 - docker: - - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg39.1-pck1.8-ci54.0 <<: *env defaults: &defaults @@ -24,7 +22,6 @@ defaults: &defaults docker: - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg58.8-pck1.8-ci56.0 - run_precommit: &run_precommit # Fail the build if the pre-commit hooks don't pass. Note: if you run $ pre-commit install locally within this repo, these hooks will # execute automatically every time before you commit, ensuring the build never fails at this step! @@ -88,7 +85,6 @@ jobs: - run: name: Terratest log parser command: | - gruntwork-install --binary-name 'terratest_log_parser' --repo 'https://github.com/gruntwork-io/terratest' --tag 'v0.30.0' terratest_log_parser --testlog logs/tests.log --outputdir logs when: always - store_artifacts: @@ -119,57 +115,58 @@ jobs: path: example/client-server/client/bin - store_artifacts: path: example/client-server/server/bin -# release: -# macos: -# xcode: 15.3.0 -# resource_class: macos.m1.medium.gen1 -# steps: -# - checkout -# - attach_workspace: -# at: . -# - go/install: -# version: "1.21.1" -# - run: -# <<: *install_gruntwork_utils -# - run: -# name: Compile and sign the binaries -# command: | -# export AC_PASSWORD=${MACOS_AC_PASSWORD} -# export AC_PROVIDER=${MACOS_AC_PROVIDER} -# -# sign-binary --os mac --install-macos-sign-dependencies .gon_amd64.hcl -# sign-binary --os mac .gon_arm64.hcl -# echo "Done signing the binary" -# mkdir -p bin -# -# # Replace the files in bin. These are the same file names generated from .gon_amd64.hcl and .gon_arm64.hcl -# unzip terragrunt-iac-engine-opentofu_amd64.zip -# mv terragrunt-iac-engine-opentofu_darwin_amd64 bin/ -# -# unzip terragrunt-iac-engine-opentofu_arm64.zip -# mv terragrunt-iac-engine-opentofu_darwin_arm64 bin/ -# - run: -# name: Install required packages -# command: | -# brew install coreutils gpg gh -# # setting sign key -# echo "${GW_ENGINE_GPG_KEY}" | base64 --decode > privatekey.asc -# echo "${GW_ENGINE_GPG_KEY_PW}" | gpg --batch --yes --import privatekey.asc -# KEY_ID=$(gpg --list-keys --with-colons | awk -F: '/^pub/{print $5}') -# echo -e "trust\n5\ny\n" | gpg --command-fd 0 --edit-key $KEY_ID trust -# mkdir -p ~/.gnupg -# echo "default-key $KEY_ID" >> ~/.gnupg/gpg.conf -# - run: -# name: Package release files -# command: | -# export TAG="${CIRCLE_TAG}" -# ./.circleci/sign-files.sh -# ./.circleci/create-release.sh -# - persist_to_workspace: -# root: . -# paths: [release] -# - store_artifacts: -# path: release + + release: + macos: + xcode: 15.3.0 + resource_class: macos.m1.medium.gen1 + steps: + - checkout + - attach_workspace: + at: . + - go/install: + version: "1.21.1" + - run: + <<: *install_gruntwork_utils + - run: + name: Compile and sign the binaries + command: | + export AC_PASSWORD=${MACOS_AC_PASSWORD} + export AC_PROVIDER=${MACOS_AC_PROVIDER} + + sign-binary --os mac --install-macos-sign-dependencies .gon_amd64.hcl + sign-binary --os mac .gon_arm64.hcl + echo "Done signing the binary" + mkdir -p bin + + # Replace the files in bin. These are the same file names generated from .gon_amd64.hcl and .gon_arm64.hcl + unzip terragrunt-iac-engine-client-server_amd64.zip + mv terragrunt-iac-engine-opentofu_darwin_amd64 bin/ + + unzip terragrunt-iac-engine-client-server_arm64.zip + mv terragrunt-iac-engine-opentofu_darwin_arm64 bin/ + - run: + name: Install required packages + command: | + brew install coreutils gpg gh + # setting sign key + echo "${GW_ENGINE_GPG_KEY}" | base64 --decode > privatekey.asc + echo "${GW_ENGINE_GPG_KEY_PW}" | gpg --batch --yes --import privatekey.asc + KEY_ID=$(gpg --list-keys --with-colons | awk -F: '/^pub/{print $5}') + echo -e "trust\n5\ny\n" | gpg --command-fd 0 --edit-key $KEY_ID trust + mkdir -p ~/.gnupg + echo "default-key $KEY_ID" >> ~/.gnupg/gpg.conf + - run: + name: Package release files + command: | + export TAG="${CIRCLE_TAG}" + ./.circleci/sign-files.sh + ./.circleci/create-release.sh + - persist_to_workspace: + root: . + paths: [release] + - store_artifacts: + path: release #---------------------------------------------------------------------------------------------------------------------- # WORKFLOWS #---------------------------------------------------------------------------------------------------------------------- diff --git a/.gon_amd64.hcl b/.gon_amd64.hcl index e40be57..af1fa8e 100644 --- a/.gon_amd64.hcl +++ b/.gon_amd64.hcl @@ -1,7 +1,7 @@ # See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ # for further instructions on how to sign the binary + submitting for notarization. -source = ["./bin/terragrunt-iac-engine-opentofu_darwin_amd64"] +source = ["./example/client-server/client/bin/terragrunt-iac-engine-client_darwin_amd64", "example/client-server/client/bin/terragrunt-iac-engine-server_darwin_amd64"] bundle_id = "io.gruntwork.app.terragrunt" @@ -14,5 +14,5 @@ sign { } zip { - output_path = "terragrunt-iac-engine-opentofu_amd64.zip" + output_path = "terragrunt-iac-engine-client-server_amd64.zip" } diff --git a/.gon_arm64.hcl b/.gon_arm64.hcl index 6e74b96..d165f02 100644 --- a/.gon_arm64.hcl +++ b/.gon_arm64.hcl @@ -1,7 +1,7 @@ # See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ # for further instructions on how to sign the binary + submitting for notarization. -source = ["./bin/terragrunt-iac-engine-opentofu_darwin_arm64"] +source = ["./example/client-server/client/bin/terragrunt-iac-engine-client_darwin_arm64", "example/client-server/client/bin/terragrunt-iac-engine-server_darwin_arm64"] bundle_id = "io.gruntwork.app.terragrunt" @@ -14,5 +14,5 @@ sign { } zip { - output_path = "terragrunt-iac-engine-opentofu_arm64.zip" + output_path = "terragrunt-iac-engine-client-server_arm64.zip" } From ee5870fd16e81d179785acee010a1c86d2280ffc Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 15:13:43 +0100 Subject: [PATCH 22/82] release update --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 19dc216..e0bbd52 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -196,9 +196,9 @@ workflows: - build: requires: - precommit -# - release: -# requires: -# - build + - release: + requires: + - build # filters: # tags: # only: /^.*-rc.*$/ From 6b1adededd78b0794cdabde1986f866beab663bb Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 15:17:08 +0100 Subject: [PATCH 23/82] docker image --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index e0bbd52..9d73101 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -15,6 +15,8 @@ env: &env machine: enabled: true image: ubuntu-2004:2022.10.1 + docker: + - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg39.1-pck1.8-ci54.0 <<: *env defaults: &defaults From d4e81f06a401676a24a6cfe339253b41ec4bb531 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 15:23:09 +0100 Subject: [PATCH 24/82] Defaults update --- .circleci/config.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d73101..9dc8d13 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,14 +12,10 @@ env: &env TERRATEST_LOG_PARSER_VERSION: v0.37.0 GOLANG_VERSION: 1.21.1 -machine: - enabled: true - image: ubuntu-2004:2022.10.1 - docker: - - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg39.1-pck1.8-ci54.0 - <<: *env - defaults: &defaults + machine: + enabled: true + image: ubuntu-2004:2022.10.1 <<: *env docker: - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg58.8-pck1.8-ci56.0 From e66c50ccfcf796ceae7d56efd801fad5aff15db3 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 15:24:24 +0100 Subject: [PATCH 25/82] removed machine block --- .circleci/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9dc8d13..a341ea9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,9 +13,6 @@ env: &env GOLANG_VERSION: 1.21.1 defaults: &defaults - machine: - enabled: true - image: ubuntu-2004:2022.10.1 <<: *env docker: - image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.21.9-tf1.5-tg58.8-pck1.8-ci56.0 From 83db6d02c81f921e807f5adc605e3a0de9fbf609 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 15:26:24 +0100 Subject: [PATCH 26/82] Build context --- .circleci/config.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index a341ea9..666f201 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -191,6 +191,12 @@ workflows: - build: requires: - precommit + context: + - AWS__PHXDEVOPS__circle-ci-test + - GCP__automated-tests + - GITHUB__PAT__gruntwork-ci + - APPLE__OSX__code-signing + - TERRAGRUNT_ENGINE__circle-ci - release: requires: - build From b28c17db241b406c57d743de5e61608ed4647564 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 15:31:15 +0100 Subject: [PATCH 27/82] Add env install --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 666f201..6e7d55f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -112,6 +112,7 @@ jobs: path: example/client-server/server/bin release: + <<: *env macos: xcode: 15.3.0 resource_class: macos.m1.medium.gen1 From 583bdd8766d142f91821070dfd6932bae98a1216 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 17:58:51 +0100 Subject: [PATCH 28/82] Added client server setup --- .circleci/config.yml | 3 +- engine/meta.go | 48 ++++++++++++++ example/client-server/README.md | 6 ++ example/client-server/client/main.go | 8 +++ example/client-server/proto/proto.pb.go | 70 +++++++++++--------- example/client-server/proto/proto.proto | 7 +- example/client-server/proto/proto_grpc.pb.go | 1 - example/client-server/server/main.go | 28 +++++--- 8 files changed, 126 insertions(+), 45 deletions(-) create mode 100644 engine/meta.go create mode 100644 example/client-server/README.md diff --git a/.circleci/config.yml b/.circleci/config.yml index 6e7d55f..2a22b7b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -120,8 +120,7 @@ jobs: - checkout - attach_workspace: at: . - - go/install: - version: "1.21.1" + - run: <<: *install_gruntwork_utils - run: diff --git a/engine/meta.go b/engine/meta.go new file mode 100644 index 0000000..c142c5f --- /dev/null +++ b/engine/meta.go @@ -0,0 +1,48 @@ +package engine + +import ( + "encoding/json" + "fmt" + "github.com/gruntwork-io/terragrunt-engine-go/proto" + log "github.com/sirupsen/logrus" + "google.golang.org/protobuf/types/known/structpb" + "strconv" +) + +// Meta extract request.Meta to go map[string]interface{} struct. +func Meta(request *proto.RunRequest) (map[string]interface{}, error) { + protoMeta := request.Meta + meta := make(map[string]interface{}) + for key, anyValue := range protoMeta { + var value structpb.Value + if err := anyValue.UnmarshalTo(&value); err != nil { + return nil, fmt.Errorf("error unmarshaling any value to structpb.Value: %w", err) + } + jsonData, err := value.MarshalJSON() + if err != nil { + return nil, fmt.Errorf("error marshaling structpb.Value to JSON: %w", err) + } + var result interface{} + if err := json.Unmarshal(jsonData, &result); err != nil { + return nil, fmt.Errorf("error unmarshaling JSON to interface{}: %w", err) + } + meta[key] = result + } + + return meta, nil +} + +// MetaString returns the value of a meta key from the RunRequest. If the key does not exist, an empty string is returned. +func MetaString(request *proto.RunRequest, key string) (string, error) { + meta, err := Meta(request) + log.Printf("Meta: %v", meta) + if err != nil { + return "", err + } + value, ok := meta[key] + log.Printf("value: %v", value) + if !ok { + return "", nil + } + return strconv.Unquote(fmt.Sprintf("%v", value)) +} diff --git a/example/client-server/README.md b/example/client-server/README.md new file mode 100644 index 0000000..c6c1e85 --- /dev/null +++ b/example/client-server/README.md @@ -0,0 +1,6 @@ +# Engine Client - Server implementation + + +``` +terragrunt-engine-server --token secret-token +``` \ No newline at end of file diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index 5baa79b..26e08f2 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -18,6 +18,7 @@ import ( ) type Command struct { + Token string Command string WorkingDir string EnvVars map[string]string @@ -49,6 +50,7 @@ func Run(command *Command) (*CommandOutput, error) { Command: command.Command, WorkingDir: command.WorkingDir, EnvVars: command.EnvVars, + Token: command.Token, }) if err != nil { return nil, err @@ -81,6 +83,11 @@ func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engin log.Infof("Run client meta: %v", req.Meta) iacCommand := util.GetEnv("IAC_COMMAND", "tofu") + token, err := engine.MetaString(req, "token") + if err != nil { + return err + } + // build run command command := iacCommand + "" for _, value := range req.Args { @@ -92,6 +99,7 @@ func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engin Command: command, WorkingDir: req.WorkingDir, EnvVars: req.EnvVars, + Token: token, }) if err != nil { return err diff --git a/example/client-server/proto/proto.pb.go b/example/client-server/proto/proto.pb.go index 69afc2d..6a83b5b 100644 --- a/example/client-server/proto/proto.pb.go +++ b/example/client-server/proto/proto.pb.go @@ -7,11 +7,10 @@ package proto import ( - reflect "reflect" - sync "sync" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) const ( @@ -26,9 +25,10 @@ type CommandRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Command string `protobuf:"bytes,1,opt,name=command,proto3" json:"command,omitempty"` - WorkingDir string `protobuf:"bytes,2,opt,name=working_dir,json=workingDir,proto3" json:"working_dir,omitempty"` - EnvVars map[string]string `protobuf:"bytes,3,rep,name=env_vars,json=envVars,proto3" json:"env_vars,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Token string `protobuf:"bytes,1,opt,name=token,proto3" json:"token,omitempty"` + Command string `protobuf:"bytes,2,opt,name=command,proto3" json:"command,omitempty"` + WorkingDir string `protobuf:"bytes,3,opt,name=working_dir,json=workingDir,proto3" json:"working_dir,omitempty"` + EnvVars map[string]string `protobuf:"bytes,4,rep,name=env_vars,json=envVars,proto3" json:"env_vars,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } func (x *CommandRequest) Reset() { @@ -63,6 +63,13 @@ func (*CommandRequest) Descriptor() ([]byte, []int) { return file_example_client_server_proto_proto_proto_rawDescGZIP(), []int{0} } +func (x *CommandRequest) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + func (x *CommandRequest) GetCommand() string { if x != nil { return x.Command @@ -153,31 +160,32 @@ var file_example_client_server_proto_proto_proto_rawDesc = []byte{ 0x0a, 0x27, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0xc6, 0x01, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x1f, 0x0a, - 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0a, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x44, 0x69, 0x72, 0x12, 0x3d, - 0x0a, 0x08, 0x65, 0x6e, 0x76, 0x5f, 0x76, 0x61, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x65, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x1a, 0x3a, 0x0a, - 0x0c, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, - 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x5c, 0x0a, 0x0f, 0x43, 0x6f, 0x6d, - 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, - 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75, - 0x74, 0x70, 0x75, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x63, 0x6f, 0x64, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x65, 0x78, 0x69, 0x74, 0x43, 0x6f, 0x64, - 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x32, 0x4b, 0x0a, 0x0c, 0x53, 0x68, 0x65, 0x6c, 0x6c, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, - 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, - 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x22, 0xdc, 0x01, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, + 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, + 0x61, 0x6e, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x64, + 0x69, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, + 0x67, 0x44, 0x69, 0x72, 0x12, 0x3d, 0x0a, 0x08, 0x65, 0x6e, 0x76, 0x5f, 0x76, 0x61, 0x72, 0x73, + 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, + 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x6e, + 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x65, 0x6e, 0x76, 0x56, + 0x61, 0x72, 0x73, 0x1a, 0x3a, 0x0a, 0x0c, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, + 0x5c, 0x0a, 0x0f, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x78, + 0x69, 0x74, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x65, + 0x78, 0x69, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x32, 0x4b, 0x0a, + 0x0c, 0x53, 0x68, 0x65, 0x6c, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a, + 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x15, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, + 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/example/client-server/proto/proto.proto b/example/client-server/proto/proto.proto index 7957055..910e7eb 100644 --- a/example/client-server/proto/proto.proto +++ b/example/client-server/proto/proto.proto @@ -8,9 +8,10 @@ service ShellService { } message CommandRequest { - string command = 1; - string working_dir = 2; - map env_vars = 3; + string token = 1; + string command = 2; + string working_dir = 3; + map env_vars = 4; } message CommandResponse { diff --git a/example/client-server/proto/proto_grpc.pb.go b/example/client-server/proto/proto_grpc.pb.go index 5b09cda..2ad55dc 100644 --- a/example/client-server/proto/proto_grpc.pb.go +++ b/example/client-server/proto/proto_grpc.pb.go @@ -8,7 +8,6 @@ package proto import ( context "context" - grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go index a3aab32..3d3ce21 100644 --- a/example/client-server/server/main.go +++ b/example/client-server/server/main.go @@ -2,6 +2,8 @@ package main import ( "context" + "flag" + "fmt" "io" "net" "os" @@ -9,9 +11,8 @@ import ( "google.golang.org/grpc" - "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" - pb "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/proto" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" log "github.com/sirupsen/logrus" ) @@ -20,13 +21,17 @@ const readBufferSize = 1024 // ShellServiceServer implements the ShellService defined in the proto file. type ShellServiceServer struct { pb.UnimplementedShellServiceServer + Token string } +// RunCommand validates the token and runs the command. func (s *ShellServiceServer) RunCommand(_ context.Context, req *pb.CommandRequest) (*pb.CommandResponse, error) { - log.Infof("Running command: %s in %s", req.Command, req.WorkingDir) - for key, value := range req.EnvVars { - log.Infof("Env: %s=%s", key, value) + if req.Token != s.Token { + log.Infof("Invalid token: %s, expected %s", req.Token, s.Token) + return nil, fmt.Errorf("invalid token") } + + log.Infof("Running command: %s in %s", req.Command, req.WorkingDir) // run command in bash cmd := exec.Command("bash", "-c", req.Command) @@ -111,14 +116,14 @@ func readOutput(r io.Reader, ch chan<- string) { } // Serve starts the gRPC server -func Serve() { +func Serve(token string) { listenAddress := util.GetEnv("LISTEN_ADDRESS", ":50051") listener, err := net.Listen("tcp", listenAddress) if err != nil { log.Fatalf("Failed to listen: %v", err) } grpcServer := grpc.NewServer() - pb.RegisterShellServiceServer(grpcServer, &ShellServiceServer{}) + pb.RegisterShellServiceServer(grpcServer, &ShellServiceServer{Token: token}) log.Println("Server is running on port " + listenAddress) if err := grpcServer.Serve(listener); err != nil { log.Fatalf("Failed to serve: %v", err) @@ -126,5 +131,12 @@ func Serve() { } func main() { - Serve() + token := flag.String("token", "", "Token for authenticating requests") + flag.Parse() + + if *token == "" { + log.Fatal("Token is required") + } + + Serve(*token) } From f821744c386dfcc71adab0fc6fde4aa6b8e57dfe Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 18:08:17 +0100 Subject: [PATCH 29/82] Added configurable endpoint --- example/client-server/client/main.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index 26e08f2..4be976d 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -30,8 +30,11 @@ type CommandOutput struct { ExitCode int32 } -func Run(command *Command) (*CommandOutput, error) { +func Run(endpoint string, command *Command) (*CommandOutput, error) { connectAddress := util.GetEnv("CONNECT_ADDRESS", "localhost:50051") + if endpoint != "" { + connectAddress = endpoint + } log.Printf("Connecting to %s", connectAddress) conn, err := grpc.NewClient(connectAddress, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { @@ -88,6 +91,11 @@ func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engin return err } + endpoint, err := engine.MetaString(req, "endpoint") + if err != nil { + return err + } + // build run command command := iacCommand + "" for _, value := range req.Args { @@ -95,7 +103,7 @@ func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engin } req.EnvVars["TF_IN_AUTOMATION"] = "true" - output, err := Run(&Command{ + output, err := Run(endpoint, &Command{ Command: command, WorkingDir: req.WorkingDir, EnvVars: req.EnvVars, From a79571b8456527a91968861ab94942108b34b5d2 Mon Sep 17 00:00:00 2001 From: Denis O Date: Fri, 16 Aug 2024 21:21:33 +0100 Subject: [PATCH 30/82] Add build file --- example/client-server/server/Dockerfile | 10 ++++++++++ example/client-server/server/main.go | 16 +++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 example/client-server/server/Dockerfile diff --git a/example/client-server/server/Dockerfile b/example/client-server/server/Dockerfile new file mode 100644 index 0000000..80175be --- /dev/null +++ b/example/client-server/server/Dockerfile @@ -0,0 +1,10 @@ +FROM gruntwork/terragrunt:0.2.0 + +ENV LISTEN_ADDRESS=0.0.0.0:50051 + +RUN mise use --global -y opentofu@1.7.0 +RUN ln -s /root/.local/share/mise/installs/opentofu/1.7.0/bin/tofu /bin/tofu +RUN mkdir /app +ADD terragrunt-engine-server /app/terragrunt-engine-server + +ENTRYPOINT ["/app/terragrunt-engine-server"] \ No newline at end of file diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go index 3d3ce21..3a97a40 100644 --- a/example/client-server/server/main.go +++ b/example/client-server/server/main.go @@ -131,12 +131,14 @@ func Serve(token string) { } func main() { - token := flag.String("token", "", "Token for authenticating requests") - flag.Parse() - - if *token == "" { - log.Fatal("Token is required") + token := util.GetEnv("TOKEN", "") + if token == "" { + clitoken := flag.String("token", "", "Token for authenticating requests") + flag.Parse() + if *clitoken == "" { + log.Fatal("Token is required") + } + token = *clitoken } - - Serve(*token) + Serve(token) } From dddf905543186f00df02c31cbcc7fa73355494b7 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 19:38:57 +0100 Subject: [PATCH 31/82] Make file update --- Makefile | 8 +++----- engine/meta.go | 3 ++- example/client-server/proto/proto.pb.go | 5 +++-- example/client-server/proto/proto_grpc.pb.go | 1 + example/client-server/server/Dockerfile | 10 ---------- 5 files changed, 9 insertions(+), 18 deletions(-) delete mode 100644 example/client-server/server/Dockerfile diff --git a/Makefile b/Makefile index 88e1ef9..fbf97ce 100644 --- a/Makefile +++ b/Makefile @@ -19,16 +19,14 @@ protoc-examples: $(shell find ./example/client-server -name '*.proto') protoc --go_out=. --go_opt=paths=source_relative example/client-server/proto/proto.proto protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative example/client-server/proto/proto.proto -examples: +examples: protoc-examples set -xe ;\ - vtag=$$(git describe --tags --abbrev=12 --dirty --broken) ;\ cd example/client-server ;\ cd client ;\ - go build -o terragrunt-engine-client -ldflags "-X github.com/gruntwork-io/go-commons/version.Version=$${vtag} -extldflags '-static'" . ;\ + go build -o terragrunt-engine-client -ldflags "-extldflags '-static'" . ;\ cd .. ;\ cd server ;\ - go build -o terragrunt-engine-server -ldflags "-X github.com/gruntwork-io/go-commons/version.Version=$${vtag} -extldflags '-static'" . - + go build -o terragrunt-engine-server -ldflags "-extldflags '-static'" . pre-commit: pre-commit run --all-files diff --git a/engine/meta.go b/engine/meta.go index c142c5f..63cbb6b 100644 --- a/engine/meta.go +++ b/engine/meta.go @@ -3,10 +3,11 @@ package engine import ( "encoding/json" "fmt" + "strconv" + "github.com/gruntwork-io/terragrunt-engine-go/proto" log "github.com/sirupsen/logrus" "google.golang.org/protobuf/types/known/structpb" - "strconv" ) // Meta extract request.Meta to go map[string]interface{} struct. diff --git a/example/client-server/proto/proto.pb.go b/example/client-server/proto/proto.pb.go index 6a83b5b..b3a2f3f 100644 --- a/example/client-server/proto/proto.pb.go +++ b/example/client-server/proto/proto.pb.go @@ -7,10 +7,11 @@ package proto import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const ( diff --git a/example/client-server/proto/proto_grpc.pb.go b/example/client-server/proto/proto_grpc.pb.go index 2ad55dc..5b09cda 100644 --- a/example/client-server/proto/proto_grpc.pb.go +++ b/example/client-server/proto/proto_grpc.pb.go @@ -8,6 +8,7 @@ package proto import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" diff --git a/example/client-server/server/Dockerfile b/example/client-server/server/Dockerfile deleted file mode 100644 index 80175be..0000000 --- a/example/client-server/server/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM gruntwork/terragrunt:0.2.0 - -ENV LISTEN_ADDRESS=0.0.0.0:50051 - -RUN mise use --global -y opentofu@1.7.0 -RUN ln -s /root/.local/share/mise/installs/opentofu/1.7.0/bin/tofu /bin/tofu -RUN mkdir /app -ADD terragrunt-engine-server /app/terragrunt-engine-server - -ENTRYPOINT ["/app/terragrunt-engine-server"] \ No newline at end of file From 527899047fbac694dc1ba87b5a985507e17271e8 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:15:42 +0100 Subject: [PATCH 32/82] sign executables --- .circleci/config.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2a22b7b..4d4a0b0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -120,9 +120,12 @@ jobs: - checkout - attach_workspace: at: . - - run: - <<: *install_gruntwork_utils + name: Install gruntwork utils + command: | + curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}" + gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" + gruntwork-install --module-name "sign-binary-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" - run: name: Compile and sign the binaries command: | From 9e2e38228310eeb8fd94ed009acb23d43770f37b Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:20:30 +0100 Subject: [PATCH 33/82] Circle ci cleanup --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4d4a0b0..19a315a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -124,7 +124,6 @@ jobs: name: Install gruntwork utils command: | curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}" - gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" gruntwork-install --module-name "sign-binary-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" - run: name: Compile and sign the binaries From 45607b9713614aae799265161cb16768951b90b5 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:24:09 +0100 Subject: [PATCH 34/82] binary sign --- .circleci/config.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 19a315a..e69debb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -120,10 +120,13 @@ jobs: - checkout - attach_workspace: at: . + - go/install: + version: "1.21.1" - run: - name: Install gruntwork utils + name: Install sign-binary-helpers command: | curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}" + gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" gruntwork-install --module-name "sign-binary-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" - run: name: Compile and sign the binaries From 27721228e2c20d5c3d97614461b9f30c05ff27f4 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:29:02 +0100 Subject: [PATCH 35/82] gon update --- .gon_amd64.hcl | 2 +- .gon_arm64.hcl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gon_amd64.hcl b/.gon_amd64.hcl index af1fa8e..eb961ba 100644 --- a/.gon_amd64.hcl +++ b/.gon_amd64.hcl @@ -1,7 +1,7 @@ # See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ # for further instructions on how to sign the binary + submitting for notarization. -source = ["./example/client-server/client/bin/terragrunt-iac-engine-client_darwin_amd64", "example/client-server/client/bin/terragrunt-iac-engine-server_darwin_amd64"] +source = ["./example/client-server/client/bin/terragrunt-iac-engine-client_darwin_amd64", "example/client-server/server/bin/terragrunt-iac-engine-server_darwin_amd64"] bundle_id = "io.gruntwork.app.terragrunt" diff --git a/.gon_arm64.hcl b/.gon_arm64.hcl index d165f02..b34e554 100644 --- a/.gon_arm64.hcl +++ b/.gon_arm64.hcl @@ -1,7 +1,7 @@ # See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ # for further instructions on how to sign the binary + submitting for notarization. -source = ["./example/client-server/client/bin/terragrunt-iac-engine-client_darwin_arm64", "example/client-server/client/bin/terragrunt-iac-engine-server_darwin_arm64"] +source = ["./example/client-server/client/bin/terragrunt-iac-engine-client_darwin_arm64", "example/client-server/server/bin/terragrunt-iac-engine-server_darwin_arm64"] bundle_id = "io.gruntwork.app.terragrunt" From 7931628f73b1de980a31c2496a6c252879e2af3d Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:38:58 +0100 Subject: [PATCH 36/82] bin extraction --- .circleci/config.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e69debb..a605344 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -138,13 +138,16 @@ jobs: sign-binary --os mac .gon_arm64.hcl echo "Done signing the binary" mkdir -p bin + # copy other binaries + cp -r example/client-server/client/bin/* bin/ + cp -r example/client-server/server/bin/* bin/ # Replace the files in bin. These are the same file names generated from .gon_amd64.hcl and .gon_arm64.hcl unzip terragrunt-iac-engine-client-server_amd64.zip - mv terragrunt-iac-engine-opentofu_darwin_amd64 bin/ - unzip terragrunt-iac-engine-client-server_arm64.zip - mv terragrunt-iac-engine-opentofu_darwin_arm64 bin/ + mv *_amd64 bin/ + mv *_arm64 bin/ + ls -lahrt ./bin - run: name: Install required packages command: | From f82161e8c544aa71081c5ffb0817568da21d8fae Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:50:18 +0100 Subject: [PATCH 37/82] bin update --- .circleci/config.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a605344..d32a4c4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -137,17 +137,21 @@ jobs: sign-binary --os mac --install-macos-sign-dependencies .gon_amd64.hcl sign-binary --os mac .gon_arm64.hcl echo "Done signing the binary" - mkdir -p bin + mkdir -p bin-server + mkdir -p bin-client # copy other binaries - cp -r example/client-server/client/bin/* bin/ - cp -r example/client-server/server/bin/* bin/ - + cp -r example/client-server/server/bin/* bin-server/ + cp -r example/client-server/client/bin/* bin-client/ + + # create separated directory for client and separated for server + # Replace the files in bin. These are the same file names generated from .gon_amd64.hcl and .gon_arm64.hcl unzip terragrunt-iac-engine-client-server_amd64.zip unzip terragrunt-iac-engine-client-server_arm64.zip - mv *_amd64 bin/ - mv *_arm64 bin/ - ls -lahrt ./bin + mv *-server_* bin-server/ + mv *-client_* bin-client/ + ls -lahrt ./bin-client + ls -lahrt ./bin-server - run: name: Install required packages command: | From d85da130552ea4752483c452783f878a43e98268 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:52:39 +0100 Subject: [PATCH 38/82] Add client exporting --- .circleci/config.yml | 2 + .circleci/create-release.sh | 171 ++++++++++++++++++++++++++++++++++++ .circleci/sign-files.sh | 67 ++++++++++++++ 3 files changed, 240 insertions(+) create mode 100755 .circleci/create-release.sh create mode 100755 .circleci/sign-files.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index d32a4c4..e26acc0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -166,6 +166,8 @@ jobs: - run: name: Package release files command: | + export BIN=$(pwd)/bin-client + export NAME="client" export TAG="${CIRCLE_TAG}" ./.circleci/sign-files.sh ./.circleci/create-release.sh diff --git a/.circleci/create-release.sh b/.circleci/create-release.sh new file mode 100755 index 0000000..6ebee68 --- /dev/null +++ b/.circleci/create-release.sh @@ -0,0 +1,171 @@ +#!/usr/bin/env bash +# Create Github release from release candidate tag +set -euo pipefail + +export GH_TOKEN=${GW_GITHUB_OAUTH_TOKEN} + +readonly REPO_OWNER="${REPO_OWNER:-gruntwork-io}" +readonly REPO_NAME="${REPO_NAME:-terragrunt-engine-opentofu}" +readonly MAX_RETRIES=${MAX_RETRIES:-10} +readonly RETRY_INTERVAL=${RETRY_INTERVAL:-20} + +readonly RC_VERSION=${TAG} +readonly VERSION=${TAG%-rc*} +readonly RELEASE="${RELEASE:-release}" +readonly COMMITS=$(git log $(git describe --tags --abbrev=0 @^)..@ --pretty=format:"- %s") + +function create_rc_release_notes() { + cat << EOF > rc_release_notes.txt +## Pre-Release $RC_VERSION + +### Changes +$COMMITS + +EOF +} + +function create_release_notes() { + cat << EOF > release_notes.txt +## Release $VERSION + +### Changes +$COMMITS + +EOF +} + +function get_release_response() { + local -r release_tag=$1 + + # First try using the gh CLI + local response + if response=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \ + "/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$release_tag" 2> /dev/null); then + echo "$response" + else + # Fallback to using curl if gh CLI fails + response=$(curl -s \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token $GH_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$release_tag") + echo "$response" + fi +} + +function check_release_exists() { + local -r release_response=$1 + + if jq -e '.message == "Not Found"' <<< "$release_response" > /dev/null; then + echo "Release $CIRCLE_TAG not found. Exiting..." + exit 1 + fi +} + +function get_release_id() { + local -r release_response=$1 + + echo "$release_response" | jq -r '.id' +} + +function get_asset_urls() { + local -r release_response=$1 + + echo "$release_response" | jq -r '.assets[].browser_download_url' +} + +function verify_and_reupload_assets() { + local -r release_version=$1 + local -r asset_dir=$2 + + # Get the list of assets for the release + local assets + assets=$(gh release view "$release_version" --json assets --jq '.assets[].name') + + if [ -z "$assets" ]; then + echo "No assets found for release $release_version" + return + fi + + for asset in $assets; do + for ((i=0; i /dev/null 2>&1; then + echo "Failed to download the asset $asset. Uploading..." + + # Re-upload the asset + if ! gh release upload --clobber "$release_version" "${asset_dir}/${asset}"; then + echo "Failed to upload $asset" + sleep $RETRY_INTERVAL + else + echo "Successfully uploaded $asset" + break + fi + else + echo "Successfully checked the asset $asset" + rm -f "/tmp/$asset" + break + fi + done + + if (( i == MAX_RETRIES )); then + echo "Failed to process the asset $asset after $MAX_RETRIES retries. Exiting..." + exit 1 + fi + done +} + +function check_github_release() { + local retries=0 + local release_tag=$1 + + while [ $retries -lt $MAX_RETRIES ]; do + if gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \ + "/repos/$REPO_OWNER/$REPO_NAME/releases" | jq -e --arg tag "$release_tag" '.[] | select(.tag_name == $tag)' > /dev/null; then + echo "Release $release_tag found." + return 0 + else + echo "Release $release_tag not found. Retrying in $RETRY_INTERVAL seconds..." + ((retries++)) + sleep $RETRY_INTERVAL + fi + done + + echo "Failed to find release $release_tag after $MAX_RETRIES retries. Exiting..." + exit 1 +} + +function download_release_assets() { + local -r release_tag=$1 + local -r download_dir=$2 + + mkdir -p "$download_dir" + + assets=$(gh release view "$release_tag" --json assets --jq '.assets[].name') + for asset in $assets; do + gh release download "$release_tag" --pattern "$asset" -D "$download_dir" + done +} + +function main() { + create_rc_release_notes + # check if rc release exists, create if missing + if ! gh release view "${RC_VERSION}" > /dev/null 2>&1; then + gh release create "${RC_VERSION}" --prerelease -F rc_release_notes.txt -t "${RC_VERSION}" release/* + fi + check_github_release "${RC_VERSION}" + verify_and_reupload_assets "${RC_VERSION}" "release" + + # download rc assets + download_release_assets "$RC_VERSION" "release-bin" + + # create full release + create_release_notes + # check if release exists, create if missing + if ! gh release view "${VERSION}" > /dev/null 2>&1; then + gh release create "${VERSION}" -F release_notes.txt -t "${VERSION}" release-bin/* + fi + check_github_release "${VERSION}" + verify_and_reupload_assets "${VERSION}" "release-bin" +} + +main "$@" diff --git a/.circleci/sign-files.sh b/.circleci/sign-files.sh new file mode 100755 index 0000000..265ab86 --- /dev/null +++ b/.circleci/sign-files.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# This script is used to sign the release files with the GPG key +set -euo pipefail + +readonly BIN="${BIN:-bin}" +readonly RELEASE="${RELEASE:-release}" +readonly NAME="${NAME:-opentofu}" +# Extract version from RC +readonly VERSION=${TAG%-rc*} +readonly TYPE="rpc" + +function get_key_id() { + gpg --list-keys --with-colons | awk -F: '/^pub/{print $5}' +} + +function prepare_release_directory() { + mkdir -p "${RELEASE}" +} + +function process_files() { + cd "${BIN}" + for file in *; do + # Extract the OS and ARCH from the file name + if [[ $file =~ terragrunt-iac-engine-${NAME}_([^_]+)_([^_]+) ]]; then + OS="${BASH_REMATCH[1]}" + ARCH="${BASH_REMATCH[2]}" + + # Set the binary and archive names + BINARY_NAME="terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_${OS}_${ARCH}" + mv "${file}" "${BINARY_NAME}" + ARCHIVE_NAME="terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_${OS}_${ARCH}.zip" + + # Create the zip archive + zip "${ARCHIVE_NAME}" "${BINARY_NAME}" + fi + done + cd .. +} + +# Function to create the SHA256SUMS file +function create_shasums_file() { + pwd=$(pwd) + cd "${BIN}" + # Create the SHA256SUMS file for all files in the release directory + shasum -a 256 * > "terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_SHA256SUMS" + cp *.zip ../"${RELEASE}" + cp "terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_SHA256SUMS" ../"${RELEASE}" + cd "../${RELEASE}" +} + +# Function to sign the SHA256SUMS file +function sign_shasums_file() { + local -r key_id=$1 + echo "${GW_ENGINE_GPG_KEY_PW}" | gpg --batch --yes --pinentry-mode loopback --passphrase-fd 0 --default-key "${key_id}" --detach-sign "terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_SHA256SUMS" +} + +# Main function to orchestrate the actions +main() { + local key_id + key_id=$(get_key_id) + prepare_release_directory + process_files + create_shasums_file + sign_shasums_file "$key_id" +} + +main "$@" From 131b4dbbe0f2490d44398969fd0336b637385ba5 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:55:14 +0100 Subject: [PATCH 39/82] Add docker file for server --- example/client-server/Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 example/client-server/Dockerfile diff --git a/example/client-server/Dockerfile b/example/client-server/Dockerfile new file mode 100644 index 0000000..2451101 --- /dev/null +++ b/example/client-server/Dockerfile @@ -0,0 +1,10 @@ +FROM gruntwork/terragrunt:0.2.0 + +ENV LISTEN_ADDRESS=0.0.0.0:50051 + +RUN mise use --global -y opentofu@1.7.0 +RUN ln -s /root/.local/share/mise/installs/opentofu/1.7.0/bin/tofu /bin/tofu +RUN mkdir /app +ADD server/terragrunt-engine-server /app/terragrunt-engine-server + +ENTRYPOINT ["/app/terragrunt-engine-server"] \ No newline at end of file From cab233495b40dfd54bca1aa70e80e4decb32fcd6 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:56:57 +0100 Subject: [PATCH 40/82] Readme update --- README.md | 3 ++- example/client-server/Dockerfile | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6661cd5..2afb21b 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,10 @@ Make commands: ## Engines -Impelmentations of the Terragrunt Engine include: +Implementations of the Terragrunt Engine include: - [terragrunt-engine-opentofu](https://github.com/gruntwork-io/terragrunt-engine-opentofu) +- [terragrunt-engine-client-server](./engine/client-server) ## Example Engine Implementation diff --git a/example/client-server/Dockerfile b/example/client-server/Dockerfile index 2451101..3c2e0f6 100644 --- a/example/client-server/Dockerfile +++ b/example/client-server/Dockerfile @@ -2,6 +2,8 @@ FROM gruntwork/terragrunt:0.2.0 ENV LISTEN_ADDRESS=0.0.0.0:50051 +RUN apt-get update && apt-get install -y wget + RUN mise use --global -y opentofu@1.7.0 RUN ln -s /root/.local/share/mise/installs/opentofu/1.7.0/bin/tofu /bin/tofu RUN mkdir /app From b701a102adf981f38ea70ca97ca065a2b724139d Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 20:59:18 +0100 Subject: [PATCH 41/82] config update --- .circleci/config.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e26acc0..d1fcd8e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -214,11 +214,11 @@ workflows: - release: requires: - build - # filters: -# tags: -# only: /^.*-rc.*$/ -# branches: -# ignore: /.*/ + filters: + tags: + only: /^.*-rc.*$/ + branches: + ignore: /.*/ context: - AWS__PHXDEVOPS__circle-ci-test - GCP__automated-tests From 11b00fb9cd5ee2edc864e2e00b7caff40be4a9fa Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 21:08:28 +0100 Subject: [PATCH 42/82] Add release script --- .circleci/config.yml | 3 +++ .circleci/create-release.sh | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d1fcd8e..6a8f87a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -169,7 +169,10 @@ jobs: export BIN=$(pwd)/bin-client export NAME="client" export TAG="${CIRCLE_TAG}" + export REPO_NAME="terragrunt-engine-go" ./.circleci/sign-files.sh + # copy server files to release + cp bin-server/* release/ ./.circleci/create-release.sh - persist_to_workspace: root: . diff --git a/.circleci/create-release.sh b/.circleci/create-release.sh index 6ebee68..a183ffc 100755 --- a/.circleci/create-release.sh +++ b/.circleci/create-release.sh @@ -5,7 +5,7 @@ set -euo pipefail export GH_TOKEN=${GW_GITHUB_OAUTH_TOKEN} readonly REPO_OWNER="${REPO_OWNER:-gruntwork-io}" -readonly REPO_NAME="${REPO_NAME:-terragrunt-engine-opentofu}" +readonly REPO_NAME="${REPO_NAME:-terragrunt-engine-go}" readonly MAX_RETRIES=${MAX_RETRIES:-10} readonly RETRY_INTERVAL=${RETRY_INTERVAL:-20} From b790413542206e674d606befde3a68aede4e837f Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 21:09:58 +0100 Subject: [PATCH 43/82] add rc release --- .circleci/create-release.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.circleci/create-release.sh b/.circleci/create-release.sh index a183ffc..fd946db 100755 --- a/.circleci/create-release.sh +++ b/.circleci/create-release.sh @@ -155,17 +155,17 @@ function main() { check_github_release "${RC_VERSION}" verify_and_reupload_assets "${RC_VERSION}" "release" - # download rc assets - download_release_assets "$RC_VERSION" "release-bin" - - # create full release - create_release_notes - # check if release exists, create if missing - if ! gh release view "${VERSION}" > /dev/null 2>&1; then - gh release create "${VERSION}" -F release_notes.txt -t "${VERSION}" release-bin/* - fi - check_github_release "${VERSION}" - verify_and_reupload_assets "${VERSION}" "release-bin" +# # download rc assets +# download_release_assets "$RC_VERSION" "release-bin" +# +# # create full release +# create_release_notes +# # check if release exists, create if missing +# if ! gh release view "${VERSION}" > /dev/null 2>&1; then +# gh release create "${VERSION}" -F release_notes.txt -t "${VERSION}" release-bin/* +# fi +# check_github_release "${VERSION}" +# verify_and_reupload_assets "${VERSION}" "release-bin" } main "$@" From 7a4a1d4cdd5bed4f9e1880b73587275ba370af66 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 21:15:09 +0100 Subject: [PATCH 44/82] Tags update --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6a8f87a..5f91420 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -206,6 +206,9 @@ workflows: tags: only: /^v.*/ - build: + filters: + tags: + only: /^v.*/ requires: - precommit context: From bdcd84156cd1286cfa50ff3b2e26fd3d95782164 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 21:35:16 +0100 Subject: [PATCH 45/82] added docker compose --- example/client-server/Dockerfile | 6 ++++-- example/client-server/docker-compose.yaml | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 example/client-server/docker-compose.yaml diff --git a/example/client-server/Dockerfile b/example/client-server/Dockerfile index 3c2e0f6..6c0dd29 100644 --- a/example/client-server/Dockerfile +++ b/example/client-server/Dockerfile @@ -1,5 +1,7 @@ FROM gruntwork/terragrunt:0.2.0 +ARG VERSION=v0.0.3-rc2024081902 +ARG PLATFORM=linux_amd64 ENV LISTEN_ADDRESS=0.0.0.0:50051 RUN apt-get update && apt-get install -y wget @@ -7,6 +9,6 @@ RUN apt-get update && apt-get install -y wget RUN mise use --global -y opentofu@1.7.0 RUN ln -s /root/.local/share/mise/installs/opentofu/1.7.0/bin/tofu /bin/tofu RUN mkdir /app -ADD server/terragrunt-engine-server /app/terragrunt-engine-server - +RUN wget https://github.com/gruntwork-io/terragrunt-engine-go/releases/download/${VERSION}/terragrunt-iac-engine-server_${PLATFORM} -O /app/terragrunt-engine-server +RUN chmod +x /app/terragrunt-engine-server ENTRYPOINT ["/app/terragrunt-engine-server"] \ No newline at end of file diff --git a/example/client-server/docker-compose.yaml b/example/client-server/docker-compose.yaml new file mode 100644 index 0000000..8b84c12 --- /dev/null +++ b/example/client-server/docker-compose.yaml @@ -0,0 +1,14 @@ + +version: '3' +services: + terragrunt-engine-server: + build: + context: . + dockerfile: Dockerfile + environment: + TOKEN: secret-token + volumes: + # Update path to allow tofu access from container to working directory + - $PWD:$PWD + ports: + - "0.0.0.0:50051:50051" From 45463f882eb819a2956eedb5167fc6ae3bec5b7b Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 22:04:51 +0100 Subject: [PATCH 46/82] client server update --- example/client-server/Makefile | 23 ++++ example/client-server/README.md | 35 +++++- example/client-server/client/main.go | 2 - example/client-server/docker-compose.yaml | 4 +- example/client-server/go.mod | 26 ++++ example/client-server/proto/proto.pb.go | 124 +++++++++---------- example/client-server/proto/proto_grpc.pb.go | 5 +- example/client-server/server/main.go | 1 - 8 files changed, 146 insertions(+), 74 deletions(-) create mode 100644 example/client-server/Makefile create mode 100644 example/client-server/go.mod diff --git a/example/client-server/Makefile b/example/client-server/Makefile new file mode 100644 index 0000000..b8f69ee --- /dev/null +++ b/example/client-server/Makefile @@ -0,0 +1,23 @@ +default: build + +tools: + go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2 + go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.4.0 + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2 + +protoc: $(shell find ./example/client-server -name '*.proto') + protoc --go_out=. --go_opt=paths=source_relative proto/proto.proto + protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/proto.proto + +build: protoc + set -xe ;\ + cd client ;\ + go build -o terragrunt-engine-client -ldflags "-extldflags '-static'" . ;\ + cd .. ;\ + cd server ;\ + go build -o terragrunt-engine-server -ldflags "-extldflags '-static'" . + +pre-commit: + pre-commit run --all-files + +.PHONY: default lint protoc test tools diff --git a/example/client-server/README.md b/example/client-server/README.md index c6c1e85..f709a4d 100644 --- a/example/client-server/README.md +++ b/example/client-server/README.md @@ -1,6 +1,35 @@ -# Engine Client - Server implementation +# Example Engine Client - Server implementation +To build locally the client and server, you can use the following commands in the repository root: +```bash +make examples +``` + +## Example HCL Configuration + +Here is an example of how you can configure the IaC engine client in your Terragrunt configuration: + +* update `docker-compose.yml` with path to the project where IaC tool should be invoked +* run `docker-compose up` to start the server +* prepare the client configuration in `terragrunt.hcl` file +```hcl +# terragrunt.hcl +engine { + source = "https://github.com/gruntwork-io/terragrunt-engine-go/releases/download/v0.0.3-rc2024081902/terragrunt-iac-engine-client_rpc_v0.0.3_linux_amd64.zip" + meta = { + # server endpoint + endpoint = "127.0.0.1:50051" + # authentication token + token = get_env("TG_SERVER_TOKEN") + } +} +``` + +Terragrunt execution: +```bash +export TG_EXPERIMENTAL_ENGINE=1 +export TG_SERVER_TOKEN=secret-token + +terragrunt apply --auto-approve ``` -terragrunt-engine-server --token secret-token -``` \ No newline at end of file diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index 4be976d..c78a725 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -6,8 +6,6 @@ import ( "google.golang.org/grpc/credentials/insecure" - "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" - "github.com/gruntwork-io/terragrunt-engine-go/engine" "github.com/hashicorp/go-plugin" log "github.com/sirupsen/logrus" diff --git a/example/client-server/docker-compose.yaml b/example/client-server/docker-compose.yaml index 8b84c12..c8c1e1f 100644 --- a/example/client-server/docker-compose.yaml +++ b/example/client-server/docker-compose.yaml @@ -9,6 +9,6 @@ services: TOKEN: secret-token volumes: # Update path to allow tofu access from container to working directory - - $PWD:$PWD + - /projects:/projects ports: - - "0.0.0.0:50051:50051" + - "127.0.0.1:50051:50051" diff --git a/example/client-server/go.mod b/example/client-server/go.mod new file mode 100644 index 0000000..b7a9bdb --- /dev/null +++ b/example/client-server/go.mod @@ -0,0 +1,26 @@ +module github.com/gruntwork-io/terragrunt-engine-go/example/client-server + +go 1.21 + +require ( + github.com/gruntwork-io/terragrunt-engine-go v0.0.3-rc2024081903 + github.com/hashicorp/go-plugin v1.6.1 + github.com/sirupsen/logrus v1.9.3 + google.golang.org/grpc v1.65.0 + google.golang.org/protobuf v1.34.2 +) + +require ( + github.com/fatih/color v1.7.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/hashicorp/go-hclog v0.14.1 // indirect + github.com/hashicorp/yamux v0.1.1 // indirect + github.com/mattn/go-colorable v0.1.4 // indirect + github.com/mattn/go-isatty v0.0.10 // indirect + github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 // indirect + github.com/oklog/run v1.0.0 // indirect + golang.org/x/net v0.27.0 // indirect + golang.org/x/sys v0.22.0 // indirect + golang.org/x/text v0.16.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect +) diff --git a/example/client-server/proto/proto.pb.go b/example/client-server/proto/proto.pb.go index b3a2f3f..99d1109 100644 --- a/example/client-server/proto/proto.pb.go +++ b/example/client-server/proto/proto.pb.go @@ -2,16 +2,15 @@ // versions: // protoc-gen-go v1.34.2 // protoc v3.12.4 -// source: example/client-server/proto/proto.proto +// source: proto/proto.proto package proto import ( - reflect "reflect" - sync "sync" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) const ( @@ -35,7 +34,7 @@ type CommandRequest struct { func (x *CommandRequest) Reset() { *x = CommandRequest{} if protoimpl.UnsafeEnabled { - mi := &file_example_client_server_proto_proto_proto_msgTypes[0] + mi := &file_proto_proto_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -48,7 +47,7 @@ func (x *CommandRequest) String() string { func (*CommandRequest) ProtoMessage() {} func (x *CommandRequest) ProtoReflect() protoreflect.Message { - mi := &file_example_client_server_proto_proto_proto_msgTypes[0] + mi := &file_proto_proto_proto_msgTypes[0] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -61,7 +60,7 @@ func (x *CommandRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandRequest.ProtoReflect.Descriptor instead. func (*CommandRequest) Descriptor() ([]byte, []int) { - return file_example_client_server_proto_proto_proto_rawDescGZIP(), []int{0} + return file_proto_proto_proto_rawDescGZIP(), []int{0} } func (x *CommandRequest) GetToken() string { @@ -105,7 +104,7 @@ type CommandResponse struct { func (x *CommandResponse) Reset() { *x = CommandResponse{} if protoimpl.UnsafeEnabled { - mi := &file_example_client_server_proto_proto_proto_msgTypes[1] + mi := &file_proto_proto_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -118,7 +117,7 @@ func (x *CommandResponse) String() string { func (*CommandResponse) ProtoMessage() {} func (x *CommandResponse) ProtoReflect() protoreflect.Message { - mi := &file_example_client_server_proto_proto_proto_msgTypes[1] + mi := &file_proto_proto_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -131,7 +130,7 @@ func (x *CommandResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use CommandResponse.ProtoReflect.Descriptor instead. func (*CommandResponse) Descriptor() ([]byte, []int) { - return file_example_client_server_proto_proto_proto_rawDescGZIP(), []int{1} + return file_proto_proto_proto_rawDescGZIP(), []int{1} } func (x *CommandResponse) GetOutput() string { @@ -155,59 +154,58 @@ func (x *CommandResponse) GetError() string { return "" } -var File_example_client_server_proto_proto_proto protoreflect.FileDescriptor +var File_proto_proto_proto protoreflect.FileDescriptor -var file_example_client_server_proto_proto_proto_rawDesc = []byte{ - 0x0a, 0x27, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, - 0x2d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x22, 0xdc, 0x01, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, - 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, - 0x61, 0x6e, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x64, - 0x69, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, - 0x67, 0x44, 0x69, 0x72, 0x12, 0x3d, 0x0a, 0x08, 0x65, 0x6e, 0x76, 0x5f, 0x76, 0x61, 0x72, 0x73, - 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, - 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x6e, - 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x65, 0x6e, 0x76, 0x56, - 0x61, 0x72, 0x73, 0x1a, 0x3a, 0x0a, 0x0c, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, 0x6e, - 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, - 0x5c, 0x0a, 0x0f, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x78, - 0x69, 0x74, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x65, - 0x78, 0x69, 0x74, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x32, 0x4b, 0x0a, - 0x0c, 0x53, 0x68, 0x65, 0x6c, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a, - 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x15, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, - 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +var file_proto_proto_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdc, 0x01, 0x0a, 0x0e, 0x43, + 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, + 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, + 0x6b, 0x65, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x1f, 0x0a, + 0x0b, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x77, 0x6f, 0x72, 0x6b, 0x69, 0x6e, 0x67, 0x44, 0x69, 0x72, 0x12, 0x3d, + 0x0a, 0x08, 0x65, 0x6e, 0x76, 0x5f, 0x76, 0x61, 0x72, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x65, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x1a, 0x3a, 0x0a, + 0x0c, 0x45, 0x6e, 0x76, 0x56, 0x61, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x5c, 0x0a, 0x0f, 0x43, 0x6f, 0x6d, + 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x78, 0x69, 0x74, 0x5f, 0x63, 0x6f, 0x64, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x65, 0x78, 0x69, 0x74, 0x43, 0x6f, 0x64, + 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x32, 0x4b, 0x0a, 0x0c, 0x53, 0x68, 0x65, 0x6c, 0x6c, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3b, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x43, 0x6f, + 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, + 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_example_client_server_proto_proto_proto_rawDescOnce sync.Once - file_example_client_server_proto_proto_proto_rawDescData = file_example_client_server_proto_proto_proto_rawDesc + file_proto_proto_proto_rawDescOnce sync.Once + file_proto_proto_proto_rawDescData = file_proto_proto_proto_rawDesc ) -func file_example_client_server_proto_proto_proto_rawDescGZIP() []byte { - file_example_client_server_proto_proto_proto_rawDescOnce.Do(func() { - file_example_client_server_proto_proto_proto_rawDescData = protoimpl.X.CompressGZIP(file_example_client_server_proto_proto_proto_rawDescData) +func file_proto_proto_proto_rawDescGZIP() []byte { + file_proto_proto_proto_rawDescOnce.Do(func() { + file_proto_proto_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_proto_proto_rawDescData) }) - return file_example_client_server_proto_proto_proto_rawDescData + return file_proto_proto_proto_rawDescData } -var file_example_client_server_proto_proto_proto_msgTypes = make([]protoimpl.MessageInfo, 3) -var file_example_client_server_proto_proto_proto_goTypes = []any{ +var file_proto_proto_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_proto_proto_proto_goTypes = []any{ (*CommandRequest)(nil), // 0: proto.CommandRequest (*CommandResponse)(nil), // 1: proto.CommandResponse nil, // 2: proto.CommandRequest.EnvVarsEntry } -var file_example_client_server_proto_proto_proto_depIdxs = []int32{ +var file_proto_proto_proto_depIdxs = []int32{ 2, // 0: proto.CommandRequest.env_vars:type_name -> proto.CommandRequest.EnvVarsEntry 0, // 1: proto.ShellService.RunCommand:input_type -> proto.CommandRequest 1, // 2: proto.ShellService.RunCommand:output_type -> proto.CommandResponse @@ -218,13 +216,13 @@ var file_example_client_server_proto_proto_proto_depIdxs = []int32{ 0, // [0:1] is the sub-list for field type_name } -func init() { file_example_client_server_proto_proto_proto_init() } -func file_example_client_server_proto_proto_proto_init() { - if File_example_client_server_proto_proto_proto != nil { +func init() { file_proto_proto_proto_init() } +func file_proto_proto_proto_init() { + if File_proto_proto_proto != nil { return } if !protoimpl.UnsafeEnabled { - file_example_client_server_proto_proto_proto_msgTypes[0].Exporter = func(v any, i int) any { + file_proto_proto_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*CommandRequest); i { case 0: return &v.state @@ -236,7 +234,7 @@ func file_example_client_server_proto_proto_proto_init() { return nil } } - file_example_client_server_proto_proto_proto_msgTypes[1].Exporter = func(v any, i int) any { + file_proto_proto_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*CommandResponse); i { case 0: return &v.state @@ -253,18 +251,18 @@ func file_example_client_server_proto_proto_proto_init() { out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_example_client_server_proto_proto_proto_rawDesc, + RawDescriptor: file_proto_proto_proto_rawDesc, NumEnums: 0, NumMessages: 3, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_example_client_server_proto_proto_proto_goTypes, - DependencyIndexes: file_example_client_server_proto_proto_proto_depIdxs, - MessageInfos: file_example_client_server_proto_proto_proto_msgTypes, + GoTypes: file_proto_proto_proto_goTypes, + DependencyIndexes: file_proto_proto_proto_depIdxs, + MessageInfos: file_proto_proto_proto_msgTypes, }.Build() - File_example_client_server_proto_proto_proto = out.File - file_example_client_server_proto_proto_proto_rawDesc = nil - file_example_client_server_proto_proto_proto_goTypes = nil - file_example_client_server_proto_proto_proto_depIdxs = nil + File_proto_proto_proto = out.File + file_proto_proto_proto_rawDesc = nil + file_proto_proto_proto_goTypes = nil + file_proto_proto_proto_depIdxs = nil } diff --git a/example/client-server/proto/proto_grpc.pb.go b/example/client-server/proto/proto_grpc.pb.go index 5b09cda..c2dc9cf 100644 --- a/example/client-server/proto/proto_grpc.pb.go +++ b/example/client-server/proto/proto_grpc.pb.go @@ -2,13 +2,12 @@ // versions: // - protoc-gen-go-grpc v1.4.0 // - protoc v3.12.4 -// source: example/client-server/proto/proto.proto +// source: proto/proto.proto package proto import ( context "context" - grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -107,5 +106,5 @@ var ShellService_ServiceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "example/client-server/proto/proto.proto", + Metadata: "proto/proto.proto", } diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go index 3a97a40..c918435 100644 --- a/example/client-server/server/main.go +++ b/example/client-server/server/main.go @@ -12,7 +12,6 @@ import ( "google.golang.org/grpc" pb "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/proto" - "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" log "github.com/sirupsen/logrus" ) From 45219ebe6603c1a68d25ad7a3c30bd72e59e46c2 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 22:06:36 +0100 Subject: [PATCH 47/82] main go update --- example/client-server/client/main.go | 1 + example/client-server/go.mod | 2 +- example/client-server/server/main.go | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index c78a725..17dd3b3 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" "time" "google.golang.org/grpc/credentials/insecure" diff --git a/example/client-server/go.mod b/example/client-server/go.mod index b7a9bdb..d688dc3 100644 --- a/example/client-server/go.mod +++ b/example/client-server/go.mod @@ -3,7 +3,7 @@ module github.com/gruntwork-io/terragrunt-engine-go/example/client-server go 1.21 require ( - github.com/gruntwork-io/terragrunt-engine-go v0.0.3-rc2024081903 + github.com/gruntwork-io/terragrunt-engine-go v0.0.3-rc2024081904 github.com/hashicorp/go-plugin v1.6.1 github.com/sirupsen/logrus v1.9.3 google.golang.org/grpc v1.65.0 diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go index c918435..ad6cde4 100644 --- a/example/client-server/server/main.go +++ b/example/client-server/server/main.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" "io" "net" "os" From 27973eb246738ae73a0a0899c8d2cddd975f3391 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 22:06:49 +0100 Subject: [PATCH 48/82] Go sum update --- example/client-server/go.sum | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 example/client-server/go.sum diff --git a/example/client-server/go.sum b/example/client-server/go.sum new file mode 100644 index 0000000..ea49e5f --- /dev/null +++ b/example/client-server/go.sum @@ -0,0 +1,56 @@ +github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= +github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/gruntwork-io/terragrunt-engine-go v0.0.3-rc2024081904 h1:6SJ3nj5B7XX/MRnLRBbot2P6b84zYgDOqWYFwhUfUac= +github.com/gruntwork-io/terragrunt-engine-go v0.0.3-rc2024081904/go.mod h1:NnZknGXCWIaKtncFg6YuE+NrdSe1yia4JdwNa/mAN1I= +github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU= +github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI= +github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0= +github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= +github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= +github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= +github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= +github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77 h1:7GoSOOW2jpsfkntVKaS2rAr1TJqfcxotyaUcuxoZSzg= +github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= +github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= +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/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d h1:JU0iKnSg02Gmb5ZdV8nYsKEKsP6o/FGVWTrw4i1DA9A= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= +google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 73b9491f75d0bae2ae88cb604dc28c48fe90bb95 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 22:07:04 +0100 Subject: [PATCH 49/82] Go imports --- example/client-server/client/main.go | 3 ++- example/client-server/proto/proto.pb.go | 5 +++-- example/client-server/proto/proto_grpc.pb.go | 1 + example/client-server/server/main.go | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/example/client-server/client/main.go b/example/client-server/client/main.go index 17dd3b3..492e12c 100644 --- a/example/client-server/client/main.go +++ b/example/client-server/client/main.go @@ -2,9 +2,10 @@ package main import ( "context" - "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" "time" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" + "google.golang.org/grpc/credentials/insecure" "github.com/gruntwork-io/terragrunt-engine-go/engine" diff --git a/example/client-server/proto/proto.pb.go b/example/client-server/proto/proto.pb.go index 99d1109..55bddf8 100644 --- a/example/client-server/proto/proto.pb.go +++ b/example/client-server/proto/proto.pb.go @@ -7,10 +7,11 @@ package proto import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const ( diff --git a/example/client-server/proto/proto_grpc.pb.go b/example/client-server/proto/proto_grpc.pb.go index c2dc9cf..8e2db3d 100644 --- a/example/client-server/proto/proto_grpc.pb.go +++ b/example/client-server/proto/proto_grpc.pb.go @@ -8,6 +8,7 @@ package proto import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" diff --git a/example/client-server/server/main.go b/example/client-server/server/main.go index ad6cde4..316cc9c 100644 --- a/example/client-server/server/main.go +++ b/example/client-server/server/main.go @@ -4,12 +4,13 @@ import ( "context" "flag" "fmt" - "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" "io" "net" "os" "os/exec" + "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" + "google.golang.org/grpc" pb "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/proto" From 46e7be320e93ee3024890dc5e697990feb15802c Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 22:07:56 +0100 Subject: [PATCH 50/82] Client --- Makefile | 13 ------------- example/client-server/Makefile | 2 +- example/client-server/proto/proto.pb.go | 5 ++--- example/client-server/proto/proto_grpc.pb.go | 1 - 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index fbf97ce..d675a20 100644 --- a/Makefile +++ b/Makefile @@ -15,19 +15,6 @@ protoc: $(shell find ./proto -name '*.proto') protoc --go_out=. --go_opt=paths=source_relative proto/engine.proto protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/engine.proto -protoc-examples: $(shell find ./example/client-server -name '*.proto') - protoc --go_out=. --go_opt=paths=source_relative example/client-server/proto/proto.proto - protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative example/client-server/proto/proto.proto - -examples: protoc-examples - set -xe ;\ - cd example/client-server ;\ - cd client ;\ - go build -o terragrunt-engine-client -ldflags "-extldflags '-static'" . ;\ - cd .. ;\ - cd server ;\ - go build -o terragrunt-engine-server -ldflags "-extldflags '-static'" . - pre-commit: pre-commit run --all-files diff --git a/example/client-server/Makefile b/example/client-server/Makefile index b8f69ee..5f62ac3 100644 --- a/example/client-server/Makefile +++ b/example/client-server/Makefile @@ -9,7 +9,7 @@ protoc: $(shell find ./example/client-server -name '*.proto') protoc --go_out=. --go_opt=paths=source_relative proto/proto.proto protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/proto.proto -build: protoc +build: set -xe ;\ cd client ;\ go build -o terragrunt-engine-client -ldflags "-extldflags '-static'" . ;\ diff --git a/example/client-server/proto/proto.pb.go b/example/client-server/proto/proto.pb.go index 55bddf8..99d1109 100644 --- a/example/client-server/proto/proto.pb.go +++ b/example/client-server/proto/proto.pb.go @@ -7,11 +7,10 @@ package proto import ( - reflect "reflect" - sync "sync" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) const ( diff --git a/example/client-server/proto/proto_grpc.pb.go b/example/client-server/proto/proto_grpc.pb.go index 8e2db3d..c2dc9cf 100644 --- a/example/client-server/proto/proto_grpc.pb.go +++ b/example/client-server/proto/proto_grpc.pb.go @@ -8,7 +8,6 @@ package proto import ( context "context" - grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" From 433a88fa0c643a339d82f703baf9d3f9cabc5641 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 22:08:14 +0100 Subject: [PATCH 51/82] protoc files update --- example/client-server/proto/proto.pb.go | 5 +++-- example/client-server/proto/proto_grpc.pb.go | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/example/client-server/proto/proto.pb.go b/example/client-server/proto/proto.pb.go index 99d1109..55bddf8 100644 --- a/example/client-server/proto/proto.pb.go +++ b/example/client-server/proto/proto.pb.go @@ -7,10 +7,11 @@ package proto import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const ( diff --git a/example/client-server/proto/proto_grpc.pb.go b/example/client-server/proto/proto_grpc.pb.go index c2dc9cf..8e2db3d 100644 --- a/example/client-server/proto/proto_grpc.pb.go +++ b/example/client-server/proto/proto_grpc.pb.go @@ -8,6 +8,7 @@ package proto import ( context "context" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" From e0e1d64388250ab7f491cfff91791814d1b33392 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 22:11:05 +0100 Subject: [PATCH 52/82] Readme and makefile update --- example/client-server/Makefile | 6 +++--- example/client-server/README.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/example/client-server/Makefile b/example/client-server/Makefile index 5f62ac3..1c3d30c 100644 --- a/example/client-server/Makefile +++ b/example/client-server/Makefile @@ -9,13 +9,13 @@ protoc: $(shell find ./example/client-server -name '*.proto') protoc --go_out=. --go_opt=paths=source_relative proto/proto.proto protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/proto.proto -build: +build: set -xe ;\ cd client ;\ - go build -o terragrunt-engine-client -ldflags "-extldflags '-static'" . ;\ + go build -o ../terragrunt-engine-client -ldflags "-extldflags '-static'" . ;\ cd .. ;\ cd server ;\ - go build -o terragrunt-engine-server -ldflags "-extldflags '-static'" . + go build -o ../terragrunt-engine-server -ldflags "-extldflags '-static'" . pre-commit: pre-commit run --all-files diff --git a/example/client-server/README.md b/example/client-server/README.md index f709a4d..8d54286 100644 --- a/example/client-server/README.md +++ b/example/client-server/README.md @@ -1,10 +1,10 @@ # Example Engine Client - Server implementation -To build locally the client and server, you can use the following commands in the repository root: +To build locally the client and server, run make command: ```bash - -make examples +make ``` +It will build client and server binaries. ## Example HCL Configuration From 701dc05419ca56aae70d6bd42087842902784577 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 22:13:59 +0100 Subject: [PATCH 53/82] Add readme file --- example/client-server/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/example/client-server/README.md b/example/client-server/README.md index 8d54286..6bf9bc0 100644 --- a/example/client-server/README.md +++ b/example/client-server/README.md @@ -33,3 +33,6 @@ export TG_SERVER_TOKEN=secret-token terragrunt apply --auto-approve ``` + +End to end example: +[![asciicast](https://asciinema.org/a/672387.svg)](https://asciinema.org/a/672387) \ No newline at end of file From 221dce55f541a4adf7f4a2cd4b74d362ab824128 Mon Sep 17 00:00:00 2001 From: Denis O Date: Mon, 19 Aug 2024 22:14:47 +0100 Subject: [PATCH 54/82] Version release --- .circleci/create-release.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.circleci/create-release.sh b/.circleci/create-release.sh index fd946db..a183ffc 100755 --- a/.circleci/create-release.sh +++ b/.circleci/create-release.sh @@ -155,17 +155,17 @@ function main() { check_github_release "${RC_VERSION}" verify_and_reupload_assets "${RC_VERSION}" "release" -# # download rc assets -# download_release_assets "$RC_VERSION" "release-bin" -# -# # create full release -# create_release_notes -# # check if release exists, create if missing -# if ! gh release view "${VERSION}" > /dev/null 2>&1; then -# gh release create "${VERSION}" -F release_notes.txt -t "${VERSION}" release-bin/* -# fi -# check_github_release "${VERSION}" -# verify_and_reupload_assets "${VERSION}" "release-bin" + # download rc assets + download_release_assets "$RC_VERSION" "release-bin" + + # create full release + create_release_notes + # check if release exists, create if missing + if ! gh release view "${VERSION}" > /dev/null 2>&1; then + gh release create "${VERSION}" -F release_notes.txt -t "${VERSION}" release-bin/* + fi + check_github_release "${VERSION}" + verify_and_reupload_assets "${VERSION}" "release-bin" } main "$@" From a73d14b8a861ff291ff2cb9b08a9a85d6b68d928 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 15:43:36 +0100 Subject: [PATCH 55/82] Updated naming convention --- README.md | 2 +- {example => examples}/client-server/Dockerfile | 0 {example => examples}/client-server/Makefile | 0 {example => examples}/client-server/README.md | 0 {example => examples}/client-server/client/main.go | 0 {example => examples}/client-server/docker-compose.yaml | 0 {example => examples}/client-server/go.mod | 0 {example => examples}/client-server/go.sum | 0 {example => examples}/client-server/proto/proto.pb.go | 0 {example => examples}/client-server/proto/proto.proto | 0 {example => examples}/client-server/proto/proto_grpc.pb.go | 0 {example => examples}/client-server/server/main.go | 0 {example => examples}/client-server/util/env.go | 0 13 files changed, 1 insertion(+), 1 deletion(-) rename {example => examples}/client-server/Dockerfile (100%) rename {example => examples}/client-server/Makefile (100%) rename {example => examples}/client-server/README.md (100%) rename {example => examples}/client-server/client/main.go (100%) rename {example => examples}/client-server/docker-compose.yaml (100%) rename {example => examples}/client-server/go.mod (100%) rename {example => examples}/client-server/go.sum (100%) rename {example => examples}/client-server/proto/proto.pb.go (100%) rename {example => examples}/client-server/proto/proto.proto (100%) rename {example => examples}/client-server/proto/proto_grpc.pb.go (100%) rename {example => examples}/client-server/server/main.go (100%) rename {example => examples}/client-server/util/env.go (100%) diff --git a/README.md b/README.md index 2afb21b..d3c6e8b 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Make commands: Implementations of the Terragrunt Engine include: - [terragrunt-engine-opentofu](https://github.com/gruntwork-io/terragrunt-engine-opentofu) -- [terragrunt-engine-client-server](./engine/client-server) +- [terragrunt-engine-client-server](./examples/client-server) ## Example Engine Implementation diff --git a/example/client-server/Dockerfile b/examples/client-server/Dockerfile similarity index 100% rename from example/client-server/Dockerfile rename to examples/client-server/Dockerfile diff --git a/example/client-server/Makefile b/examples/client-server/Makefile similarity index 100% rename from example/client-server/Makefile rename to examples/client-server/Makefile diff --git a/example/client-server/README.md b/examples/client-server/README.md similarity index 100% rename from example/client-server/README.md rename to examples/client-server/README.md diff --git a/example/client-server/client/main.go b/examples/client-server/client/main.go similarity index 100% rename from example/client-server/client/main.go rename to examples/client-server/client/main.go diff --git a/example/client-server/docker-compose.yaml b/examples/client-server/docker-compose.yaml similarity index 100% rename from example/client-server/docker-compose.yaml rename to examples/client-server/docker-compose.yaml diff --git a/example/client-server/go.mod b/examples/client-server/go.mod similarity index 100% rename from example/client-server/go.mod rename to examples/client-server/go.mod diff --git a/example/client-server/go.sum b/examples/client-server/go.sum similarity index 100% rename from example/client-server/go.sum rename to examples/client-server/go.sum diff --git a/example/client-server/proto/proto.pb.go b/examples/client-server/proto/proto.pb.go similarity index 100% rename from example/client-server/proto/proto.pb.go rename to examples/client-server/proto/proto.pb.go diff --git a/example/client-server/proto/proto.proto b/examples/client-server/proto/proto.proto similarity index 100% rename from example/client-server/proto/proto.proto rename to examples/client-server/proto/proto.proto diff --git a/example/client-server/proto/proto_grpc.pb.go b/examples/client-server/proto/proto_grpc.pb.go similarity index 100% rename from example/client-server/proto/proto_grpc.pb.go rename to examples/client-server/proto/proto_grpc.pb.go diff --git a/example/client-server/server/main.go b/examples/client-server/server/main.go similarity index 100% rename from example/client-server/server/main.go rename to examples/client-server/server/main.go diff --git a/example/client-server/util/env.go b/examples/client-server/util/env.go similarity index 100% rename from example/client-server/util/env.go rename to examples/client-server/util/env.go From 376194349cfe8219b625eb15eb3dab6da96faa61 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 15:59:07 +0100 Subject: [PATCH 56/82] go mod ref update --- examples/client-server/go.mod | 4 +++- examples/client-server/go.sum | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/client-server/go.mod b/examples/client-server/go.mod index d688dc3..0c1edfa 100644 --- a/examples/client-server/go.mod +++ b/examples/client-server/go.mod @@ -3,7 +3,7 @@ module github.com/gruntwork-io/terragrunt-engine-go/example/client-server go 1.21 require ( - github.com/gruntwork-io/terragrunt-engine-go v0.0.3-rc2024081904 + github.com/gruntwork-io/terragrunt-engine-go v0.0.2 github.com/hashicorp/go-plugin v1.6.1 github.com/sirupsen/logrus v1.9.3 google.golang.org/grpc v1.65.0 @@ -24,3 +24,5 @@ require ( golang.org/x/text v0.16.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect ) + +replace github.com/gruntwork-io/terragrunt-engine-go => ../.. diff --git a/examples/client-server/go.sum b/examples/client-server/go.sum index ea49e5f..8b90ed3 100644 --- a/examples/client-server/go.sum +++ b/examples/client-server/go.sum @@ -9,8 +9,6 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/gruntwork-io/terragrunt-engine-go v0.0.3-rc2024081904 h1:6SJ3nj5B7XX/MRnLRBbot2P6b84zYgDOqWYFwhUfUac= -github.com/gruntwork-io/terragrunt-engine-go v0.0.3-rc2024081904/go.mod h1:NnZknGXCWIaKtncFg6YuE+NrdSe1yia4JdwNa/mAN1I= github.com/hashicorp/go-hclog v0.14.1 h1:nQcJDQwIAGnmoUWp8ubocEX40cCml/17YkF6csQLReU= github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI= From d28c0614d9a37b7438f062f848978a9c2cca9b7e Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 16:07:47 +0100 Subject: [PATCH 57/82] pushd update --- .circleci/config.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5f91420..52ff57a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -95,11 +95,10 @@ jobs: <<: *install_gruntwork_utils - run: | go mod tidy - pushd . - cd example/client-server/client + pushd example/client-server/client build-go-binaries --app-name terragrunt-iac-engine-client --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" popd - cd example/client-server/server + pushd example/client-server/server build-go-binaries --app-name terragrunt-iac-engine-server --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" - persist_to_workspace: root: . From 66c4b931856e2545bfd19fb59708555156f80975 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 16:09:55 +0100 Subject: [PATCH 58/82] Paths update --- .circleci/config.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 52ff57a..9bc3f28 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -86,6 +86,7 @@ jobs: path: logs - store_test_results: path: logs + path: logs build: resource_class: xlarge <<: *defaults @@ -95,20 +96,20 @@ jobs: <<: *install_gruntwork_utils - run: | go mod tidy - pushd example/client-server/client + pushd examples/client-server/client build-go-binaries --app-name terragrunt-iac-engine-client --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" popd - pushd example/client-server/server + pushd examples/client-server/server build-go-binaries --app-name terragrunt-iac-engine-server --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" - persist_to_workspace: root: . paths: - - example/client-server/client/bin - - example/client-server/server/bin + - examples/client-server/client/bin + - examples/client-server/server/bin - store_artifacts: - path: example/client-server/client/bin + path: examples/client-server/client/bin - store_artifacts: - path: example/client-server/server/bin + path: examples/client-server/server/bin release: <<: *env @@ -139,8 +140,8 @@ jobs: mkdir -p bin-server mkdir -p bin-client # copy other binaries - cp -r example/client-server/server/bin/* bin-server/ - cp -r example/client-server/client/bin/* bin-client/ + cp -r examples/client-server/server/bin/* bin-server/ + cp -r examples/client-server/client/bin/* bin-client/ # create separated directory for client and separated for server From f7ae48eb781a37337aac0fea315b4e7493066828 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 16:11:16 +0100 Subject: [PATCH 59/82] Logs update --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9bc3f28..cd65334 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -86,7 +86,6 @@ jobs: path: logs - store_test_results: path: logs - path: logs build: resource_class: xlarge <<: *defaults From 007b60205b3034f612fbd64d0d67311fc0bb9a33 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 17:46:27 +0100 Subject: [PATCH 60/82] PR comments --- engine/meta.go | 3 --- examples/client-server/Dockerfile | 15 +++++++++++---- examples/client-server/client/main.go | 24 ++++++++++++++++-------- examples/client-server/server/main.go | 4 ++-- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/engine/meta.go b/engine/meta.go index 63cbb6b..76b1655 100644 --- a/engine/meta.go +++ b/engine/meta.go @@ -6,7 +6,6 @@ import ( "strconv" "github.com/gruntwork-io/terragrunt-engine-go/proto" - log "github.com/sirupsen/logrus" "google.golang.org/protobuf/types/known/structpb" ) @@ -36,12 +35,10 @@ func Meta(request *proto.RunRequest) (map[string]interface{}, error) { // MetaString returns the value of a meta key from the RunRequest. If the key does not exist, an empty string is returned. func MetaString(request *proto.RunRequest, key string) (string, error) { meta, err := Meta(request) - log.Printf("Meta: %v", meta) if err != nil { return "", err } value, ok := meta[key] - log.Printf("value: %v", value) if !ok { return "", nil } diff --git a/examples/client-server/Dockerfile b/examples/client-server/Dockerfile index 6c0dd29..3962ed9 100644 --- a/examples/client-server/Dockerfile +++ b/examples/client-server/Dockerfile @@ -1,14 +1,21 @@ -FROM gruntwork/terragrunt:0.2.0 +FROM ubuntu:20.04 as downloader ARG VERSION=v0.0.3-rc2024081902 ARG PLATFORM=linux_amd64 -ENV LISTEN_ADDRESS=0.0.0.0:50051 RUN apt-get update && apt-get install -y wget +RUN wget https://github.com/gruntwork-io/terragrunt-engine-go/releases/download/${VERSION}/terragrunt-iac-engine-server_${PLATFORM} -O /tmp/terragrunt-engine-server +RUN chmod +x /tmp/terragrunt-engine-server + +FROM gruntwork/terragrunt:0.2.0 + +ENV LISTEN_ADDRESS=0.0.0.0:50051 RUN mise use --global -y opentofu@1.7.0 RUN ln -s /root/.local/share/mise/installs/opentofu/1.7.0/bin/tofu /bin/tofu + RUN mkdir /app -RUN wget https://github.com/gruntwork-io/terragrunt-engine-go/releases/download/${VERSION}/terragrunt-iac-engine-server_${PLATFORM} -O /app/terragrunt-engine-server -RUN chmod +x /app/terragrunt-engine-server +COPY --from=downloader /tmp/terragrunt-engine-server /app/terragrunt-engine-server + +WORKDIR /app ENTRYPOINT ["/app/terragrunt-engine-server"] \ No newline at end of file diff --git a/examples/client-server/client/main.go b/examples/client-server/client/main.go index 492e12c..b21f509 100644 --- a/examples/client-server/client/main.go +++ b/examples/client-server/client/main.go @@ -17,6 +17,14 @@ import ( "google.golang.org/grpc" ) +const ( + iacCommand = "IAC_COMMAND" + iacCommandTofu = "tofu" + tokenMeta = "token" + endpointMeta = "endpoint" + tfAutoApprove = "TF_IN_AUTOMATION" +) + type Command struct { Token string Command string @@ -80,18 +88,18 @@ func (c *ClientServerEngine) Init(req *tgengine.InitRequest, stream tgengine.Eng } func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engine_RunServer) error { - log.Infof("Run client command: %v", req.Command) - log.Infof("Run client args: %v", req.Args) - log.Infof("Run client dir: %v", req.WorkingDir) - log.Infof("Run client meta: %v", req.Meta) - iacCommand := util.GetEnv("IAC_COMMAND", "tofu") + log.Debugf("Run client command: %v", req.Command) + log.Debugf("Run client args: %v", req.Args) + log.Debugf("Run client dir: %v", req.WorkingDir) + log.Debugf("Run client meta: %v", req.Meta) + iacCommand := util.GetEnv(iacCommand, iacCommandTofu) - token, err := engine.MetaString(req, "token") + token, err := engine.MetaString(req, tokenMeta) if err != nil { return err } - endpoint, err := engine.MetaString(req, "endpoint") + endpoint, err := engine.MetaString(req, endpointMeta) if err != nil { return err } @@ -101,7 +109,7 @@ func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engin for _, value := range req.Args { command += " " + value } - req.EnvVars["TF_IN_AUTOMATION"] = "true" + req.EnvVars[tfAutoApprove] = "true" output, err := Run(endpoint, &Command{ Command: command, diff --git a/examples/client-server/server/main.go b/examples/client-server/server/main.go index 316cc9c..5033173 100644 --- a/examples/client-server/server/main.go +++ b/examples/client-server/server/main.go @@ -28,11 +28,11 @@ type ShellServiceServer struct { // RunCommand validates the token and runs the command. func (s *ShellServiceServer) RunCommand(_ context.Context, req *pb.CommandRequest) (*pb.CommandResponse, error) { if req.Token != s.Token { - log.Infof("Invalid token: %s, expected %s", req.Token, s.Token) + log.Errorf("Invalid token: %s, expected %s", req.Token, s.Token) return nil, fmt.Errorf("invalid token") } - log.Infof("Running command: %s in %s", req.Command, req.WorkingDir) + log.Debugf("Running command: %s in %s", req.Command, req.WorkingDir) // run command in bash cmd := exec.Command("bash", "-c", req.Command) From 5f7c25979e3f6926b81e3635771a0e3e2483acec Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 17:53:38 +0100 Subject: [PATCH 61/82] extracted constants --- examples/client-server/client/main.go | 14 +++++++------- examples/client-server/server/main.go | 13 +++++++++---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/examples/client-server/client/main.go b/examples/client-server/client/main.go index b21f509..641216f 100644 --- a/examples/client-server/client/main.go +++ b/examples/client-server/client/main.go @@ -18,11 +18,11 @@ import ( ) const ( - iacCommand = "IAC_COMMAND" - iacCommandTofu = "tofu" - tokenMeta = "token" - endpointMeta = "endpoint" - tfAutoApprove = "TF_IN_AUTOMATION" + iacCommand = "IAC_COMMAND" + iacDefaultCommandTofu = "tofu" + tokenMeta = "token" + endpointMeta = "endpoint" + tfAutoApprove = "TF_IN_AUTOMATION" ) type Command struct { @@ -43,7 +43,7 @@ func Run(endpoint string, command *Command) (*CommandOutput, error) { if endpoint != "" { connectAddress = endpoint } - log.Printf("Connecting to %s", connectAddress) + log.Infof("Connecting to %s", connectAddress) conn, err := grpc.NewClient(connectAddress, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, err @@ -92,7 +92,7 @@ func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engin log.Debugf("Run client args: %v", req.Args) log.Debugf("Run client dir: %v", req.WorkingDir) log.Debugf("Run client meta: %v", req.Meta) - iacCommand := util.GetEnv(iacCommand, iacCommandTofu) + iacCommand := util.GetEnv(iacCommand, iacDefaultCommandTofu) token, err := engine.MetaString(req, tokenMeta) if err != nil { diff --git a/examples/client-server/server/main.go b/examples/client-server/server/main.go index 5033173..eb5fd7b 100644 --- a/examples/client-server/server/main.go +++ b/examples/client-server/server/main.go @@ -17,7 +17,12 @@ import ( log "github.com/sirupsen/logrus" ) -const readBufferSize = 1024 +const ( + listenAddress = "LISTEN_ADDRESS" + defaultListenAddress = ":50051" + tokenKey = "token" + readBufferSize = 1024 +) // ShellServiceServer implements the ShellService defined in the proto file. type ShellServiceServer struct { @@ -118,21 +123,21 @@ func readOutput(r io.Reader, ch chan<- string) { // Serve starts the gRPC server func Serve(token string) { - listenAddress := util.GetEnv("LISTEN_ADDRESS", ":50051") + listenAddress := util.GetEnv(listenAddress, defaultListenAddress) listener, err := net.Listen("tcp", listenAddress) if err != nil { log.Fatalf("Failed to listen: %v", err) } grpcServer := grpc.NewServer() pb.RegisterShellServiceServer(grpcServer, &ShellServiceServer{Token: token}) - log.Println("Server is running on port " + listenAddress) + log.Infof("Server is running on port " + listenAddress) if err := grpcServer.Serve(listener); err != nil { log.Fatalf("Failed to serve: %v", err) } } func main() { - token := util.GetEnv("TOKEN", "") + token := util.GetEnv(tokenKey, "") if token == "" { clitoken := flag.String("token", "", "Token for authenticating requests") flag.Parse() From 30abf4209ffa3f7147087bdc587446f35dd461d4 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:02:05 +0100 Subject: [PATCH 62/82] Docker compose update --- examples/client-server/Dockerfile | 7 ++++--- examples/client-server/README.md | 6 +++--- examples/client-server/docker-compose.yaml | 4 +--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/client-server/Dockerfile b/examples/client-server/Dockerfile index 3962ed9..a39ab0c 100644 --- a/examples/client-server/Dockerfile +++ b/examples/client-server/Dockerfile @@ -14,8 +14,9 @@ ENV LISTEN_ADDRESS=0.0.0.0:50051 RUN mise use --global -y opentofu@1.7.0 RUN ln -s /root/.local/share/mise/installs/opentofu/1.7.0/bin/tofu /bin/tofu -RUN mkdir /app -COPY --from=downloader /tmp/terragrunt-engine-server /app/terragrunt-engine-server +COPY --from=downloader /tmp/terragrunt-engine-server /terragrunt-engine-server +RUN mkdir /app WORKDIR /app -ENTRYPOINT ["/app/terragrunt-engine-server"] \ No newline at end of file +ENTRYPOINT ["/terragrunt-engine-server"] + diff --git a/examples/client-server/README.md b/examples/client-server/README.md index 6bf9bc0..2f4c573 100644 --- a/examples/client-server/README.md +++ b/examples/client-server/README.md @@ -1,17 +1,17 @@ # Example Engine Client - Server implementation -To build locally the client and server, run make command: +o build the client and server locally, run the `make` command: ```bash make ``` -It will build client and server binaries. +This will build the `terragrunt-engine-client` and `terragrunt-engine-server` binaries. ## Example HCL Configuration Here is an example of how you can configure the IaC engine client in your Terragrunt configuration: * update `docker-compose.yml` with path to the project where IaC tool should be invoked -* run `docker-compose up` to start the server +* run `docker compose up` to start the server * prepare the client configuration in `terragrunt.hcl` file ```hcl # terragrunt.hcl diff --git a/examples/client-server/docker-compose.yaml b/examples/client-server/docker-compose.yaml index c8c1e1f..d53ada3 100644 --- a/examples/client-server/docker-compose.yaml +++ b/examples/client-server/docker-compose.yaml @@ -1,5 +1,3 @@ - -version: '3' services: terragrunt-engine-server: build: @@ -9,6 +7,6 @@ services: TOKEN: secret-token volumes: # Update path to allow tofu access from container to working directory - - /projects:/projects + - ./:/app ports: - "127.0.0.1:50051:50051" From d5cf2eba86f0c1d95de9bb41fe1064982551867e Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:06:56 +0100 Subject: [PATCH 63/82] Create release --- .circleci/create-release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/create-release.sh b/.circleci/create-release.sh index a183ffc..2cde89c 100755 --- a/.circleci/create-release.sh +++ b/.circleci/create-release.sh @@ -65,13 +65,13 @@ function check_release_exists() { function get_release_id() { local -r release_response=$1 - echo "$release_response" | jq -r '.id' + jq -r '.id' <<< "$release_response" } function get_asset_urls() { local -r release_response=$1 - echo "$release_response" | jq -r '.assets[].browser_download_url' + jq -r '.assets[].browser_download_url' <<< "$release_response" } function verify_and_reupload_assets() { From a1a31086aae1435bf77fc13ad3b961bbe12c7d90 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:11:07 +0100 Subject: [PATCH 64/82] Updated constants --- engine/meta.go | 2 +- examples/client-server/client/main.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/engine/meta.go b/engine/meta.go index 76b1655..493e0cd 100644 --- a/engine/meta.go +++ b/engine/meta.go @@ -9,7 +9,7 @@ import ( "google.golang.org/protobuf/types/known/structpb" ) -// Meta extract request.Meta to go map[string]interface{} struct. +// Meta extracts request.Meta to go map[string]interface{} struct. func Meta(request *proto.RunRequest) (map[string]interface{}, error) { protoMeta := request.Meta meta := make(map[string]interface{}) diff --git a/examples/client-server/client/main.go b/examples/client-server/client/main.go index 641216f..b753fdd 100644 --- a/examples/client-server/client/main.go +++ b/examples/client-server/client/main.go @@ -19,10 +19,12 @@ import ( const ( iacCommand = "IAC_COMMAND" + tfAutoApprove = "TF_IN_AUTOMATION" iacDefaultCommandTofu = "tofu" tokenMeta = "token" endpointMeta = "endpoint" - tfAutoApprove = "TF_IN_AUTOMATION" + connectAddress = "CONNECT_ADDRESS" + defaultConnectAddress = "localhost:50051" ) type Command struct { @@ -39,7 +41,7 @@ type CommandOutput struct { } func Run(endpoint string, command *Command) (*CommandOutput, error) { - connectAddress := util.GetEnv("CONNECT_ADDRESS", "localhost:50051") + connectAddress := util.GetEnv(connectAddress, defaultConnectAddress) if endpoint != "" { connectAddress = endpoint } @@ -151,7 +153,7 @@ func (c *ClientServerEngine) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) er // GRPCClient is used to create a client that connects to the // //nolint:unparam // result 0 (error) is always nil -func (c *ClientServerEngine) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, client *grpc.ClientConn) (interface{}, error) { +func (c *ClientServerEngine) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, client *grpc.ClientConn) (any, error) { return tgengine.NewEngineClient(client), nil } From 91a9f09efa1da65a30545ec15ceac8ba9785d8ba Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:12:54 +0100 Subject: [PATCH 65/82] Address update --- examples/client-server/server/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/client-server/server/main.go b/examples/client-server/server/main.go index eb5fd7b..50cafbc 100644 --- a/examples/client-server/server/main.go +++ b/examples/client-server/server/main.go @@ -123,14 +123,14 @@ func readOutput(r io.Reader, ch chan<- string) { // Serve starts the gRPC server func Serve(token string) { - listenAddress := util.GetEnv(listenAddress, defaultListenAddress) - listener, err := net.Listen("tcp", listenAddress) + address := util.GetEnv(listenAddress, defaultListenAddress) + listener, err := net.Listen("tcp", address) if err != nil { log.Fatalf("Failed to listen: %v", err) } grpcServer := grpc.NewServer() pb.RegisterShellServiceServer(grpcServer, &ShellServiceServer{Token: token}) - log.Infof("Server is running on port " + listenAddress) + log.Infof("Server is running on port " + address) if err := grpcServer.Serve(listener); err != nil { log.Fatalf("Failed to serve: %v", err) } From 678d77f03cb83d5ea166b3718bbbf24e172bb885 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:14:26 +0100 Subject: [PATCH 66/82] Updated error handling --- examples/client-server/client/main.go | 5 ++++- examples/client-server/server/main.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/client-server/client/main.go b/examples/client-server/client/main.go index b753fdd..9b52058 100644 --- a/examples/client-server/client/main.go +++ b/examples/client-server/client/main.go @@ -51,7 +51,10 @@ func Run(endpoint string, command *Command) (*CommandOutput, error) { return nil, err } defer func() { - _ = conn.Close() + err := conn.Close() + if err != nil { + log.Errorf("Error closing connection: %v", err) + } }() client := pb.NewShellServiceClient(conn) diff --git a/examples/client-server/server/main.go b/examples/client-server/server/main.go index 50cafbc..cd014d3 100644 --- a/examples/client-server/server/main.go +++ b/examples/client-server/server/main.go @@ -75,7 +75,10 @@ func (s *ShellServiceServer) RunCommand(_ context.Context, req *pb.CommandReques } defer func() { - _ = stdin.Close() + err := stdin.Close() + if err != nil { + log.Errorf("Error closing stdin: %v", err) + } }() // Read stdout and stderr From 1f140d8ffd3c0e129a666dffde4bafa3fbb4e92a Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:16:05 +0100 Subject: [PATCH 67/82] Simplfied error handling --- examples/client-server/server/main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/client-server/server/main.go b/examples/client-server/server/main.go index cd014d3..ef7c7c6 100644 --- a/examples/client-server/server/main.go +++ b/examples/client-server/server/main.go @@ -75,8 +75,7 @@ func (s *ShellServiceServer) RunCommand(_ context.Context, req *pb.CommandReques } defer func() { - err := stdin.Close() - if err != nil { + if err := stdin.Close(); err != nil { log.Errorf("Error closing stdin: %v", err) } }() From aea26e1f7bdd33b10570a184d38506bdfff56cee Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:19:06 +0100 Subject: [PATCH 68/82] Token level update --- examples/client-server/server/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/client-server/server/main.go b/examples/client-server/server/main.go index ef7c7c6..19d21af 100644 --- a/examples/client-server/server/main.go +++ b/examples/client-server/server/main.go @@ -33,7 +33,7 @@ type ShellServiceServer struct { // RunCommand validates the token and runs the command. func (s *ShellServiceServer) RunCommand(_ context.Context, req *pb.CommandRequest) (*pb.CommandResponse, error) { if req.Token != s.Token { - log.Errorf("Invalid token: %s, expected %s", req.Token, s.Token) + log.Warnf("Invalid token: %s, expected %s", req.Token, s.Token) return nil, fmt.Errorf("invalid token") } From c4ea8dda5540484f6817ae1b2a409be18ced2b8c Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:20:24 +0100 Subject: [PATCH 69/82] Readme update --- examples/client-server/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/client-server/README.md b/examples/client-server/README.md index 2f4c573..7dbe920 100644 --- a/examples/client-server/README.md +++ b/examples/client-server/README.md @@ -1,6 +1,9 @@ # Example Engine Client - Server implementation -o build the client and server locally, run the `make` command: +Example implementation of the Terragrunt IaC engine client and server. +Use it only for testing purposes since it is allowing execution of arbitrary bash commands on the server. + +To build the client and server locally, run the `make` command: ```bash make ``` From 2d9d76069a3e233f2dd34a34e6067cb1c5a34a40 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:27:03 +0100 Subject: [PATCH 70/82] Constant name update --- examples/client-server/client/main.go | 20 +++++++++++--------- examples/client-server/server/main.go | 17 +++++++++-------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/examples/client-server/client/main.go b/examples/client-server/client/main.go index 9b52058..5f95d1b 100644 --- a/examples/client-server/client/main.go +++ b/examples/client-server/client/main.go @@ -18,13 +18,15 @@ import ( ) const ( - iacCommand = "IAC_COMMAND" - tfAutoApprove = "TF_IN_AUTOMATION" - iacDefaultCommandTofu = "tofu" - tokenMeta = "token" - endpointMeta = "endpoint" - connectAddress = "CONNECT_ADDRESS" + iacCommandEnvName = "IAC_COMMAND" + tfAutoApproveEnvName = "TF_IN_AUTOMATION" + connectAddressEnvName = "CONNECT_ADDRESS" + + defaultIacCommand = "tofu" defaultConnectAddress = "localhost:50051" + + tokenMeta = "token" + endpointMeta = "endpoint" ) type Command struct { @@ -41,7 +43,7 @@ type CommandOutput struct { } func Run(endpoint string, command *Command) (*CommandOutput, error) { - connectAddress := util.GetEnv(connectAddress, defaultConnectAddress) + connectAddress := util.GetEnv(connectAddressEnvName, defaultConnectAddress) if endpoint != "" { connectAddress = endpoint } @@ -97,7 +99,7 @@ func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engin log.Debugf("Run client args: %v", req.Args) log.Debugf("Run client dir: %v", req.WorkingDir) log.Debugf("Run client meta: %v", req.Meta) - iacCommand := util.GetEnv(iacCommand, iacDefaultCommandTofu) + iacCommand := util.GetEnv(iacCommandEnvName, defaultIacCommand) token, err := engine.MetaString(req, tokenMeta) if err != nil { @@ -114,7 +116,7 @@ func (c *ClientServerEngine) Run(req *tgengine.RunRequest, stream tgengine.Engin for _, value := range req.Args { command += " " + value } - req.EnvVars[tfAutoApprove] = "true" + req.EnvVars[tfAutoApproveEnvName] = "true" output, err := Run(endpoint, &Command{ Command: command, diff --git a/examples/client-server/server/main.go b/examples/client-server/server/main.go index 19d21af..e12139e 100644 --- a/examples/client-server/server/main.go +++ b/examples/client-server/server/main.go @@ -18,10 +18,11 @@ import ( ) const ( - listenAddress = "LISTEN_ADDRESS" + listenAddressEnvName = "LISTEN_ADDRESS" defaultListenAddress = ":50051" - tokenKey = "token" - readBufferSize = 1024 + + tokenMeta = "token" + readBufferSize = 1024 ) // ShellServiceServer implements the ShellService defined in the proto file. @@ -125,7 +126,7 @@ func readOutput(r io.Reader, ch chan<- string) { // Serve starts the gRPC server func Serve(token string) { - address := util.GetEnv(listenAddress, defaultListenAddress) + address := util.GetEnv(listenAddressEnvName, defaultListenAddress) listener, err := net.Listen("tcp", address) if err != nil { log.Fatalf("Failed to listen: %v", err) @@ -139,14 +140,14 @@ func Serve(token string) { } func main() { - token := util.GetEnv(tokenKey, "") + token := util.GetEnv(tokenMeta, "") if token == "" { - clitoken := flag.String("token", "", "Token for authenticating requests") + cliToken := flag.String("token", "", "Token for authenticating requests") flag.Parse() - if *clitoken == "" { + if *cliToken == "" { log.Fatal("Token is required") } - token = *clitoken + token = *cliToken } Serve(token) } From 45c2d5b01be3672283c38bd1416a1342893e5022 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:30:36 +0100 Subject: [PATCH 71/82] Updated engine server --- examples/client-server/Dockerfile | 4 ++-- examples/client-server/README.md | 1 - examples/client-server/docker-compose.yaml | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/client-server/Dockerfile b/examples/client-server/Dockerfile index a39ab0c..7ac76af 100644 --- a/examples/client-server/Dockerfile +++ b/examples/client-server/Dockerfile @@ -14,9 +14,9 @@ ENV LISTEN_ADDRESS=0.0.0.0:50051 RUN mise use --global -y opentofu@1.7.0 RUN ln -s /root/.local/share/mise/installs/opentofu/1.7.0/bin/tofu /bin/tofu -COPY --from=downloader /tmp/terragrunt-engine-server /terragrunt-engine-server +COPY --from=downloader /tmp/terragrunt-engine-server /opt/terragrunt-engine-server RUN mkdir /app WORKDIR /app -ENTRYPOINT ["/terragrunt-engine-server"] +ENTRYPOINT ["/opt/terragrunt-engine-server"] diff --git a/examples/client-server/README.md b/examples/client-server/README.md index 7dbe920..8e12f3b 100644 --- a/examples/client-server/README.md +++ b/examples/client-server/README.md @@ -13,7 +13,6 @@ This will build the `terragrunt-engine-client` and `terragrunt-engine-server` bi Here is an example of how you can configure the IaC engine client in your Terragrunt configuration: -* update `docker-compose.yml` with path to the project where IaC tool should be invoked * run `docker compose up` to start the server * prepare the client configuration in `terragrunt.hcl` file ```hcl diff --git a/examples/client-server/docker-compose.yaml b/examples/client-server/docker-compose.yaml index d53ada3..7ad36ea 100644 --- a/examples/client-server/docker-compose.yaml +++ b/examples/client-server/docker-compose.yaml @@ -6,7 +6,6 @@ services: environment: TOKEN: secret-token volumes: - # Update path to allow tofu access from container to working directory - ./:/app ports: - "127.0.0.1:50051:50051" From a560ff0bb1bc06187c6cb9b52a8ba5b6adb44616 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:33:35 +0100 Subject: [PATCH 72/82] Readme update --- examples/client-server/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/client-server/README.md b/examples/client-server/README.md index 8e12f3b..b6f4fa9 100644 --- a/examples/client-server/README.md +++ b/examples/client-server/README.md @@ -11,8 +11,7 @@ This will build the `terragrunt-engine-client` and `terragrunt-engine-server` bi ## Example HCL Configuration -Here is an example of how you can configure the IaC engine client in your Terragrunt configuration: - +Here is an example of how you can configure the IaC engine client in your Terragrunt configuration for AMD64 Linux: * run `docker compose up` to start the server * prepare the client configuration in `terragrunt.hcl` file ```hcl From 6c542168f105cd6bb556cd7c77ad439aebac2911 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 18:55:53 +0100 Subject: [PATCH 73/82] Paths update --- .gon_amd64.hcl | 2 +- .gon_arm64.hcl | 2 +- examples/client-server/Makefile | 2 +- examples/client-server/client/main.go | 4 ++-- examples/client-server/go.mod | 2 +- examples/client-server/server/main.go | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gon_amd64.hcl b/.gon_amd64.hcl index eb961ba..9710639 100644 --- a/.gon_amd64.hcl +++ b/.gon_amd64.hcl @@ -1,7 +1,7 @@ # See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ # for further instructions on how to sign the binary + submitting for notarization. -source = ["./example/client-server/client/bin/terragrunt-iac-engine-client_darwin_amd64", "example/client-server/server/bin/terragrunt-iac-engine-server_darwin_amd64"] +source = ["./examples/client-server/client/bin/terragrunt-iac-engine-client_darwin_amd64", "examples/client-server/server/bin/terragrunt-iac-engine-server_darwin_amd64"] bundle_id = "io.gruntwork.app.terragrunt" diff --git a/.gon_arm64.hcl b/.gon_arm64.hcl index b34e554..cabd153 100644 --- a/.gon_arm64.hcl +++ b/.gon_arm64.hcl @@ -1,7 +1,7 @@ # See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ # for further instructions on how to sign the binary + submitting for notarization. -source = ["./example/client-server/client/bin/terragrunt-iac-engine-client_darwin_arm64", "example/client-server/server/bin/terragrunt-iac-engine-server_darwin_arm64"] +source = ["./examples/client-server/client/bin/terragrunt-iac-engine-client_darwin_arm64", "examples/client-server/server/bin/terragrunt-iac-engine-server_darwin_arm64"] bundle_id = "io.gruntwork.app.terragrunt" diff --git a/examples/client-server/Makefile b/examples/client-server/Makefile index 1c3d30c..4bb7f4d 100644 --- a/examples/client-server/Makefile +++ b/examples/client-server/Makefile @@ -5,7 +5,7 @@ tools: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.4.0 go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2 -protoc: $(shell find ./example/client-server -name '*.proto') +protoc: $(shell find ./examples/client-server -name '*.proto') protoc --go_out=. --go_opt=paths=source_relative proto/proto.proto protoc --go-grpc_out=. --go-grpc_opt=paths=source_relative proto/proto.proto diff --git a/examples/client-server/client/main.go b/examples/client-server/client/main.go index 5f95d1b..0139dcf 100644 --- a/examples/client-server/client/main.go +++ b/examples/client-server/client/main.go @@ -4,7 +4,7 @@ import ( "context" "time" - "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" + "github.com/gruntwork-io/terragrunt-engine-go/examples/client-server/util" "google.golang.org/grpc/credentials/insecure" @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/go-plugin" log "github.com/sirupsen/logrus" - pb "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/proto" + pb "github.com/gruntwork-io/terragrunt-engine-go/examples/client-server/proto" tgengine "github.com/gruntwork-io/terragrunt-engine-go/proto" "google.golang.org/grpc" ) diff --git a/examples/client-server/go.mod b/examples/client-server/go.mod index 0c1edfa..a263bbf 100644 --- a/examples/client-server/go.mod +++ b/examples/client-server/go.mod @@ -1,4 +1,4 @@ -module github.com/gruntwork-io/terragrunt-engine-go/example/client-server +module github.com/gruntwork-io/terragrunt-engine-go/examples/client-server go 1.21 diff --git a/examples/client-server/server/main.go b/examples/client-server/server/main.go index e12139e..7f5e1ac 100644 --- a/examples/client-server/server/main.go +++ b/examples/client-server/server/main.go @@ -9,11 +9,11 @@ import ( "os" "os/exec" - "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/util" + "github.com/gruntwork-io/terragrunt-engine-go/examples/client-server/util" "google.golang.org/grpc" - pb "github.com/gruntwork-io/terragrunt-engine-go/example/client-server/proto" + pb "github.com/gruntwork-io/terragrunt-engine-go/examples/client-server/proto" log "github.com/sirupsen/logrus" ) From 7a51d4578e574d3b4cbf305da1fe6841a6649b90 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 19:36:04 +0100 Subject: [PATCH 74/82] Engine building --- examples/client-server/Dockerfile | 22 +++++++++++++++------- examples/client-server/server/main.go | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/examples/client-server/Dockerfile b/examples/client-server/Dockerfile index 7ac76af..001b1a4 100644 --- a/examples/client-server/Dockerfile +++ b/examples/client-server/Dockerfile @@ -1,11 +1,19 @@ -FROM ubuntu:20.04 as downloader +FROM golang:1.21.13-bullseye as builder -ARG VERSION=v0.0.3-rc2024081902 -ARG PLATFORM=linux_amd64 +ARG ENGINE_VERSION=v0.0.3-rc2024081902 -RUN apt-get update && apt-get install -y wget -RUN wget https://github.com/gruntwork-io/terragrunt-engine-go/releases/download/${VERSION}/terragrunt-iac-engine-server_${PLATFORM} -O /tmp/terragrunt-engine-server -RUN chmod +x /tmp/terragrunt-engine-server + + +# clone base engine repo +WORKDIR src +RUN git clone https://github.com/gruntwork-io/terragrunt-engine-go.git -b ${ENGINE_VERSION} . +# add examples from working directory +RUN rm -rf ./examples/* +COPY . ./examples/client-server + +# build engine +WORKDIR examples/client-server +RUN make FROM gruntwork/terragrunt:0.2.0 @@ -14,7 +22,7 @@ ENV LISTEN_ADDRESS=0.0.0.0:50051 RUN mise use --global -y opentofu@1.7.0 RUN ln -s /root/.local/share/mise/installs/opentofu/1.7.0/bin/tofu /bin/tofu -COPY --from=downloader /tmp/terragrunt-engine-server /opt/terragrunt-engine-server +COPY --from=builder /go/src/examples/client-server/terragrunt-engine-server /opt/terragrunt-engine-server RUN mkdir /app WORKDIR /app diff --git a/examples/client-server/server/main.go b/examples/client-server/server/main.go index 7f5e1ac..86c2d67 100644 --- a/examples/client-server/server/main.go +++ b/examples/client-server/server/main.go @@ -19,9 +19,9 @@ import ( const ( listenAddressEnvName = "LISTEN_ADDRESS" + tokenEnvName = "TOKEN" defaultListenAddress = ":50051" - tokenMeta = "token" readBufferSize = 1024 ) @@ -140,7 +140,7 @@ func Serve(token string) { } func main() { - token := util.GetEnv(tokenMeta, "") + token := util.GetEnv(tokenEnvName, "") if token == "" { cliToken := flag.String("token", "", "Token for authenticating requests") flag.Parse() From be520196cd37c3322f8d44f1e9bc6879dd5cadf1 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 19:41:05 +0100 Subject: [PATCH 75/82] Spacing cleanup --- examples/client-server/Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/client-server/Dockerfile b/examples/client-server/Dockerfile index 001b1a4..a876011 100644 --- a/examples/client-server/Dockerfile +++ b/examples/client-server/Dockerfile @@ -2,8 +2,6 @@ FROM golang:1.21.13-bullseye as builder ARG ENGINE_VERSION=v0.0.3-rc2024081902 - - # clone base engine repo WORKDIR src RUN git clone https://github.com/gruntwork-io/terragrunt-engine-go.git -b ${ENGINE_VERSION} . From fe081787973b57682003825c993836a32b62b018 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 19:51:14 +0100 Subject: [PATCH 76/82] Added docker make task --- examples/client-server/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/client-server/Makefile b/examples/client-server/Makefile index 4bb7f4d..4ebef2f 100644 --- a/examples/client-server/Makefile +++ b/examples/client-server/Makefile @@ -17,6 +17,9 @@ build: cd server ;\ go build -o ../terragrunt-engine-server -ldflags "-extldflags '-static'" . +docker: + docker build -t terragrunt-engine-server . + pre-commit: pre-commit run --all-files From 3efbf2eefe9d307f6c995c899976a8a13da8fb18 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 20:32:04 +0100 Subject: [PATCH 77/82] Build process simplification --- .circleci/config.yml | 100 +----------------- .circleci/create-release.sh | 171 ------------------------------- .circleci/sign-files.sh | 67 ------------ examples/client-server/README.md | 2 +- 4 files changed, 5 insertions(+), 335 deletions(-) delete mode 100755 .circleci/create-release.sh delete mode 100755 .circleci/sign-files.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index cd65334..845cdcf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,7 +1,6 @@ version: 2.1 orbs: - win: circleci/windows@5.0 go: circleci/go@1.11 env: &env @@ -94,90 +93,13 @@ jobs: - run: <<: *install_gruntwork_utils - run: | - go mod tidy - pushd examples/client-server/client - build-go-binaries --app-name terragrunt-iac-engine-client --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" - popd - pushd examples/client-server/server - build-go-binaries --app-name terragrunt-iac-engine-server --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" - - persist_to_workspace: - root: . - paths: - - examples/client-server/client/bin - - examples/client-server/server/bin + cd examples/client-server + make - store_artifacts: - path: examples/client-server/client/bin + path: examples/client-server/terragrunt-engine-client - store_artifacts: - path: examples/client-server/server/bin + path: examples/client-server/terragrunt-engine-server - release: - <<: *env - macos: - xcode: 15.3.0 - resource_class: macos.m1.medium.gen1 - steps: - - checkout - - attach_workspace: - at: . - - go/install: - version: "1.21.1" - - run: - name: Install sign-binary-helpers - command: | - curl -Ls https://raw.githubusercontent.com/gruntwork-io/gruntwork-installer/master/bootstrap-gruntwork-installer.sh | bash /dev/stdin --version "${GRUNTWORK_INSTALLER_VERSION}" - gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" - gruntwork-install --module-name "sign-binary-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" - - run: - name: Compile and sign the binaries - command: | - export AC_PASSWORD=${MACOS_AC_PASSWORD} - export AC_PROVIDER=${MACOS_AC_PROVIDER} - - sign-binary --os mac --install-macos-sign-dependencies .gon_amd64.hcl - sign-binary --os mac .gon_arm64.hcl - echo "Done signing the binary" - mkdir -p bin-server - mkdir -p bin-client - # copy other binaries - cp -r examples/client-server/server/bin/* bin-server/ - cp -r examples/client-server/client/bin/* bin-client/ - - # create separated directory for client and separated for server - - # Replace the files in bin. These are the same file names generated from .gon_amd64.hcl and .gon_arm64.hcl - unzip terragrunt-iac-engine-client-server_amd64.zip - unzip terragrunt-iac-engine-client-server_arm64.zip - mv *-server_* bin-server/ - mv *-client_* bin-client/ - ls -lahrt ./bin-client - ls -lahrt ./bin-server - - run: - name: Install required packages - command: | - brew install coreutils gpg gh - # setting sign key - echo "${GW_ENGINE_GPG_KEY}" | base64 --decode > privatekey.asc - echo "${GW_ENGINE_GPG_KEY_PW}" | gpg --batch --yes --import privatekey.asc - KEY_ID=$(gpg --list-keys --with-colons | awk -F: '/^pub/{print $5}') - echo -e "trust\n5\ny\n" | gpg --command-fd 0 --edit-key $KEY_ID trust - mkdir -p ~/.gnupg - echo "default-key $KEY_ID" >> ~/.gnupg/gpg.conf - - run: - name: Package release files - command: | - export BIN=$(pwd)/bin-client - export NAME="client" - export TAG="${CIRCLE_TAG}" - export REPO_NAME="terragrunt-engine-go" - ./.circleci/sign-files.sh - # copy server files to release - cp bin-server/* release/ - ./.circleci/create-release.sh - - persist_to_workspace: - root: . - paths: [release] - - store_artifacts: - path: release #---------------------------------------------------------------------------------------------------------------------- # WORKFLOWS #---------------------------------------------------------------------------------------------------------------------- @@ -216,17 +138,3 @@ workflows: - GITHUB__PAT__gruntwork-ci - APPLE__OSX__code-signing - TERRAGRUNT_ENGINE__circle-ci - - release: - requires: - - build - filters: - tags: - only: /^.*-rc.*$/ - branches: - ignore: /.*/ - context: - - AWS__PHXDEVOPS__circle-ci-test - - GCP__automated-tests - - GITHUB__PAT__gruntwork-ci - - APPLE__OSX__code-signing - - TERRAGRUNT_ENGINE__circle-ci \ No newline at end of file diff --git a/.circleci/create-release.sh b/.circleci/create-release.sh deleted file mode 100755 index 2cde89c..0000000 --- a/.circleci/create-release.sh +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/env bash -# Create Github release from release candidate tag -set -euo pipefail - -export GH_TOKEN=${GW_GITHUB_OAUTH_TOKEN} - -readonly REPO_OWNER="${REPO_OWNER:-gruntwork-io}" -readonly REPO_NAME="${REPO_NAME:-terragrunt-engine-go}" -readonly MAX_RETRIES=${MAX_RETRIES:-10} -readonly RETRY_INTERVAL=${RETRY_INTERVAL:-20} - -readonly RC_VERSION=${TAG} -readonly VERSION=${TAG%-rc*} -readonly RELEASE="${RELEASE:-release}" -readonly COMMITS=$(git log $(git describe --tags --abbrev=0 @^)..@ --pretty=format:"- %s") - -function create_rc_release_notes() { - cat << EOF > rc_release_notes.txt -## Pre-Release $RC_VERSION - -### Changes -$COMMITS - -EOF -} - -function create_release_notes() { - cat << EOF > release_notes.txt -## Release $VERSION - -### Changes -$COMMITS - -EOF -} - -function get_release_response() { - local -r release_tag=$1 - - # First try using the gh CLI - local response - if response=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \ - "/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$release_tag" 2> /dev/null); then - echo "$response" - else - # Fallback to using curl if gh CLI fails - response=$(curl -s \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token $GH_TOKEN" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/tags/$release_tag") - echo "$response" - fi -} - -function check_release_exists() { - local -r release_response=$1 - - if jq -e '.message == "Not Found"' <<< "$release_response" > /dev/null; then - echo "Release $CIRCLE_TAG not found. Exiting..." - exit 1 - fi -} - -function get_release_id() { - local -r release_response=$1 - - jq -r '.id' <<< "$release_response" -} - -function get_asset_urls() { - local -r release_response=$1 - - jq -r '.assets[].browser_download_url' <<< "$release_response" -} - -function verify_and_reupload_assets() { - local -r release_version=$1 - local -r asset_dir=$2 - - # Get the list of assets for the release - local assets - assets=$(gh release view "$release_version" --json assets --jq '.assets[].name') - - if [ -z "$assets" ]; then - echo "No assets found for release $release_version" - return - fi - - for asset in $assets; do - for ((i=0; i /dev/null 2>&1; then - echo "Failed to download the asset $asset. Uploading..." - - # Re-upload the asset - if ! gh release upload --clobber "$release_version" "${asset_dir}/${asset}"; then - echo "Failed to upload $asset" - sleep $RETRY_INTERVAL - else - echo "Successfully uploaded $asset" - break - fi - else - echo "Successfully checked the asset $asset" - rm -f "/tmp/$asset" - break - fi - done - - if (( i == MAX_RETRIES )); then - echo "Failed to process the asset $asset after $MAX_RETRIES retries. Exiting..." - exit 1 - fi - done -} - -function check_github_release() { - local retries=0 - local release_tag=$1 - - while [ $retries -lt $MAX_RETRIES ]; do - if gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \ - "/repos/$REPO_OWNER/$REPO_NAME/releases" | jq -e --arg tag "$release_tag" '.[] | select(.tag_name == $tag)' > /dev/null; then - echo "Release $release_tag found." - return 0 - else - echo "Release $release_tag not found. Retrying in $RETRY_INTERVAL seconds..." - ((retries++)) - sleep $RETRY_INTERVAL - fi - done - - echo "Failed to find release $release_tag after $MAX_RETRIES retries. Exiting..." - exit 1 -} - -function download_release_assets() { - local -r release_tag=$1 - local -r download_dir=$2 - - mkdir -p "$download_dir" - - assets=$(gh release view "$release_tag" --json assets --jq '.assets[].name') - for asset in $assets; do - gh release download "$release_tag" --pattern "$asset" -D "$download_dir" - done -} - -function main() { - create_rc_release_notes - # check if rc release exists, create if missing - if ! gh release view "${RC_VERSION}" > /dev/null 2>&1; then - gh release create "${RC_VERSION}" --prerelease -F rc_release_notes.txt -t "${RC_VERSION}" release/* - fi - check_github_release "${RC_VERSION}" - verify_and_reupload_assets "${RC_VERSION}" "release" - - # download rc assets - download_release_assets "$RC_VERSION" "release-bin" - - # create full release - create_release_notes - # check if release exists, create if missing - if ! gh release view "${VERSION}" > /dev/null 2>&1; then - gh release create "${VERSION}" -F release_notes.txt -t "${VERSION}" release-bin/* - fi - check_github_release "${VERSION}" - verify_and_reupload_assets "${VERSION}" "release-bin" -} - -main "$@" diff --git a/.circleci/sign-files.sh b/.circleci/sign-files.sh deleted file mode 100755 index 265ab86..0000000 --- a/.circleci/sign-files.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env bash -# This script is used to sign the release files with the GPG key -set -euo pipefail - -readonly BIN="${BIN:-bin}" -readonly RELEASE="${RELEASE:-release}" -readonly NAME="${NAME:-opentofu}" -# Extract version from RC -readonly VERSION=${TAG%-rc*} -readonly TYPE="rpc" - -function get_key_id() { - gpg --list-keys --with-colons | awk -F: '/^pub/{print $5}' -} - -function prepare_release_directory() { - mkdir -p "${RELEASE}" -} - -function process_files() { - cd "${BIN}" - for file in *; do - # Extract the OS and ARCH from the file name - if [[ $file =~ terragrunt-iac-engine-${NAME}_([^_]+)_([^_]+) ]]; then - OS="${BASH_REMATCH[1]}" - ARCH="${BASH_REMATCH[2]}" - - # Set the binary and archive names - BINARY_NAME="terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_${OS}_${ARCH}" - mv "${file}" "${BINARY_NAME}" - ARCHIVE_NAME="terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_${OS}_${ARCH}.zip" - - # Create the zip archive - zip "${ARCHIVE_NAME}" "${BINARY_NAME}" - fi - done - cd .. -} - -# Function to create the SHA256SUMS file -function create_shasums_file() { - pwd=$(pwd) - cd "${BIN}" - # Create the SHA256SUMS file for all files in the release directory - shasum -a 256 * > "terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_SHA256SUMS" - cp *.zip ../"${RELEASE}" - cp "terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_SHA256SUMS" ../"${RELEASE}" - cd "../${RELEASE}" -} - -# Function to sign the SHA256SUMS file -function sign_shasums_file() { - local -r key_id=$1 - echo "${GW_ENGINE_GPG_KEY_PW}" | gpg --batch --yes --pinentry-mode loopback --passphrase-fd 0 --default-key "${key_id}" --detach-sign "terragrunt-iac-engine-${NAME}_${TYPE}_${VERSION}_SHA256SUMS" -} - -# Main function to orchestrate the actions -main() { - local key_id - key_id=$(get_key_id) - prepare_release_directory - process_files - create_shasums_file - sign_shasums_file "$key_id" -} - -main "$@" diff --git a/examples/client-server/README.md b/examples/client-server/README.md index b6f4fa9..2f9da08 100644 --- a/examples/client-server/README.md +++ b/examples/client-server/README.md @@ -17,7 +17,7 @@ Here is an example of how you can configure the IaC engine client in your Terrag ```hcl # terragrunt.hcl engine { - source = "https://github.com/gruntwork-io/terragrunt-engine-go/releases/download/v0.0.3-rc2024081902/terragrunt-iac-engine-client_rpc_v0.0.3_linux_amd64.zip" + source = "./terragrunt-iac-engine-client" meta = { # server endpoint endpoint = "127.0.0.1:50051" From 11a78e572c938361a5c1bd2099b021c80a8004a3 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 20:34:11 +0100 Subject: [PATCH 78/82] cleanup --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 845cdcf..25405ad 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,7 +31,6 @@ install_gruntwork_utils: &install_gruntwork_utils gruntwork-install --module-name "gruntwork-module-circleci-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" gruntwork-install --module-name "git-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" gruntwork-install --binary-name "terratest_log_parser" --repo "https://github.com/gruntwork-io/terratest" --tag "${TERRATEST_LOG_PARSER_VERSION}" - gruntwork-install --module-name "sign-binary-helpers" --repo "https://github.com/gruntwork-io/terraform-aws-ci" --tag "${MODULE_CI_VERSION}" configure-environment-for-gruntwork-module \ --mise-version "NONE" \ --terraform-version "NONE" \ From 025b227662ec94535d8351cf844bd3ea3ab4c01c Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 20:43:31 +0100 Subject: [PATCH 79/82] Executables building --- .circleci/config.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 25405ad..9292892 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -92,12 +92,22 @@ jobs: - run: <<: *install_gruntwork_utils - run: | - cd examples/client-server + go mod tidy + pushd examples/client-server make + build-go-binaries --app-name terragrunt-iac-engine-client --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" + popd + pushd examples/client-server/server + build-go-binaries --app-name terragrunt-iac-engine-server --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" + - persist_to_workspace: + root: . + paths: + - examples/client-server/client/bin + - examples/client-server/server/bin - store_artifacts: - path: examples/client-server/terragrunt-engine-client + path: examples/client-server/client/bin - store_artifacts: - path: examples/client-server/terragrunt-engine-server + path: examples/client-server/server/bin #---------------------------------------------------------------------------------------------------------------------- # WORKFLOWS From 28e50d82003d907a13f593383274b763862760d3 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 20:45:13 +0100 Subject: [PATCH 80/82] removed gon files --- .gon_amd64.hcl | 18 ------------------ .gon_arm64.hcl | 18 ------------------ 2 files changed, 36 deletions(-) delete mode 100644 .gon_amd64.hcl delete mode 100644 .gon_arm64.hcl diff --git a/.gon_amd64.hcl b/.gon_amd64.hcl deleted file mode 100644 index 9710639..0000000 --- a/.gon_amd64.hcl +++ /dev/null @@ -1,18 +0,0 @@ -# See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ -# for further instructions on how to sign the binary + submitting for notarization. - -source = ["./examples/client-server/client/bin/terragrunt-iac-engine-client_darwin_amd64", "examples/client-server/server/bin/terragrunt-iac-engine-server_darwin_amd64"] - -bundle_id = "io.gruntwork.app.terragrunt" - -apple_id { - username = "machine.apple@gruntwork.io" -} - -sign { - application_identity = "Developer ID Application: Gruntwork, Inc." -} - -zip { - output_path = "terragrunt-iac-engine-client-server_amd64.zip" -} diff --git a/.gon_arm64.hcl b/.gon_arm64.hcl deleted file mode 100644 index cabd153..0000000 --- a/.gon_arm64.hcl +++ /dev/null @@ -1,18 +0,0 @@ -# See https://github.com/gruntwork-io/terraform-aws-ci/blob/main/modules/sign-binary-helpers/ -# for further instructions on how to sign the binary + submitting for notarization. - -source = ["./examples/client-server/client/bin/terragrunt-iac-engine-client_darwin_arm64", "examples/client-server/server/bin/terragrunt-iac-engine-server_darwin_arm64"] - -bundle_id = "io.gruntwork.app.terragrunt" - -apple_id { - username = "machine.apple@gruntwork.io" -} - -sign { - application_identity = "Developer ID Application: Gruntwork, Inc." -} - -zip { - output_path = "terragrunt-iac-engine-client-server_arm64.zip" -} From adbad4473e081909a0f1de8c9c27e0132ae7d22b Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 20:51:34 +0100 Subject: [PATCH 81/82] Cleanup --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9292892..807a387 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,7 +94,6 @@ jobs: - run: | go mod tidy pushd examples/client-server - make build-go-binaries --app-name terragrunt-iac-engine-client --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" popd pushd examples/client-server/server From 9feaf911a29349a7987fcdce6efde9ea7d877908 Mon Sep 17 00:00:00 2001 From: Denis O Date: Tue, 20 Aug 2024 20:54:01 +0100 Subject: [PATCH 82/82] Client building --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 807a387..0f07bea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -93,7 +93,7 @@ jobs: <<: *install_gruntwork_utils - run: | go mod tidy - pushd examples/client-server + pushd examples/client-server/client build-go-binaries --app-name terragrunt-iac-engine-client --dest-path bin --ld-flags "-X github.com/gruntwork-io/go-commons/version.Version=$CIRCLE_TAG -extldflags '-static'" popd pushd examples/client-server/server