2020-08-18 11:38:23 +02:00
|
|
|
/*
|
2020-09-22 12:13:00 +02:00
|
|
|
Copyright 2020 Docker Compose CLI authors
|
2020-08-18 11:38:23 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-08-17 17:48:52 +02:00
|
|
|
package ecs
|
2020-07-09 10:49:21 +02:00
|
|
|
|
|
|
|
import (
|
2020-09-24 10:28:32 +02:00
|
|
|
"fmt"
|
|
|
|
|
2020-07-09 10:49:21 +02:00
|
|
|
"github.com/compose-spec/compose-go/compatibility"
|
2020-09-24 10:28:32 +02:00
|
|
|
"github.com/compose-spec/compose-go/errdefs"
|
2020-07-09 10:49:21 +02:00
|
|
|
"github.com/compose-spec/compose-go/types"
|
2020-09-24 10:28:32 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-07-09 10:49:21 +02:00
|
|
|
)
|
|
|
|
|
2020-09-24 10:28:32 +02:00
|
|
|
func (b *ecsAPIService) checkCompatibility(project *types.Project) error {
|
|
|
|
var checker compatibility.Checker = &fargateCompatibilityChecker{
|
2020-11-10 08:38:46 +01:00
|
|
|
AllowList: compatibility.AllowList{
|
2020-09-24 10:28:32 +02:00
|
|
|
Supported: compatibleComposeAttributes,
|
|
|
|
},
|
2020-11-10 08:38:46 +01:00
|
|
|
projet: project,
|
2020-09-24 10:28:32 +02:00
|
|
|
}
|
|
|
|
compatibility.Check(project, checker)
|
|
|
|
for _, err := range checker.Errors() {
|
|
|
|
if errdefs.IsIncompatibleError(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logrus.Warn(err.Error())
|
|
|
|
}
|
|
|
|
if !compatibility.IsCompatible(checker) {
|
|
|
|
return fmt.Errorf("compose file is incompatible with Amazon ECS")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
type fargateCompatibilityChecker struct {
|
2020-07-09 10:49:21 +02:00
|
|
|
compatibility.AllowList
|
2020-11-10 08:38:46 +01:00
|
|
|
projet *types.Project
|
2020-07-09 10:49:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var compatibleComposeAttributes = []string{
|
|
|
|
"services.command",
|
|
|
|
"services.container_name",
|
|
|
|
"services.cap_drop",
|
|
|
|
"services.depends_on",
|
2020-07-10 09:35:32 +02:00
|
|
|
"services.deploy",
|
2020-09-29 15:11:31 +02:00
|
|
|
"services.deploy.placement",
|
|
|
|
"services.deploy.placement.constraints",
|
2020-07-10 09:35:32 +02:00
|
|
|
"services.deploy.replicas",
|
2020-07-23 14:37:05 +02:00
|
|
|
"services.deploy.resources.limits",
|
|
|
|
"services.deploy.resources.limits.cpus",
|
|
|
|
"services.deploy.resources.limits.memory",
|
|
|
|
"services.deploy.resources.reservations",
|
|
|
|
"services.deploy.resources.reservations.cpus",
|
|
|
|
"services.deploy.resources.reservations.memory",
|
2020-11-16 14:09:12 +01:00
|
|
|
"services.deploy.resources.reservations.devices",
|
|
|
|
"services.deploy.resources.reservations.devices.count",
|
2020-09-17 10:42:19 +02:00
|
|
|
"services.deploy.resources.reservations.generic_resources",
|
|
|
|
"services.deploy.resources.reservations.generic_resources.discrete_resource_spec",
|
2020-08-11 11:19:58 +02:00
|
|
|
"services.deploy.update_config",
|
|
|
|
"services.deploy.update_config.parallelism",
|
2020-07-09 10:49:21 +02:00
|
|
|
"services.entrypoint",
|
|
|
|
"services.environment",
|
2020-08-11 15:48:12 +02:00
|
|
|
"services.env_file",
|
2020-07-09 10:49:21 +02:00
|
|
|
"services.healthcheck",
|
|
|
|
"services.healthcheck.interval",
|
2020-08-10 08:27:57 +02:00
|
|
|
"services.healthcheck.retries",
|
2020-07-09 10:49:21 +02:00
|
|
|
"services.healthcheck.start_period",
|
|
|
|
"services.healthcheck.test",
|
|
|
|
"services.healthcheck.timeout",
|
2020-08-11 15:48:12 +02:00
|
|
|
"services.image",
|
|
|
|
"services.init",
|
|
|
|
"services.logging",
|
|
|
|
"services.logging.options",
|
2020-07-09 10:49:21 +02:00
|
|
|
"services.networks",
|
|
|
|
"services.ports",
|
|
|
|
"services.ports.mode",
|
|
|
|
"services.ports.target",
|
|
|
|
"services.ports.protocol",
|
2020-08-04 18:04:06 +02:00
|
|
|
"services.secrets",
|
|
|
|
"services.secrets.source",
|
|
|
|
"services.secrets.target",
|
2020-07-09 10:49:21 +02:00
|
|
|
"services.user",
|
2020-09-08 10:33:06 +02:00
|
|
|
"services.volumes",
|
|
|
|
"services.volumes.read_only",
|
|
|
|
"services.volumes.target",
|
2020-07-09 10:49:21 +02:00
|
|
|
"services.working_dir",
|
2020-08-04 18:04:06 +02:00
|
|
|
"secrets.external",
|
|
|
|
"secrets.name",
|
|
|
|
"secrets.file",
|
2020-09-08 10:33:06 +02:00
|
|
|
"volumes",
|
|
|
|
"volumes.external",
|
2020-10-09 08:18:39 +02:00
|
|
|
"volumes.name",
|
2020-10-14 11:04:50 +02:00
|
|
|
"volumes.driver_opts",
|
2020-10-12 16:21:48 +02:00
|
|
|
"networks.external",
|
2020-10-09 08:18:39 +02:00
|
|
|
"networks.name",
|
2020-07-09 10:49:21 +02:00
|
|
|
}
|
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
func (c *fargateCompatibilityChecker) CheckImage(service *types.ServiceConfig) {
|
2020-07-09 10:49:21 +02:00
|
|
|
if service.Image == "" {
|
|
|
|
c.Incompatible("service %s doesn't define a Docker image to run", service.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
func (c *fargateCompatibilityChecker) CheckPortsPublished(p *types.ServicePortConfig) {
|
2020-07-09 10:49:21 +02:00
|
|
|
if p.Published == 0 {
|
|
|
|
p.Published = p.Target
|
|
|
|
}
|
|
|
|
if p.Published != p.Target {
|
|
|
|
c.Incompatible("published port can't be set to a distinct value than container port")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-10 08:38:46 +01:00
|
|
|
func (c *fargateCompatibilityChecker) CheckVolumesSource(config *types.ServiceVolumeConfig) {
|
|
|
|
if config.Type == types.VolumeTypeBind {
|
|
|
|
c.Incompatible("ECS Fargate does not support bind mounts from host")
|
|
|
|
}
|
|
|
|
if config.Type == types.VolumeTypeTmpfs {
|
|
|
|
c.Incompatible("ECS Fargate does not support tmpfs")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
func (c *fargateCompatibilityChecker) CheckCapAdd(service *types.ServiceConfig) {
|
2020-07-09 10:49:21 +02:00
|
|
|
add := []string{}
|
|
|
|
for _, cap := range service.CapAdd {
|
|
|
|
switch cap {
|
|
|
|
case "SYS_PTRACE":
|
|
|
|
add = append(add, cap)
|
|
|
|
default:
|
|
|
|
c.Incompatible("ECS doesn't allow to add capability %s", cap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
service.CapAdd = add
|
|
|
|
}
|
2020-08-11 15:48:12 +02:00
|
|
|
|
2020-08-18 16:56:42 +02:00
|
|
|
func (c *fargateCompatibilityChecker) CheckLoggingDriver(config *types.LoggingConfig) {
|
2020-08-11 15:48:12 +02:00
|
|
|
if config.Driver != "" && config.Driver != "awslogs" {
|
|
|
|
c.Unsupported("services.logging.driver %s is not supported", config.Driver)
|
|
|
|
}
|
|
|
|
}
|
2020-10-14 08:47:03 +02:00
|
|
|
|
|
|
|
func (c *fargateCompatibilityChecker) CheckUlimits(service *types.ServiceConfig) {
|
|
|
|
for k := range service.Ulimits {
|
|
|
|
if k != "nofile" {
|
|
|
|
c.Unsupported("services.ulimits.%s is not supported by Fargate", k)
|
|
|
|
delete(service.Ulimits, k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-16 14:09:12 +01:00
|
|
|
|
|
|
|
func (c *fargateCompatibilityChecker) CheckDeployResourcesDevicesCapabilities(s string, r types.DeviceRequest) {
|
|
|
|
for _, cap := range r.Capabilities {
|
|
|
|
if cap != "gpu" {
|
|
|
|
c.Unsupported("services.deploy.resources.%s.devices.capabilities = %s", s, cap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|