Сборка кода в AWS сине-зеленом развертывании ECS возвращает ошибку при выполнении команды: docker build -t: latest - PullRequest
0 голосов
/ 18 июня 2020

У меня есть проект python 3, который я хотел бы развернуть, используя AWS Blue/Green deployment.

У меня есть buildspec.yml и appspec.yaml в root проекта. Также есть папка, в которой находятся файлы терраформ. Эта папка имеет 4 уровня папок, пока не дойдет до файла json с именем my-task.json.

Мой buildspec.yml выглядит так:

version: 0.2

phases:
  install:
    commands:
      - apt-get update
      - apt install jq
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region eu-central-1 --no-include-email)
      - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...
      - echo codebuild resolved source is...
      - echo $CODEBUILD_RESOLVED_SOURCE_VERSION
      - echo Imaget tag is...
      - echo $IMAGE_TAG
      - docker build -t 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest .
      - docker tag 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:$IMAGE_TAG
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker images...
      - docker push 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest
      - aws ecs describe-task-definition --task-definition green-blue-ecs-example | jq '.taskDefinition' > taskdef.json
      - envsubst < appspec_template.yaml > appspec.yaml
artifacts:
  files:
    - appspec.yaml
    - taskdef.json

Мой appspec.yaml называется appspec_template.yaml выглядит :

version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: "arn:aws:ecs:eu-west-1:30900:task-definition/my-task-definition:19"
        LoadBalancerInfo:
          ContainerName: "my-container"
          ContainerPort: "8081"
        PlatformVersion: "LATEST"
        NetworkConfiguration:
          AwsvpcConfiguration:
            Subnets: ["subnet-0903eda"]
            SecurityGroups: ["sg-a36911be"]
            AssignPublicIp: "ENABLED"

Мой aws_codepipeline terraform выглядит так:

resource "aws_codepipeline" "codepipeline" {
  name     = "${var.namespace}-stage"
  role_arn = aws_iam_role.role.arn

  artifact_store {
    location = aws_s3_bucket.bucket.bucket
    type     = "S3"
  }

  stage {
    name = "Source"

    action {
      name             = "Source"
      category         = "Source"
      owner            = "ThirdParty"
      provider         = "GitHub"
      version          = "1"
      output_artifacts = ["${var.namespace}-source"]

      configuration = {
        OAuthToken = "my-token"
        Owner  = var.owner
        Repo   = var.repo
        Branch = var.branch
      }
    }
  }

  stage {
    name = "Build"

    action {
      name             = "Build"
      category         = "Build"
      owner            = "AWS"
      provider         = "CodeBuild"
      version          = "1"
      input_artifacts  = ["${var.namespace}-source"]
      output_artifacts = ["${var.namespace}-build"]

      configuration = {
        ProjectName = "project-name"
      }
    }
  }


  stage {
    name = "Deploy"

    action {
      name            = "Deploy"
      category        = "Deploy"
      owner           = "AWS"
      provider        = "CodeDeployToECS"
      input_artifacts = ["${var.namespace}-build"]
      version         = "1"

      configuration = {
        ApplicationName     = var.namespace
        DeploymentGroupName = var.namespace
        TaskDefinitionTemplateArtifact = "${var.namespace}-build"
        AppSpecTemplateArtifact        = "${var.namespace}-build"
      }
    }
  }
}

my_task.json выглядит:

[
    {
      "name": "my-container",
      "image": "30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest",
      "cpu": 7,
      "dnsSearchDomains": null,
      "logConfiguration": null,
      "entryPoint": null,
      "portMappings": [
        {
          "hostPort": 8081,
          "protocol": "tcp",
          "containerPort": 8080
        },
        {
          "hostPort": 8793,
          "protocol": "tcp",
          "containerPort": 8793
        }
      ],
      "command": null,
      "linuxParameters": null,
      "environment": [],
      "resourceRequirements": null,
      "ulimits": null,
      "dnsServers": null,
      "mountPoints": [
        {
          "readOnly": null,
          "containerPath": "/usr/local/airflow/dags",
          "sourceVolume": "dags"
        },
        {
          "readOnly": null,
          "containerPath": "/usr/local/airflow/logs",
          "sourceVolume": "logs"
        },
        {
          "readOnly": null,
          "containerPath": "/folder",
          "sourceVolume": "folder"
        },
      ],
      "workingDirectory": null,
      "secrets": null,
      "dockerSecurityOptions": null,
      "memoryReservation": 128,
      "volumesFrom": [],
      "stopTimeout": null,
      "startTimeout": null,
      "firelensConfiguration": null,
      "dependsOn": null,
      "disableNetworking": null,
      "interactive": null,
      "healthCheck": null,
      "essential": true,
      "links": null,
      "hostname": null,
      "extraHosts": null,
      "pseudoTerminal": null,
      "user": null,
      "readonlyRootFilesystem": null,
      "dockerLabels": null,
      "systemControls": null,
      "privileged": null
    }
  ]

Полная трассировка ошибки:

    [Container] 2020/06/18 10:59:50 Running command echo $CODEBUILD_RESOLVED_SOURCE_VERSION
1cd85954ec6d43da55faa9de9010b2c3aed10a52
[Container] 2020/06/18 10:59:50 Running command echo Imaget tag is...
Imaget tag is...
[Container] 2020/06/18 10:59:50 Running command echo $IMAGE_TAG
1cd8595
[Container] 2020/06/18 10:59:50 Running command docker build -t 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest .
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /codebuild/output/src903716123/src/Dockerfile: no such file or directory
[Container] 2020/06/18 10:59:50 Command did not exit successfully docker build -t 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest . exit status 1
[Container] 2020/06/18 10:59:50 Phase complete: BUILD State: FAILED
[Container] 2020/06/18 10:59:50 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -t 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest .. Reason: exit status 1
[Container] 2020/06/18 10:59:50 Entering phase POST_BUILD
[Container] 2020/06/18 10:59:50 Running command echo Build completed on `date`
Build completed on Thu Jun 18 10:59:50 UTC 2020
[Container] 2020/06/18 10:59:50 Running command echo Pushing the Docker images...
Pushing the Docker images...
[Container] 2020/06/18 10:59:50 Running command docker push 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest
The push refers to repository [30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository]
An image does not exist locally with the tag: 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository
[Container] 2020/06/18 10:59:50 Command did not exit successfully docker push 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest exit status 1
[Container] 2020/06/18 10:59:50 Phase complete: POST_BUILD State: FAILED
[Container] 2020/06/18 10:59:50 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker push 30900.dkr.ecr.eu-west-1.amazonaws.com/my-repository:latest. Reason: exit status 1
[Container] 2020/06/18 10:59:50 Expanding base directory path: .
[Container] 2020/06/18 10:59:50 Assembling file list
[Container] 2020/06/18 10:59:50 Expanding .   
[Container] 2020/06/18 10:59:50 Expanding file paths for base directory .
[Container] 2020/06/18 10:59:50 Assembling file list
[Container] 2020/06/18 10:59:50 Expanding appspec.yaml
[Container] 2020/06/18 10:59:50 Skipping invalid file path appspec.yaml
[Container] 2020/06/18 10:59:50 Expanding taskdef.json
[Container] 2020/06/18 10:59:50 Skipping invalid file path taskdef.json
[Container] 2020/06/18 10:59:50 Phase complete: UPLOAD_ARTIFACTS State: FAILED
[Container] 2020/06/18 10:59:50 Phase context status code: CLIENT_ERROR Message: no matching artifact paths found

Я не могу найти связанные проблемы, и я следую AWS документам, чтобы создать его, поэтому я не понимаю, что происходит.

Ответы [ 2 ]

1 голос
/ 18 июня 2020

Это сработает, если вы примените:

docker build -f dockerfile-name -t my-repo

У меня есть два файла докеров, поэтому мне нужно указать правильный оператор.

1 голос
/ 18 июня 2020

Ваша сборка не работает> invalid argument ":latest" for "-t, --tag" flag: invalid reference format

Это должно быть reponame: tag

$docker build -t repotname:2.0 .

Пример из справочника документов

$ docker build -t vieux/apache:2.0 .

Я думаю, вы следует изменить ваш buildspe c .yml и изменить эту строку

 docker build -t :latest .
...