4

My project is a flask project using docker-compose. And source code is in GitLab. I wanna auto-deploy to ECS with GitLab CI. Also, docker images are in ECR. But I faced following error.

Subnet created: subnet-0ffc4936b92c
Subnet created: subnet-0177c849eeca
Cluster creation succeeded.
WARN[0000] Skipping unsupported YAML option for service...  option name=build service name=proxy
WARN[0000] Skipping unsupported YAML option for service...  option name=container_name service name=proxy
WARN[0000] Skipping unsupported YAML option for service...  option name=restart service name=proxy
WARN[0000] Skipping unsupported YAML option for service...  option name=build service name=api
WARN[0000] Skipping unsupported YAML option for service...  option name=container_name service name=api
WARN[0000] Skipping unsupported YAML option for service...  option name=restart service name=api
WARN[0000] Skipping unsupported YAML option for service...  option name=build service name=worker
WARN[0000] Skipping unsupported YAML option for service...  option name=container_name service name=worker
WARN[0000] Skipping unsupported YAML option for service...  option name=restart service name=worker
INFO[0001] Using ECS task definition                     TaskDefinition="backend:12"
WARN[0001] No log groups to create; no containers use 'awslogs' 
ERRO[0001] Error running tasks                           error="InvalidParameterException: No Container Instances were found in your cluster." task definition=0xc0005a5ae0
FATA[0001] InvalidParameterException: No Container Instances were found in your cluster. 

docker-compose.yml

version: "3.0"

services:
  proxy:
    container_name: rs-proxy
    image: ${REPOSITORY_URL}/proxy
    build:
      context: proxy/.
      dockerfile: Dockerfile
    ports:
      - 80:80
    restart: on-failure

  api:
    container_name: rs-api
    image: ${REPOSITORY_URL}/api
    build:
      context: api/.
      dockerfile: Dockerfile.prod
    restart: on-failure
    volumes:
      - ./api/migrations:/app/migrations

  worker:
    container_name: rs-worker
    image: ${REPOSITORY_URL}/worker
    build:
      context: .
      dockerfile: ./worker/Dockerfile
    restart: on-failure

.gitlab-ci.yml

image: tiangolo/docker-with-compose

variables:
  PROJECT_NAME: test-project
  CONFIG_NAME: $PROJECT_NAME
  PROFILE_NAME: $PROJECT_NAME-profile
  AWS_ECR_URL: $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
  REPOSITORY_URL: $AWS_ECR_URL/$PROJECT_NAME

before_script:
  - export REPOSITORY_URL=$REPOSITORY_URL
  - apk add --no-cache curl jq python3 py-pip
  - apk add --update curl
  - pip install awscli
  - curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
  - chmod +x /usr/local/bin/ecs-cli
  - echo "Logging in AWS..."
  - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ECR_URL

stages:
  - build
  - deploy

build:
  stage: build
  script:
    - echo "Building image..."
    - docker-compose -f docker-compose.yml build
    - echo "Pushing image..."
    - docker push ${REPOSITORY_URL}/proxy:latest
    - docker push ${REPOSITORY_URL}/api:latest
    - docker push ${REPOSITORY_URL}/worker:latest
  only:
    - master

deploy:
  stage: deploy
  script:
    - echo "Configuring AWS ECS..."
    - ecs-cli configure --cluster $CONFIG_NAME --default-launch-type EC2 --config-name $CONFIG_NAME --region $AWS_DEFAULT_REGION
    - ecs-cli configure profile --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY --profile-name $PROFILE_NAME
    - echo "Updating the service..."
    - ecs-cli up --capability-iam --size 1 --instance-type t2.medium --cluster-config $CONFIG_NAME --ecs-profile $PROFILE_NAME --force
    - ecs-cli compose --file ./docker-compose.prod.yml up --create-log-groups --cluster-config $CONFIG_NAME --ecs-profile $PROFILE_NAME --force-update
  only:
    - master

ecs-params.yml

version: 1
task_definition:
  task_execution_role:
  services:
    proxy:
      essential: true
    api:
      essential: true
    worker:
      essential: true

project structure

I've attached configuration files. I think, I missed some AWS configurations, but I can't find mistakes. How can I fix it?

0 Answers0