0

构建规范.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

应用规范.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"

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 = ["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存在,但除子文件夹外没有其他内容。文件不存在。

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

4

1 回答 1

0

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

即,您的类似内容中没有这样的部分buildspec.yml

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

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

于 2020-06-23T10:25:05.113 回答