mirror of
https://github.com/docker/compose.git
synced 2025-07-28 08:04:09 +02:00
Compute resource names to avoid unsupported characters
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
257f829679
commit
564c369c3e
@ -2,6 +2,7 @@ package amazon
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -99,7 +100,7 @@ func (c client) Convert(project *compose.Project) (*cloudformation.Template, err
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
taskExecutionRole := fmt.Sprintf("%sTaskExecutionRole", service.Name)
|
taskExecutionRole := fmt.Sprintf("%sTaskExecutionRole", normalizeResourceName(service.Name))
|
||||||
policy, err := c.getPolicy(definition)
|
policy, err := c.getPolicy(definition)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -114,7 +115,7 @@ func (c client) Convert(project *compose.Project) (*cloudformation.Template, err
|
|||||||
}
|
}
|
||||||
definition.ExecutionRoleArn = cloudformation.Ref(taskExecutionRole)
|
definition.ExecutionRoleArn = cloudformation.Ref(taskExecutionRole)
|
||||||
|
|
||||||
taskDefinition := fmt.Sprintf("%sTaskDefinition", service.Name)
|
taskDefinition := fmt.Sprintf("%sTaskDefinition", normalizeResourceName(service.Name))
|
||||||
template.Resources[taskExecutionRole] = &iam.Role{
|
template.Resources[taskExecutionRole] = &iam.Role{
|
||||||
AssumeRolePolicyDocument: assumeRolePolicyDocument,
|
AssumeRolePolicyDocument: assumeRolePolicyDocument,
|
||||||
Policies: rolePolicies,
|
Policies: rolePolicies,
|
||||||
@ -130,7 +131,7 @@ func (c client) Convert(project *compose.Project) (*cloudformation.Template, err
|
|||||||
// FIXME ECS only support HTTP(s) health checks, while Docker only support CMD
|
// FIXME ECS only support HTTP(s) health checks, while Docker only support CMD
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceRegistration := fmt.Sprintf("%sServiceDiscoveryEntry", service.Name)
|
serviceRegistration := fmt.Sprintf("%sServiceDiscoveryEntry", normalizeResourceName(service.Name))
|
||||||
records := []cloudmap.Service_DnsRecord{
|
records := []cloudmap.Service_DnsRecord{
|
||||||
{
|
{
|
||||||
TTL: 60,
|
TTL: 60,
|
||||||
@ -166,7 +167,7 @@ func (c client) Convert(project *compose.Project) (*cloudformation.Template, err
|
|||||||
serviceSecurityGroups = append(serviceSecurityGroups, cloudformation.Ref(logicalName))
|
serviceSecurityGroups = append(serviceSecurityGroups, cloudformation.Ref(logicalName))
|
||||||
}
|
}
|
||||||
|
|
||||||
template.Resources[fmt.Sprintf("%sService", service.Name)] = &ecs.Service{
|
template.Resources[fmt.Sprintf("%sService", normalizeResourceName(service.Name))] = &ecs.Service{
|
||||||
Cluster: cluster,
|
Cluster: cluster,
|
||||||
DesiredCount: 1,
|
DesiredCount: 1,
|
||||||
LaunchType: ecsapi.LaunchTypeFargate,
|
LaunchType: ecsapi.LaunchTypeFargate,
|
||||||
@ -193,7 +194,7 @@ func (c client) Convert(project *compose.Project) (*cloudformation.Template, err
|
|||||||
Value: service.Name,
|
Value: service.Name,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
TaskDefinition: cloudformation.Ref(taskDefinition),
|
TaskDefinition: cloudformation.Ref(normalizeResourceName(taskDefinition)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return template, nil
|
return template, nil
|
||||||
@ -236,7 +237,11 @@ func convertNetwork(project *compose.Project, net string, vpc string) (string, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
func networkResourceName(project *compose.Project, network string) string {
|
func networkResourceName(project *compose.Project, network string) string {
|
||||||
return fmt.Sprintf("%s%sNetwork", project.Name, strings.Title(network))
|
return fmt.Sprintf("%s%sNetwork", normalizeResourceName(project.Name), normalizeResourceName(network))
|
||||||
|
}
|
||||||
|
|
||||||
|
func normalizeResourceName(s string) string {
|
||||||
|
return strings.Title(regexp.MustCompile("[^a-zA-Z0-9]+").ReplaceAllString(s, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c client) getPolicy(taskDef *ecs.TaskDefinition) (*PolicyDocument, error) {
|
func (c client) getPolicy(taskDef *ecs.TaskDefinition) (*PolicyDocument, error) {
|
||||||
|
@ -57,7 +57,7 @@ func Convert(project *compose.Project, service types.ServiceConfig) (*ecs.TaskDe
|
|||||||
Options: map[string]string{
|
Options: map[string]string{
|
||||||
"awslogs-region": cloudformation.Ref("AWS::Region"),
|
"awslogs-region": cloudformation.Ref("AWS::Region"),
|
||||||
"awslogs-group": cloudformation.Ref("LogGroup"),
|
"awslogs-group": cloudformation.Ref("LogGroup"),
|
||||||
"awslogs-stream-prefix": service.Name,
|
"awslogs-stream-prefix": project.Name,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Name: service.Name,
|
Name: service.Name,
|
||||||
|
@ -58,27 +58,7 @@
|
|||||||
},
|
},
|
||||||
"Type": "AWS::Logs::LogGroup"
|
"Type": "AWS::Logs::LogGroup"
|
||||||
},
|
},
|
||||||
"TestSimpleConvertDefaultNetwork": {
|
"SimpleService": {
|
||||||
"Properties": {
|
|
||||||
"GroupDescription": "TestSimpleConvert default Security Group",
|
|
||||||
"GroupName": "TestSimpleConvertDefaultNetwork",
|
|
||||||
"Tags": [
|
|
||||||
{
|
|
||||||
"Key": "com.docker.compose.project",
|
|
||||||
"Value": "TestSimpleConvert"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Key": "com.docker.compose.network",
|
|
||||||
"Value": "default"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"VpcId": {
|
|
||||||
"Ref": "ParameterVPCId"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Type": "AWS::EC2::SecurityGroup"
|
|
||||||
},
|
|
||||||
"simpleService": {
|
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"Cluster": {
|
"Cluster": {
|
||||||
"Fn::If": [
|
"Fn::If": [
|
||||||
@ -117,7 +97,7 @@
|
|||||||
{
|
{
|
||||||
"RegistryArn": {
|
"RegistryArn": {
|
||||||
"Fn::GetAtt": [
|
"Fn::GetAtt": [
|
||||||
"simpleServiceDiscoveryEntry",
|
"SimpleServiceDiscoveryEntry",
|
||||||
"Arn"
|
"Arn"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -134,12 +114,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"TaskDefinition": {
|
"TaskDefinition": {
|
||||||
"Ref": "simpleTaskDefinition"
|
"Ref": "SimpleTaskDefinition"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Type": "AWS::ECS::Service"
|
"Type": "AWS::ECS::Service"
|
||||||
},
|
},
|
||||||
"simpleServiceDiscoveryEntry": {
|
"SimpleServiceDiscoveryEntry": {
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"Description": "\"simple\" service discovery entry in Cloud Map",
|
"Description": "\"simple\" service discovery entry in Cloud Map",
|
||||||
"DnsConfig": {
|
"DnsConfig": {
|
||||||
@ -158,7 +138,7 @@
|
|||||||
},
|
},
|
||||||
"Type": "AWS::ServiceDiscovery::Service"
|
"Type": "AWS::ServiceDiscovery::Service"
|
||||||
},
|
},
|
||||||
"simpleTaskDefinition": {
|
"SimpleTaskDefinition": {
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"ContainerDefinitions": [
|
"ContainerDefinitions": [
|
||||||
{
|
{
|
||||||
@ -191,7 +171,7 @@
|
|||||||
"awslogs-region": {
|
"awslogs-region": {
|
||||||
"Ref": "AWS::Region"
|
"Ref": "AWS::Region"
|
||||||
},
|
},
|
||||||
"awslogs-stream-prefix": "simple"
|
"awslogs-stream-prefix": "TestSimpleConvert"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Name": "simple"
|
"Name": "simple"
|
||||||
@ -199,7 +179,7 @@
|
|||||||
],
|
],
|
||||||
"Cpu": "256",
|
"Cpu": "256",
|
||||||
"ExecutionRoleArn": {
|
"ExecutionRoleArn": {
|
||||||
"Ref": "simpleTaskExecutionRole"
|
"Ref": "SimpleTaskExecutionRole"
|
||||||
},
|
},
|
||||||
"Family": "TestSimpleConvert-simple",
|
"Family": "TestSimpleConvert-simple",
|
||||||
"Memory": "512",
|
"Memory": "512",
|
||||||
@ -210,7 +190,7 @@
|
|||||||
},
|
},
|
||||||
"Type": "AWS::ECS::TaskDefinition"
|
"Type": "AWS::ECS::TaskDefinition"
|
||||||
},
|
},
|
||||||
"simpleTaskExecutionRole": {
|
"SimpleTaskExecutionRole": {
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"AssumeRolePolicyDocument": {
|
"AssumeRolePolicyDocument": {
|
||||||
"Statement": [
|
"Statement": [
|
||||||
@ -232,6 +212,26 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"Type": "AWS::IAM::Role"
|
"Type": "AWS::IAM::Role"
|
||||||
|
},
|
||||||
|
"TestSimpleConvertDefaultNetwork": {
|
||||||
|
"Properties": {
|
||||||
|
"GroupDescription": "TestSimpleConvert default Security Group",
|
||||||
|
"GroupName": "TestSimpleConvertDefaultNetwork",
|
||||||
|
"Tags": [
|
||||||
|
{
|
||||||
|
"Key": "com.docker.compose.project",
|
||||||
|
"Value": "TestSimpleConvert"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": "com.docker.compose.network",
|
||||||
|
"Value": "default"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VpcId": {
|
||||||
|
"Ref": "ParameterVPCId"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Type": "AWS::EC2::SecurityGroup"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,27 +58,7 @@
|
|||||||
},
|
},
|
||||||
"Type": "AWS::Logs::LogGroup"
|
"Type": "AWS::Logs::LogGroup"
|
||||||
},
|
},
|
||||||
"TestSimpleWithOverridesDefaultNetwork": {
|
"SimpleService": {
|
||||||
"Properties": {
|
|
||||||
"GroupDescription": "TestSimpleWithOverrides default Security Group",
|
|
||||||
"GroupName": "TestSimpleWithOverridesDefaultNetwork",
|
|
||||||
"Tags": [
|
|
||||||
{
|
|
||||||
"Key": "com.docker.compose.project",
|
|
||||||
"Value": "TestSimpleWithOverrides"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Key": "com.docker.compose.network",
|
|
||||||
"Value": "default"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"VpcId": {
|
|
||||||
"Ref": "ParameterVPCId"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Type": "AWS::EC2::SecurityGroup"
|
|
||||||
},
|
|
||||||
"simpleService": {
|
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"Cluster": {
|
"Cluster": {
|
||||||
"Fn::If": [
|
"Fn::If": [
|
||||||
@ -117,7 +97,7 @@
|
|||||||
{
|
{
|
||||||
"RegistryArn": {
|
"RegistryArn": {
|
||||||
"Fn::GetAtt": [
|
"Fn::GetAtt": [
|
||||||
"simpleServiceDiscoveryEntry",
|
"SimpleServiceDiscoveryEntry",
|
||||||
"Arn"
|
"Arn"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -134,12 +114,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"TaskDefinition": {
|
"TaskDefinition": {
|
||||||
"Ref": "simpleTaskDefinition"
|
"Ref": "SimpleTaskDefinition"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Type": "AWS::ECS::Service"
|
"Type": "AWS::ECS::Service"
|
||||||
},
|
},
|
||||||
"simpleServiceDiscoveryEntry": {
|
"SimpleServiceDiscoveryEntry": {
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"Description": "\"simple\" service discovery entry in Cloud Map",
|
"Description": "\"simple\" service discovery entry in Cloud Map",
|
||||||
"DnsConfig": {
|
"DnsConfig": {
|
||||||
@ -158,7 +138,7 @@
|
|||||||
},
|
},
|
||||||
"Type": "AWS::ServiceDiscovery::Service"
|
"Type": "AWS::ServiceDiscovery::Service"
|
||||||
},
|
},
|
||||||
"simpleTaskDefinition": {
|
"SimpleTaskDefinition": {
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"ContainerDefinitions": [
|
"ContainerDefinitions": [
|
||||||
{
|
{
|
||||||
@ -191,7 +171,7 @@
|
|||||||
"awslogs-region": {
|
"awslogs-region": {
|
||||||
"Ref": "AWS::Region"
|
"Ref": "AWS::Region"
|
||||||
},
|
},
|
||||||
"awslogs-stream-prefix": "simple"
|
"awslogs-stream-prefix": "TestSimpleWithOverrides"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Name": "simple"
|
"Name": "simple"
|
||||||
@ -199,7 +179,7 @@
|
|||||||
],
|
],
|
||||||
"Cpu": "256",
|
"Cpu": "256",
|
||||||
"ExecutionRoleArn": {
|
"ExecutionRoleArn": {
|
||||||
"Ref": "simpleTaskExecutionRole"
|
"Ref": "SimpleTaskExecutionRole"
|
||||||
},
|
},
|
||||||
"Family": "TestSimpleWithOverrides-simple",
|
"Family": "TestSimpleWithOverrides-simple",
|
||||||
"Memory": "512",
|
"Memory": "512",
|
||||||
@ -210,7 +190,7 @@
|
|||||||
},
|
},
|
||||||
"Type": "AWS::ECS::TaskDefinition"
|
"Type": "AWS::ECS::TaskDefinition"
|
||||||
},
|
},
|
||||||
"simpleTaskExecutionRole": {
|
"SimpleTaskExecutionRole": {
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"AssumeRolePolicyDocument": {
|
"AssumeRolePolicyDocument": {
|
||||||
"Statement": [
|
"Statement": [
|
||||||
@ -232,6 +212,26 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"Type": "AWS::IAM::Role"
|
"Type": "AWS::IAM::Role"
|
||||||
|
},
|
||||||
|
"TestSimpleWithOverridesDefaultNetwork": {
|
||||||
|
"Properties": {
|
||||||
|
"GroupDescription": "TestSimpleWithOverrides default Security Group",
|
||||||
|
"GroupName": "TestSimpleWithOverridesDefaultNetwork",
|
||||||
|
"Tags": [
|
||||||
|
{
|
||||||
|
"Key": "com.docker.compose.project",
|
||||||
|
"Value": "TestSimpleWithOverrides"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Key": "com.docker.compose.network",
|
||||||
|
"Value": "default"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"VpcId": {
|
||||||
|
"Ref": "ParameterVPCId"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Type": "AWS::EC2::SecurityGroup"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user