// populateContext sets the required CLI arguments to the context func (projectFactory projectFactory) populateContext(ecsContext *ecscompose.Context, cliContext *cli.Context) error { // populate CLI context populate(ecsContext, cliContext) ecsContext.CLIContext = cliContext // reads and sets the parameters (required to create ECS Service Client) from the cli context to ecs context rdwr, err := config.NewReadWriter() if err != nil { utils.LogError(err, "Error loading config") return err } params, err := config.NewCliParams(cliContext, rdwr) if err != nil { utils.LogError(err, "Unable to create an instance of ECSParams given the cli context") return err } ecsContext.ECSParams = params // populate libcompose context if err = projectFactory.populateLibcomposeContext(ecsContext); err != nil { return err } return nil }
// loadProject opens the project by loading configs func (projectFactory projectFactory) loadProject(project ecscompose.Project) error { err := project.Parse() if err != nil { utils.LogError(err, "Unable to open ECS Compose Project") } return err }
// getOrCreateTaskDefinition gets the task definition from cache if present, else // creates it in ECS and persists in a local cache. It also sets the latest // taskDefinition to the current instance of task func getOrCreateTaskDefinition(entity ProjectEntity) (*ecs.TaskDefinition, error) { taskDefinition := entity.TaskDefinition() log.WithFields(log.Fields{ "TaskDefinition": taskDefinition, }).Debug("Finding task definition in cache or creating if needed") resp, err := entity.Context().ECSClient.RegisterTaskDefinitionIfNeeded(&ecs.RegisterTaskDefinitionInput{ Family: taskDefinition.Family, ContainerDefinitions: taskDefinition.ContainerDefinitions, Volumes: taskDefinition.Volumes, }, entity.TaskDefinitionCache()) if err != nil { composeutils.LogError(err, "Create task definition failed") return nil, err } log.WithFields(log.Fields{ "TaskDefinition": getIdFromArn(resp.TaskDefinitionArn), }).Info("Using ECS task definition") // update the taskdefinition of the entity with the newly received TaskDefinition entity.SetTaskDefinition(resp) return resp, nil }
// open populates the context fields and creates an ECS Client func (context *Context) open() error { // perform libcomposeContext open which loads the compose file and determines projectname err := context.Context.Open() if err != nil { utils.LogError(err, "Unable to open ECS context") return err } context.ECSClient = ecsclient.NewECSClient() context.ECSClient.Initialize(context.ECSParams) context.EC2Client = ec2client.NewEC2Client(context.ECSParams) return nil }