Services

Jeff Bachtel edited this page Sep 15, 2018 · 16 revisions

Services

Services are first pushed to an ECR repository and then deployed to a specific environment. Each service is a CloudFormation stack consisting of the following resources:

  • Task Definition – An ECS task definition referencing the image and tag in the ECR repo.
  • Service - An ECS service referencing the Task Definition.
  • Target Group - An ALB target group for the Service to reference and register containers in.
  • Listener Rule - A rule in the ALB listener from the environment to route specific URLs to the target group.

Service Diagram

Configuration

---

### Define the service for this repo
service:
  name: my-service                   # The unique name of the service (default: the name of the directory that mu.yml was in)
  desiredCount: 4                    # The desired number of tasks to run for the service (default: 2)
  dockerfile: ./Dockerfile           # The relative path to the Dockerfile to build images (default: ./Dockerfile)
  imageRepository: tutum/hello-world # The repository to push images to and deploy services from.  Leave unset to have mu manage an ECR repository (default: none)
  port: 80                           # The port to expose from the container (default: 8080)
  protocol: http                     # The protocol for the port exposed from the container (default: http)
  healthEndpoint: /health            # The endpoint inside the container to determine if the task is healthy (default: /health)
  cpu: 20                            # The number of CPU units to allocate to each task (default: 10)
  memory: 400                        # The amount of memory in MiB to allocate to each task (default: 300)
  networkMode: bridge                # The networking mode for the task: none, bridge, host, or awsvpc (default: bridge)
  targetCPUUtilization: 80           # The target CPU utilization for autoscaling (default: 75)
  minSize: 1                         # The minimum number of services for autoscaling (default: 1)
  maxSize: 4                         # The maximum number of services for autoscaling (default: 2)
  deploymentStrategy: blue_green     # The strategy for deploying new images: blue_green, rolling, replace (default: blue_green)

  # The paths to match on in the ALB and route to this service.  Leave blank to not create an ALB target group for this service (default: none)
  pathPatterns:
    - /bananas
    - /apples

  # The hostnames to match on in the ALB and route to this service.  Leave blank to not create an ALB target group for this service (default: none)
  hostPatterns:
    - my-service.*

  # The priority for resolving the pathPatterns from the ALB (between 1 and 50000)
  priority: 25

  # Environment variables
  environment:
    DB_TYPE: mysql                  # Define an environment variable for all environments by have a string for value
    DB_URL:                         # Define an different value per environment by have a map for value
        acpt:  10.0.0.1:3306
        prod: 10.0.100.5:3306

  ### Custom tags for the stacks
  tags:
    FOO: bar                    # Create a tag with key `FOO` and value `bar`
    HELLO: world                # Create a tag with key `HELLO` and value `world`

Commands

# Show details about a specific service (Which versions in which environments, pipeline status)
> mu service show [<service_name>]

# Build docker image and push to ECR
> mu service push

# Deploy the service to an environment
> mu service deploy <environment_name>

# View the logs for a service in a given environment
> mu pipeline logs [--follow] [-s <service_name>] <environment_name> [filter]

# Undeploy the service from an environment
> mu service undeploy <environment_name> [<service_name>]

# Execute commands on the ECS cluster
> mu service exec [-s <service_name>] <environment_name> <command>
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.