【问题标题】:Codepipeline in AWS Blue Green working but not gihub files not in serverAWS Blue Green 中的 Codepipeline 工作,但 gihub 文件不在服务器中
【发布时间】:2020-06-23 18:25:05
【问题描述】:

Buildspec.yaml

version: 0.2
files:
  - source: /
    destination: /folder-test

phases:
  install:
    commands:
      - apt-get update
      - apt install jq
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region eu-west-1 --no-include-email | sed 's|https://||')
      - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
  build:
    commands:
      - echo Pulling docker image
      - docker pull 309005414223.dkr.ecr.eu-west-1.amazonaws.com/my-task-webserver-repository:latest
      - echo Running the Docker image...
      - docker run -d=true 309005414223.dkr.ecr.eu-west-1.amazonaws.com/my-task-webserver-repository:latest
  post_build:
    commands:
      - aws ecs describe-task-definition --task-definition my-task-task-definition | jq '.taskDefinition' > taskdef.json
artifacts:
  files:
    - appspec.yaml
    - taskdef.json

Appspec.yml

version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: "arn:XXX/YYY"
        LoadBalancerInfo:
          ContainerName: "My-name"
          ContainerPort: "8080"
        NetworkConfiguration:
          AwsvpcConfiguration:
            Subnets: ["subnet-1","subnet-2","subnet-3"]
            SecurityGroups: ["sg-1","sg-2","sg-3"]
            AssignPublicIp: "DISABLED"

地形资源(代码管道)

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 = ["my-source"]

      configuration = {
        OAuthToken = "UUUU"
        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  = ["my-source"]
      output_artifacts = ["my-build"]

      configuration = {
        ProjectName = my-project
      }
    }
  }


  stage {
    name = "Deploy"

    action {
      name            = "Deploy"
      category        = "Deploy"
      owner           = "AWS"
      provider        = "CodeDeployToECS"
      input_artifacts = ["my-build"]
      version         = "1"

      configuration = {
        ApplicationName     = app_name
        DeploymentGroupName = group_name
        TaskDefinitionTemplateArtifact = "my-build"
        AppSpecTemplateArtifact        = "my-build"
      }
    }
  }
}

代码构建

resource "aws_codebuild_project" "codebuild" {
  name          = my-project
  description   = "Builds for my-project"
  build_timeout = "15"
  service_role  = aws_iam_role.role.arn

  artifacts {
    type = "CODEPIPELINE"
  }

  environment {
    compute_type    = "BUILD_GENERAL1_SMALL"
    image           = "aws/codebuild/standard:2.0"
    type            = "LINUX_CONTAINER"
    privileged_mode = true

  }

  cache {
    type  = "LOCAL"
    modes = ["LOCAL_DOCKER_LAYER_CACHE", "LOCAL_SOURCE_CACHE"]
  }

  source {
    type = "CODEPIPELINE"
  }

  vpc_config {
          security_group_ids = var.sg_ids
          subnets = ["subnet-1","subnet-2","subnet-3"]
          vpc_id = "vpc-1"
  }
}

在代码管道中一切正常。创建任务,并重定向流量。没有显示任何问题的日志。就在通过 ssh 连接到服务器时。文件夹folder-test 存在,但除子文件夹外没有内容。文件不存在。

我尝试在控制台中删除该文件夹,然后重新部署新推送,结果相同。

【问题讨论】:

    标签: amazon-web-services terraform aws-codepipeline aws-codebuild blue-green-deployment


    【解决方案1】:

    根据buildspec.yml 的 AWS 规范,您的文件不符合其规范。

    也就是说,buildspec.yml 中没有没有这样的部分,就像你的:

    files:
      - source: /
        destination: /folder-test
    

    这可以解释为什么文件/文件夹不是您所期望的。

    【讨论】:

    • 我第一次尝试没有它,它根本不起作用:S输出是一样的
    • @Maik 请问你是从哪里得到这个files 部分的?它绝对不在buildspec.yml 参考文档中。也许它的一些未记录的功能?
    • 当我在 EC2 部署方面遇到另一个问题时,我发现它正在寻找答案。我知道它不适用于 ECS B/G 但我必须尝试一下
    • @Maik 你想在你的容器中创建这样的文件夹吗?为此,您将在 Dockerfile 中定义它。
    • 不,这不是我想要的。我只想将我所有的代码从guthub 部署到我的服务器。当它是 EC2 部署时,它可以工作。现在在 ECS B/G 中,尽管使用了 buildspec.yml 中的所有要求,但它仍然无法正常工作。我后来添加了那 3 行代码,因为我正在尝试修复它。但是原始代码没有它。
    猜你喜欢
    • 2020-09-13
    • 2021-12-20
    • 2019-06-28
    • 1970-01-01
    • 2018-03-08
    • 2013-06-23
    • 1970-01-01
    • 2017-01-29
    • 1970-01-01
    相关资源
    最近更新 更多