Add first compose to cloudformation conversion tests

Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Guillaume Lours 2020-05-13 15:32:24 +02:00 committed by Nicolas De Loof
parent 3e5b118f26
commit 4bbe3f1589
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
5 changed files with 385 additions and 0 deletions

View File

@ -0,0 +1,49 @@
package tests
import (
"testing"
"gotest.tools/v3/fs"
"gotest.tools/v3/golden"
"gotest.tools/v3/icmd"
)
const (
composeFileName = "compose.yaml"
)
func TestSimpleConvert(t *testing.T) {
cmd, cleanup := dockerCli.createTestCmd()
defer cleanup()
composeYAML := golden.Get(t, "input/simple-single-service.yaml")
tmpDir := fs.NewDir(t, t.Name(),
fs.WithFile(composeFileName, "", fs.WithBytes(composeYAML)),
)
defer tmpDir.Remove()
cmd.Command = dockerCli.Command("ecs", "compose", "--file="+tmpDir.Join(composeFileName), "--project-name", t.Name(), "convert")
result := icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined()
expected := "simple/simple-cloudformation-conversion.golden"
golden.Assert(t, result, expected)
}
func TestSimpleWithOverrides(t *testing.T) {
cmd, cleanup := dockerCli.createTestCmd()
defer cleanup()
composeYAML := golden.Get(t, "input/simple-single-service.yaml")
overriddenComposeYAML := golden.Get(t, "input/simple-single-service-with-overrides.yaml")
tmpDir := fs.NewDir(t, t.Name(),
fs.WithFile(composeFileName, "", fs.WithBytes(composeYAML)),
fs.WithFile("overriddenService.yaml", "", fs.WithBytes(overriddenComposeYAML)),
)
defer tmpDir.Remove()
cmd.Command = dockerCli.Command("ecs", "compose", "--file="+tmpDir.Join(composeFileName), "--file",
tmpDir.Join("overriddenService.yaml"), "--project-name", t.Name(), "convert")
result := icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined()
expected := "simple/simple-cloudformation-with-overrides-conversion.golden"
golden.Assert(t, result, expected)
}

View File

@ -0,0 +1,4 @@
version: "3"
services:
simple:
image: haproxy

View File

@ -0,0 +1,4 @@
version: "3"
services:
simple:
image: nginx

View File

@ -0,0 +1,164 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"Subnet1Id": {
"Description": "SubnetId,for Availability Zone 1 in the region in your VPC",
"Type": "AWS::EC2::Subnet::Id"
},
"Subnet2Id": {
"Description": "SubnetId,for Availability Zone 1 in the region in your VPC",
"Type": "AWS::EC2::Subnet::Id"
},
"VPCId": {
"Description": "ID of the VPC",
"Type": "AWS::EC2::VPC::Id"
}
},
"Resources": {
"CloudMap": {
"Properties": {
"Description": "Service Map for Docker Compose project TestSimpleConvert",
"Name": "TestSimpleConvert.local",
"Vpc": {
"Ref": "VPCId"
}
},
"Type": "AWS::ServiceDiscovery::PrivateDnsNamespace"
},
"LogGroup": {
"Properties": {
"LogGroupName": "/docker-compose/TestSimpleConvert"
},
"Type": "AWS::Logs::LogGroup"
},
"simpleService": {
"Properties": {
"Cluster": "TestCluster",
"DesiredCount": 1,
"LaunchType": "FARGATE",
"NetworkConfiguration": {
"AwsvpcConfiguration": {
"AssignPublicIp": "ENABLED",
"Subnets": [
{
"Ref": "Subnet1Id"
},
{
"Ref": "Subnet2Id"
}
]
}
},
"SchedulingStrategy": "REPLICA",
"ServiceName": "simple",
"ServiceRegistries": [
{
"RegistryArn": {
"Fn::GetAtt": [
"simpleServiceDiscoveryEntry",
"Arn"
]
}
}
],
"TaskDefinition": {
"Ref": "simpleTaskDefinition"
}
},
"Type": "AWS::ECS::Service"
},
"simpleServiceDiscoveryEntry": {
"Properties": {
"Description": "\"simple\" service discovery entry in Cloud Map",
"DnsConfig": {
"DnsRecords": [
{
"TTL": 300,
"Type": "A"
}
],
"RoutingPolicy": "MULTIVALUE"
},
"Name": "simple",
"NamespaceId": {
"Ref": "CloudMap"
}
},
"Type": "AWS::ServiceDiscovery::Service"
},
"simpleTaskDefinition": {
"Properties": {
"ContainerDefinitions": [
{
"Environment": [
{
"Name": "LOCALDOMAIN",
"Value": {
"Fn::Join": [
"",
[
{
"Ref": "AWS::Region"
},
".compute.internal",
" TestSimpleConvert.local"
]
]
}
}
],
"Essential": true,
"Image": "docker.io/library/nginx",
"LinuxParameters": {},
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
"awslogs-group": {
"Ref": "LogGroup"
},
"awslogs-region": {
"Ref": "AWS::Region"
},
"awslogs-stream-prefix": "simple"
}
},
"Name": "simple"
}
],
"Cpu": "256",
"ExecutionRoleArn": {
"Ref": "simpleTaskExecutionRole"
},
"Family": "TestSimpleConvert-simple",
"Memory": "512",
"NetworkMode": "awsvpc",
"RequiresCompatibilities": [
"FARGATE"
]
},
"Type": "AWS::ECS::TaskDefinition"
},
"simpleTaskExecutionRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
]
},
"Type": "AWS::IAM::Role"
}
}
}

View File

@ -0,0 +1,164 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"Subnet1Id": {
"Description": "SubnetId,for Availability Zone 1 in the region in your VPC",
"Type": "AWS::EC2::Subnet::Id"
},
"Subnet2Id": {
"Description": "SubnetId,for Availability Zone 1 in the region in your VPC",
"Type": "AWS::EC2::Subnet::Id"
},
"VPCId": {
"Description": "ID of the VPC",
"Type": "AWS::EC2::VPC::Id"
}
},
"Resources": {
"CloudMap": {
"Properties": {
"Description": "Service Map for Docker Compose project TestSimpleWithOverrides",
"Name": "TestSimpleWithOverrides.local",
"Vpc": {
"Ref": "VPCId"
}
},
"Type": "AWS::ServiceDiscovery::PrivateDnsNamespace"
},
"LogGroup": {
"Properties": {
"LogGroupName": "/docker-compose/TestSimpleWithOverrides"
},
"Type": "AWS::Logs::LogGroup"
},
"simpleService": {
"Properties": {
"Cluster": "TestCluster",
"DesiredCount": 1,
"LaunchType": "FARGATE",
"NetworkConfiguration": {
"AwsvpcConfiguration": {
"AssignPublicIp": "ENABLED",
"Subnets": [
{
"Ref": "Subnet1Id"
},
{
"Ref": "Subnet2Id"
}
]
}
},
"SchedulingStrategy": "REPLICA",
"ServiceName": "simple",
"ServiceRegistries": [
{
"RegistryArn": {
"Fn::GetAtt": [
"simpleServiceDiscoveryEntry",
"Arn"
]
}
}
],
"TaskDefinition": {
"Ref": "simpleTaskDefinition"
}
},
"Type": "AWS::ECS::Service"
},
"simpleServiceDiscoveryEntry": {
"Properties": {
"Description": "\"simple\" service discovery entry in Cloud Map",
"DnsConfig": {
"DnsRecords": [
{
"TTL": 300,
"Type": "A"
}
],
"RoutingPolicy": "MULTIVALUE"
},
"Name": "simple",
"NamespaceId": {
"Ref": "CloudMap"
}
},
"Type": "AWS::ServiceDiscovery::Service"
},
"simpleTaskDefinition": {
"Properties": {
"ContainerDefinitions": [
{
"Environment": [
{
"Name": "LOCALDOMAIN",
"Value": {
"Fn::Join": [
"",
[
{
"Ref": "AWS::Region"
},
".compute.internal",
" TestSimpleWithOverrides.local"
]
]
}
}
],
"Essential": true,
"Image": "docker.io/library/haproxy",
"LinuxParameters": {},
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
"awslogs-group": {
"Ref": "LogGroup"
},
"awslogs-region": {
"Ref": "AWS::Region"
},
"awslogs-stream-prefix": "simple"
}
},
"Name": "simple"
}
],
"Cpu": "256",
"ExecutionRoleArn": {
"Ref": "simpleTaskExecutionRole"
},
"Family": "TestSimpleWithOverrides-simple",
"Memory": "512",
"NetworkMode": "awsvpc",
"RequiresCompatibilities": [
"FARGATE"
]
},
"Type": "AWS::ECS::TaskDefinition"
},
"simpleTaskExecutionRole": {
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": [
{
"Action": [
"sts:AssumeRole"
],
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
}
}
],
"Version": "2012-10-17"
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy"
]
},
"Type": "AWS::IAM::Role"
}
}
}