mirror of https://github.com/docker/compose.git
testcase to check service mapping
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
2bc1b710f2
commit
c0c31de0c8
|
@ -43,6 +43,19 @@ func (c *FargateCompatibilityChecker) CheckPortsPublished(p *types.ServicePortCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FargateCompatibilityChecker) CheckCapAdd(service *types.ServiceConfig) {
|
||||||
|
add := []string{}
|
||||||
|
for _, cap := range service.CapAdd {
|
||||||
|
switch cap {
|
||||||
|
case "SYS_PTRACE":
|
||||||
|
add = append(add, cap)
|
||||||
|
default:
|
||||||
|
c.Error("service.cap_add = %s", cap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
service.CapAdd = add
|
||||||
|
}
|
||||||
|
|
||||||
// Convert a compose project into a CloudFormation template
|
// Convert a compose project into a CloudFormation template
|
||||||
func (b Backend) Convert(project *types.Project) (*cloudformation.Template, error) {
|
func (b Backend) Convert(project *types.Project) (*cloudformation.Template, error) {
|
||||||
var checker compatibility.Checker = &FargateCompatibilityChecker{
|
var checker compatibility.Checker = &FargateCompatibilityChecker{
|
||||||
|
@ -50,9 +63,11 @@ func (b Backend) Convert(project *types.Project) (*cloudformation.Template, erro
|
||||||
Supported: []string{
|
Supported: []string{
|
||||||
"services.command",
|
"services.command",
|
||||||
"services.container_name",
|
"services.container_name",
|
||||||
|
"services.cap_drop",
|
||||||
"services.depends_on",
|
"services.depends_on",
|
||||||
"services.entrypoint",
|
"services.entrypoint",
|
||||||
"services.environment",
|
"services.environment",
|
||||||
|
"services.init",
|
||||||
"services.healthcheck",
|
"services.healthcheck",
|
||||||
"services.healthcheck.interval",
|
"services.healthcheck.interval",
|
||||||
"services.healthcheck.start_period",
|
"services.healthcheck.start_period",
|
||||||
|
|
|
@ -5,16 +5,16 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/ecs-plugin/pkg/compose"
|
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/service/elbv2"
|
"github.com/aws/aws-sdk-go/service/elbv2"
|
||||||
"github.com/awslabs/goformation/v4/cloudformation"
|
"github.com/awslabs/goformation/v4/cloudformation"
|
||||||
"github.com/awslabs/goformation/v4/cloudformation/ec2"
|
"github.com/awslabs/goformation/v4/cloudformation/ec2"
|
||||||
|
"github.com/awslabs/goformation/v4/cloudformation/ecs"
|
||||||
"github.com/awslabs/goformation/v4/cloudformation/elasticloadbalancingv2"
|
"github.com/awslabs/goformation/v4/cloudformation/elasticloadbalancingv2"
|
||||||
"github.com/awslabs/goformation/v4/cloudformation/iam"
|
"github.com/awslabs/goformation/v4/cloudformation/iam"
|
||||||
"github.com/compose-spec/compose-go/cli"
|
"github.com/compose-spec/compose-go/cli"
|
||||||
"github.com/compose-spec/compose-go/loader"
|
"github.com/compose-spec/compose-go/loader"
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
|
"github.com/docker/ecs-plugin/pkg/compose"
|
||||||
"gotest.tools/v3/assert"
|
"gotest.tools/v3/assert"
|
||||||
"gotest.tools/v3/golden"
|
"gotest.tools/v3/golden"
|
||||||
)
|
)
|
||||||
|
@ -108,6 +108,46 @@ services:
|
||||||
assert.Check(t, lb.Type == elbv2.LoadBalancerTypeEnumNetwork)
|
assert.Check(t, lb.Type == elbv2.LoadBalancerTypeEnumNetwork)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServiceMapping(t *testing.T) {
|
||||||
|
template := convertYaml(t, `
|
||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
test:
|
||||||
|
image: "image"
|
||||||
|
command: "command"
|
||||||
|
entrypoint: "entrypoint"
|
||||||
|
environment:
|
||||||
|
- "FOO=BAR"
|
||||||
|
cap_add:
|
||||||
|
- SYS_PTRACE
|
||||||
|
cap_drop:
|
||||||
|
- SYSLOG
|
||||||
|
init: true
|
||||||
|
user: "user"
|
||||||
|
working_dir: "working_dir"
|
||||||
|
`)
|
||||||
|
def := template.Resources["TestTaskDefinition"].(*ecs.TaskDefinition)
|
||||||
|
container := def.ContainerDefinitions[0]
|
||||||
|
assert.Equal(t, container.Image, "docker.io/library/image")
|
||||||
|
assert.Equal(t, container.Command[0], "command")
|
||||||
|
assert.Equal(t, container.EntryPoint[0], "entrypoint")
|
||||||
|
assert.Equal(t, get(container.Environment, "FOO"), "BAR")
|
||||||
|
assert.Check(t, container.LinuxParameters.InitProcessEnabled)
|
||||||
|
assert.Equal(t, container.LinuxParameters.Capabilities.Add[0], "SYS_PTRACE")
|
||||||
|
assert.Equal(t, container.LinuxParameters.Capabilities.Drop[0], "SYSLOG")
|
||||||
|
assert.Equal(t, container.User, "user")
|
||||||
|
assert.Equal(t, container.WorkingDirectory, "working_dir")
|
||||||
|
}
|
||||||
|
|
||||||
|
func get(l []ecs.TaskDefinition_KeyValuePair, name string) string {
|
||||||
|
for _, e := range l {
|
||||||
|
if e.Name == name {
|
||||||
|
return e.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func TestResourcesHaveProjectTagSet(t *testing.T) {
|
func TestResourcesHaveProjectTagSet(t *testing.T) {
|
||||||
template := convertYaml(t, `
|
template := convertYaml(t, `
|
||||||
version: "3"
|
version: "3"
|
||||||
|
|
Loading…
Reference in New Issue