0

I'm having an issue with a fargate one off task , it's meant to run database migration and then stop but it keeps stuck in running status

this is the task definition :

resource "aws_ecs_task_definition" "migrate" {
  family                   = "${var.project_name}-${var.environment}-migrate"
  network_mode             = "awsvpc"
  requires_compatibilities = ["FARGATE"]
  cpu                      = 512
  memory                   = 1024
  execution_role_arn       = aws_iam_role.ecs_task_execution_role.arn
  task_role_arn            = aws_iam_role.ecs_task_execution_role.arn

  container_definitions = <<DEFINITION
  [
   {
      "name": "${var.project_name}-migrate",
      "image": "${var.repository_url}:latest",
      "cpu": 512,
      "memory": 1024,
      "command": [
        "/bin/sh",
        "-c",
        "python manage.py migrate --no-input"
      ],
      "mountPoints": [],
      "environment": [
        {
          "name": "DJANGO_SETTINGS_MODULE",
          "value": "****"
        },
        {
          "name": "DB_HOST",
          "value": "****"
        },
        {
          "name": "DD_API_KEY",
          "value": "****"
        }
      ],
      "secrets": [
        {
          "name": "SECRETS",
          "valueFrom": "*****"
        }
      ],
      "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
        "awslogs-group": "****",
        "awslogs-region": "****",
        "awslogs-stream-prefix": "******"
      }
      },
      "volumesFrom": []
    }

  ]
DEFINITION
}

and this is how i call it from github actions

aws ecs run-task --launch-type FARGATE --cluster cs-name  --task-definition $MIGRATE_TASK_ARN --network-configuration "awsvpcConfiguration={subnets=[${{ secrets.MIGRATE_TASK_SUBNET_IDA }}, ${{ secrets.MIGRATE_TASK_SUBNET_IDB }}],securityGroups=${{ secrets.MIGRATE_TASK_SECURITY_GROUP_ID }}}"

any idea what's wrong ?

soukaina
  • 11
  • 1
  • 4

1 Answers1

0

I guess it depends what the command does. When the main process in the container exits the containers stops and the task will stop. One way to check the behavior would be to run something like ls (or similar) and see what happens. I am wondering if the problem is due to the fact you are calling the shell and then the python program and when the program exits the shell keeps the container alive? Have you tried just running the python program?

"command": "python manage.py migrate --no-input",
mreferre
  • 5,464
  • 3
  • 22
  • 29
  • yes already tried it, although i can see in the logs that gunicorn is started, which shouldn't be the case I guess – soukaina Jun 20 '21 at 22:42