You've already forked golang-saas-starter-kit
mirror of
https://github.com/raseels-repos/golang-saas-starter-kit.git
synced 2025-08-10 22:41:25 +02:00
gitlab json encode build info fields title and description
This commit is contained in:
@@ -327,3 +327,9 @@ func convertKeys(j json.RawMessage) json.RawMessage {
|
|||||||
func fixKey(key string) string {
|
func fixKey(key string) string {
|
||||||
return strings.ToTitle(key)
|
return strings.ToTitle(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// jsonEncodeStringValue json encodes string values to be used in the ECS task definition.
|
||||||
|
func jsonEncodeStringValue(str string) string {
|
||||||
|
dat, _ := json.Marshal(str)
|
||||||
|
return strings.Trim(string(dat), "\"")
|
||||||
|
}
|
||||||
|
@@ -100,6 +100,8 @@ type serviceDeployRequest struct {
|
|||||||
Ec2SecurityGroupName string `validate:"required"`
|
Ec2SecurityGroupName string `validate:"required"`
|
||||||
Ec2SecurityGroup *ec2.CreateSecurityGroupInput
|
Ec2SecurityGroup *ec2.CreateSecurityGroupInput
|
||||||
|
|
||||||
|
GitlabRunnerEc2SecurityGroupName string `validate:"required"`
|
||||||
|
|
||||||
CloudWatchLogGroupName string `validate:"required"`
|
CloudWatchLogGroupName string `validate:"required"`
|
||||||
CloudWatchLogGroup *cloudwatchlogs.CreateLogGroupInput
|
CloudWatchLogGroup *cloudwatchlogs.CreateLogGroupInput
|
||||||
|
|
||||||
@@ -488,6 +490,10 @@ func NewServiceDeployRequest(log *log.Logger, flags ServiceDeployFlags) (*servic
|
|||||||
}
|
}
|
||||||
log.Printf("\t\t\tSet ECS Security Group Name to '%s'.", req.Ec2SecurityGroupName)
|
log.Printf("\t\t\tSet ECS Security Group Name to '%s'.", req.Ec2SecurityGroupName)
|
||||||
|
|
||||||
|
// Set the name of the EC2 Security Group used by the gitlab runner. This is used to ensure the security
|
||||||
|
// group defined above has access to the RDS cluster/instance and can thus handle schema migrations.
|
||||||
|
req.GitlabRunnerEc2SecurityGroupName = "gitlab-runner"
|
||||||
|
|
||||||
// Set default ELB Load Balancer Name when ELB is enabled.
|
// Set default ELB Load Balancer Name when ELB is enabled.
|
||||||
if req.EnableEcsElb {
|
if req.EnableEcsElb {
|
||||||
if !strings.Contains(req.EcsClusterName, req.Env) && !strings.Contains(req.ServiceName, req.Env) {
|
if !strings.Contains(req.EcsClusterName, req.Env) && !strings.Contains(req.ServiceName, req.Env) {
|
||||||
@@ -1049,13 +1055,15 @@ func ServiceDeploy(log *log.Logger, req *serviceDeployRequest) error {
|
|||||||
req.Ec2SecurityGroup.VpcId = aws.String(projectVpcId)
|
req.Ec2SecurityGroup.VpcId = aws.String(projectVpcId)
|
||||||
|
|
||||||
// Find all the security groups and then parse the group name to get the Id of the security group.
|
// Find all the security groups and then parse the group name to get the Id of the security group.
|
||||||
|
var runnerSgId string
|
||||||
err := svc.DescribeSecurityGroupsPages(&ec2.DescribeSecurityGroupsInput{
|
err := svc.DescribeSecurityGroupsPages(&ec2.DescribeSecurityGroupsInput{
|
||||||
GroupNames: aws.StringSlice([]string{req.Ec2SecurityGroupName}),
|
GroupNames: aws.StringSlice([]string{req.Ec2SecurityGroupName, req.GitlabRunnerEc2SecurityGroupName}),
|
||||||
}, func(res *ec2.DescribeSecurityGroupsOutput, lastPage bool) bool {
|
}, func(res *ec2.DescribeSecurityGroupsOutput, lastPage bool) bool {
|
||||||
for _, s := range res.SecurityGroups {
|
for _, s := range res.SecurityGroups {
|
||||||
if *s.GroupName == req.Ec2SecurityGroupName {
|
if *s.GroupName == req.Ec2SecurityGroupName {
|
||||||
securityGroupId = *s.GroupId
|
securityGroupId = *s.GroupId
|
||||||
break
|
} else if *s.GroupName == req.GitlabRunnerEc2SecurityGroupName {
|
||||||
|
runnerSgId = *s.GroupId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return !lastPage
|
return !lastPage
|
||||||
@@ -1108,6 +1116,20 @@ func ServiceDeploy(log *log.Logger, req *serviceDeployRequest) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When a db instance is defined, deploy needs access to the RDS instance to handle executing schema migration.
|
||||||
|
if req.DBInstance != nil {
|
||||||
|
// The gitlab runner security group is required when a db instance is defined.
|
||||||
|
if runnerSgId == "" {
|
||||||
|
return errors.Errorf("Failed to find security group '%s'", req.GitlabRunnerEc2SecurityGroupName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable GitLab runner to communicate with deployment created services.
|
||||||
|
ingressInputs = append(ingressInputs, &ec2.AuthorizeSecurityGroupIngressInput{
|
||||||
|
SourceSecurityGroupName: aws.String(req.GitlabRunnerEc2SecurityGroupName),
|
||||||
|
GroupId: aws.String(securityGroupId),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Add all the default ingress to the security group.
|
// Add all the default ingress to the security group.
|
||||||
for _, ingressInput := range ingressInputs {
|
for _, ingressInput := range ingressInputs {
|
||||||
_, err = svc.AuthorizeSecurityGroupIngress(ingressInput)
|
_, err = svc.AuthorizeSecurityGroupIngress(ingressInput)
|
||||||
@@ -2302,8 +2324,8 @@ func ServiceDeploy(log *log.Logger, req *serviceDeployRequest) error {
|
|||||||
"{CI_COMMIT_REF_SLUG}": os.Getenv("CI_COMMIT_REF_SLUG"),
|
"{CI_COMMIT_REF_SLUG}": os.Getenv("CI_COMMIT_REF_SLUG"),
|
||||||
"{CI_COMMIT_SHA}": os.Getenv("CI_COMMIT_SHA"),
|
"{CI_COMMIT_SHA}": os.Getenv("CI_COMMIT_SHA"),
|
||||||
"{CI_COMMIT_TAG}": os.Getenv("CI_COMMIT_TAG"),
|
"{CI_COMMIT_TAG}": os.Getenv("CI_COMMIT_TAG"),
|
||||||
"{CI_COMMIT_TITLE}": os.Getenv("CI_COMMIT_TITLE"),
|
"{CI_COMMIT_TITLE}": jsonEncodeStringValue(os.Getenv("CI_COMMIT_TITLE")),
|
||||||
"{CI_COMMIT_DESCRIPTION}": os.Getenv("CI_COMMIT_DESCRIPTION"),
|
"{CI_COMMIT_DESCRIPTION}": jsonEncodeStringValue(os.Getenv("CI_COMMIT_DESCRIPTION")),
|
||||||
"{CI_COMMIT_JOB_ID}": os.Getenv("CI_COMMIT_JOB_ID"),
|
"{CI_COMMIT_JOB_ID}": os.Getenv("CI_COMMIT_JOB_ID"),
|
||||||
"{CI_COMMIT_JOB_URL}": os.Getenv("CI_COMMIT_JOB_URL"),
|
"{CI_COMMIT_JOB_URL}": os.Getenv("CI_COMMIT_JOB_URL"),
|
||||||
"{CI_COMMIT_PIPELINE_ID}": os.Getenv("CI_COMMIT_PIPELINE_ID"),
|
"{CI_COMMIT_PIPELINE_ID}": os.Getenv("CI_COMMIT_PIPELINE_ID"),
|
||||||
|
Reference in New Issue
Block a user