amazon-web-services - AWS Blue/Green ECS 部署中的 Codebuild 在执行命令时返回错误:docker build -t :latest
问题描述
我有一个python 3
项目,我想使用AWS Blue/Green deployment
.
我在项目的根目录中有一个buildspec.yml
and 。appspec.yaml
还有一个包含 terraform 文件的文件夹。此文件夹有 4 级文件夹,直到到达名为 .json 的 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
地形看起来像:
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
文档来创建它,所以我不明白发生了什么。
解决方案
如果您申请,它会起作用:
docker build -f dockerfile-name -t my-repo
我有两个 dockerfile,所以我需要将声明指向好的那个。
推荐阅读
- google-api - Google Drive API v3 & Google Picker:更改文件的下载权限
- swift - 如何自定义 MKAnnotation pin 的图像
- azure - 在 Azure DW(突触)中使用 Max 进行数据透视
- python - 调用函数来检查输入是否能被 7 整除
- json - 如何使用 Flutter 将 Json 数据中的所有图像显示到 Carousal 中
- arrays - 如何根据相同的键将一个对象放入另一个对象中?
- python-3.x - 使用 Voila 运行 ipynb 文件时,Chrome 浏览器中不会显示任何交互式小部件
- swift - 带有重复的本地通知
- javascript - angular 9在单个元素滚动上添加类
- c++ - C++ 初学者,尝试打印值时访问冲突