You've already forked golang-saas-starter-kit
mirror of
https://github.com/raseels-repos/golang-saas-starter-kit.git
synced 2025-07-01 00:55:01 +02:00
issue#8 datadog ECS logs
Working on cleaning up deployment code to add support for deploying a lambda function to ship logs from AWS cloudwatch to datadog. WIP
This commit is contained in:
24
tools/devops/cmd/cicd/deploy.go
Normal file
24
tools/devops/cmd/cicd/deploy.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package cicd
|
||||||
|
|
||||||
|
import "github.com/aws/aws-sdk-go/service/ec2"
|
||||||
|
|
||||||
|
// deployRequest defines the details needed to execute a service deployment.
|
||||||
|
type deployRequest struct {
|
||||||
|
*serviceRequest
|
||||||
|
|
||||||
|
EcrRepositoryName string `validate:"required"`
|
||||||
|
|
||||||
|
Ec2SecurityGroupName string `validate:"required"`
|
||||||
|
Ec2SecurityGroup *ec2.CreateSecurityGroupInput
|
||||||
|
|
||||||
|
GitlabRunnerEc2SecurityGroupName string `validate:"required"`
|
||||||
|
|
||||||
|
S3BucketTempPrefix string `validate:"required_with=S3BucketPrivateName S3BucketPublicName"`
|
||||||
|
S3BucketPrivateName string `validate:"omitempty"`
|
||||||
|
S3Buckets []S3Bucket
|
||||||
|
|
||||||
|
|
||||||
|
EcsService *deployEcsServiceRequest
|
||||||
|
LambdaFunction *deployLambdaFuncRequest
|
||||||
|
}
|
||||||
|
|
11
tools/devops/cmd/cicd/deploy_function.go
Normal file
11
tools/devops/cmd/cicd/deploy_function.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package cicd
|
||||||
|
|
||||||
|
|
||||||
|
// deployLambdaFuncRequest defines the details needed to deploy a function to AWS Lambda.
|
||||||
|
type deployLambdaFuncRequest struct {
|
||||||
|
EnableLambdaVPC bool `validate:"omitempty"`
|
||||||
|
|
||||||
|
FuncName string `validate:"required"`
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -74,15 +74,18 @@ type ServiceDeployFlags struct {
|
|||||||
RecreateService bool `validate:"omitempty" example:"false"`
|
RecreateService bool `validate:"omitempty" example:"false"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// serviceDeployRequest defines the details needed to execute a service deployment.
|
|
||||||
type serviceDeployRequest struct {
|
|
||||||
*serviceRequest
|
// deployEcsServiceRequest defines the details needed to execute a service deployment to AWS ECS.
|
||||||
|
type deployEcsServiceRequest struct {
|
||||||
|
|
||||||
|
S3BucketPublicName string `validate:"omitempty"`
|
||||||
|
S3BucketPublicKeyPrefix string `validate:"omitempty"`
|
||||||
|
|
||||||
EnableHTTPS bool `validate:"omitempty"`
|
EnableHTTPS bool `validate:"omitempty"`
|
||||||
ServiceHostPrimary string `validate:"omitempty,required_with=EnableHTTPS,fqdn"`
|
ServiceHostPrimary string `validate:"omitempty,required_with=EnableHTTPS,fqdn"`
|
||||||
ServiceHostNames []string `validate:"omitempty,dive,fqdn"`
|
ServiceHostNames []string `validate:"omitempty,dive,fqdn"`
|
||||||
|
|
||||||
EcrRepositoryName string `validate:"required"`
|
|
||||||
|
|
||||||
EcsClusterName string `validate:"required"`
|
EcsClusterName string `validate:"required"`
|
||||||
EcsCluster *ecs.CreateClusterInput
|
EcsCluster *ecs.CreateClusterInput
|
||||||
@ -104,19 +107,10 @@ type serviceDeployRequest struct {
|
|||||||
EcsTaskPolicy *iam.CreatePolicyInput
|
EcsTaskPolicy *iam.CreatePolicyInput
|
||||||
EcsTaskPolicyDocument IamPolicyDocument
|
EcsTaskPolicyDocument IamPolicyDocument
|
||||||
|
|
||||||
Ec2SecurityGroupName string `validate:"required"`
|
|
||||||
Ec2SecurityGroup *ec2.CreateSecurityGroupInput
|
|
||||||
|
|
||||||
GitlabRunnerEc2SecurityGroupName string `validate:"required"`
|
|
||||||
|
|
||||||
CloudWatchLogGroupName string `validate:"required"`
|
CloudWatchLogGroupName string `validate:"required"`
|
||||||
CloudWatchLogGroup *cloudwatchlogs.CreateLogGroupInput
|
CloudWatchLogGroup *cloudwatchlogs.CreateLogGroupInput
|
||||||
|
|
||||||
S3BucketTempPrefix string `validate:"required_with=S3BucketPrivateName S3BucketPublicName"`
|
|
||||||
S3BucketPrivateName string `validate:"omitempty"`
|
|
||||||
S3BucketPublicName string `validate:"omitempty"`
|
|
||||||
S3BucketPublicKeyPrefix string `validate:"omitempty"`
|
|
||||||
S3Buckets []S3Bucket
|
|
||||||
|
|
||||||
CloudfrontPublic *cloudfront.DistributionConfig
|
CloudfrontPublic *cloudfront.DistributionConfig
|
||||||
|
|
||||||
@ -136,8 +130,6 @@ type serviceDeployRequest struct {
|
|||||||
VpcPublic *ec2.CreateVpcInput
|
VpcPublic *ec2.CreateVpcInput
|
||||||
VpcPublicSubnets []*ec2.CreateSubnetInput
|
VpcPublicSubnets []*ec2.CreateSubnetInput
|
||||||
|
|
||||||
EnableLambdaVPC bool `validate:"omitempty"`
|
|
||||||
IsLambda bool `validate:"omitempty"`
|
|
||||||
RecreateService bool `validate:"omitempty"`
|
RecreateService bool `validate:"omitempty"`
|
||||||
|
|
||||||
SDNamepsace *servicediscovery.CreatePrivateDnsNamespaceInput
|
SDNamepsace *servicediscovery.CreatePrivateDnsNamespaceInput
|
||||||
@ -152,6 +144,9 @@ type serviceDeployRequest struct {
|
|||||||
flags ServiceDeployFlags
|
flags ServiceDeployFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// NewServiceDeployRequest generates a new request for executing deployment of a single service for a given set of CLI flags.
|
// NewServiceDeployRequest generates a new request for executing deployment of a single service for a given set of CLI flags.
|
||||||
func NewServiceDeployRequest(log *log.Logger, flags ServiceDeployFlags) (*serviceDeployRequest, error) {
|
func NewServiceDeployRequest(log *log.Logger, flags ServiceDeployFlags) (*serviceDeployRequest, error) {
|
||||||
|
|
@ -70,7 +70,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "deploy",
|
Name: "deploy-service",
|
||||||
Usage: "-service=web-api -env=dev",
|
Usage: "-service=web-api -env=dev",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{Name: "service", Usage: "name of cmd", Destination: &deployFlags.ServiceName},
|
cli.StringFlag{Name: "service", Usage: "name of cmd", Destination: &deployFlags.ServiceName},
|
||||||
@ -88,7 +88,7 @@ func main() {
|
|||||||
cli.BoolTFlag{Name: "lambda_vpc", Usage: "deploy lambda behind VPC", Destination: &deployFlags.EnableLambdaVPC},
|
cli.BoolTFlag{Name: "lambda_vpc", Usage: "deploy lambda behind VPC", Destination: &deployFlags.EnableLambdaVPC},
|
||||||
cli.BoolFlag{Name: "static_files_s3", Usage: "service static files from S3", Destination: &deployFlags.StaticFilesS3Enable},
|
cli.BoolFlag{Name: "static_files_s3", Usage: "service static files from S3", Destination: &deployFlags.StaticFilesS3Enable},
|
||||||
cli.BoolFlag{Name: "static_files_img_resize", Usage: "enable response images from service", Destination: &deployFlags.StaticFilesImgResizeEnable},
|
cli.BoolFlag{Name: "static_files_img_resize", Usage: "enable response images from service", Destination: &deployFlags.StaticFilesImgResizeEnable},
|
||||||
cli.BoolFlag{Name: "recreate_service", Usage: "skip docker push after build", Destination: &deployFlags.RecreateService},
|
cli.BoolFlag{Name: "recreate", Usage: "skip docker push after build", Destination: &deployFlags.RecreateService},
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
if len(deployFlags.ServiceHostNames.Value()) == 1 {
|
if len(deployFlags.ServiceHostNames.Value()) == 1 {
|
||||||
@ -114,6 +114,44 @@ func main() {
|
|||||||
return cicd.ServiceDeploy(log, req)
|
return cicd.ServiceDeploy(log, req)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "deploy-function",
|
||||||
|
Usage: "-function=web-api -env=dev",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "function", Usage: "name of function", Destination: &deployFlags.ServiceName},
|
||||||
|
cli.StringFlag{Name: "env", Usage: "dev, stage, or prod", Destination: &deployFlags.Env},
|
||||||
|
cli.StringFlag{Name: "private_bucket", Usage: "dev, stage, or prod", Destination: &deployFlags.S3BucketPrivateName},
|
||||||
|
cli.StringFlag{Name: "dockerfile", Usage: "DockerFile for service", Destination: &deployFlags.DockerFile},
|
||||||
|
cli.StringFlag{Name: "root", Usage: "project root directory", Destination: &deployFlags.ProjectRoot},
|
||||||
|
cli.StringFlag{Name: "project", Usage: "name of project", Destination: &deployFlags.ProjectName},
|
||||||
|
cli.BoolTFlag{Name: "use_vpc", Usage: "deploy lambda behind VPC", Destination: &deployFlags.EnableLambdaVPC},
|
||||||
|
cli.BoolFlag{Name: "recreate", Usage: "skip docker push after build", Destination: &deployFlags.RecreateService},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
if len(deployFlags.ServiceHostNames.Value()) == 1 {
|
||||||
|
var hostNames []string
|
||||||
|
for _, inpVal := range deployFlags.ServiceHostNames.Value() {
|
||||||
|
pts := strings.Split(inpVal, ",")
|
||||||
|
|
||||||
|
for _, h := range pts {
|
||||||
|
h = strings.TrimSpace(h)
|
||||||
|
if h != "" {
|
||||||
|
hostNames = append(hostNames, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deployFlags.ServiceHostNames = hostNames
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := cicd.NewServiceDeployRequest(log, deployFlags)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return cicd.ServiceDeploy(log, req)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: "migrate",
|
Name: "migrate",
|
||||||
Usage: "-env=dev",
|
Usage: "-env=dev",
|
||||||
|
Reference in New Issue
Block a user