使用 AWS CDK 创建用于构建 Docker 个图像的 CodeBuild 项目
Use AWS CDK to create CodeBuild Project for building Docker Images
我想使用 AWS CDK 在源代码中定义一个 CodeBuild 项目。 CodeBuild 项目需要能够构建并推送 docker 个图像。
在 AWS 控制台中创建新的 CodeBuild 项目时,有一个选项:
Privileged Enable this flag if you want to build Docker images or want your builds to get elevated privileges.
我没有看到 api 用于在 API Docs 中打开 Privileged 标志。
var codeBuildProject = new Project(this, "Example_Build", new ProjectProps
{
ProjectName = "ExampleBuildFromCDK",
// How to add Privileged?
BuildSpec = BuildSpec.FromSourceFilename("example/buildspec.yml"),
Source = Source.CodeCommit(new CodeCommitSourceProps
{
Repository = Repository.FromRepositoryArn(this, "CodeCommit", CodeRepositoryArn),
BranchOrRef = "refs/heads/example/added-docker-images"
})
});
如果我尝试 运行 我的构建而不将 Privileged 设置为 true,我将得到标准错误:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
如何使用 AWS CDK 创建具有构建 Docker 图像的“特权”的 CodeBuild 项目?
new Project(this, "coolBuildProject", {
// ... setting up your codeBuildProject
environment: {
// this is the essential piece you're looking for
privileged: true,
},
});
一般来说,您可以在此处找到所有其他(构建)环境设置:
https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-codebuild.BuildEnvironment.html#privileged
我想使用 AWS CDK 在源代码中定义一个 CodeBuild 项目。 CodeBuild 项目需要能够构建并推送 docker 个图像。
在 AWS 控制台中创建新的 CodeBuild 项目时,有一个选项:
Privileged Enable this flag if you want to build Docker images or want your builds to get elevated privileges.
我没有看到 api 用于在 API Docs 中打开 Privileged 标志。
var codeBuildProject = new Project(this, "Example_Build", new ProjectProps
{
ProjectName = "ExampleBuildFromCDK",
// How to add Privileged?
BuildSpec = BuildSpec.FromSourceFilename("example/buildspec.yml"),
Source = Source.CodeCommit(new CodeCommitSourceProps
{
Repository = Repository.FromRepositoryArn(this, "CodeCommit", CodeRepositoryArn),
BranchOrRef = "refs/heads/example/added-docker-images"
})
});
如果我尝试 运行 我的构建而不将 Privileged 设置为 true,我将得到标准错误:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
如何使用 AWS CDK 创建具有构建 Docker 图像的“特权”的 CodeBuild 项目?
new Project(this, "coolBuildProject", {
// ... setting up your codeBuildProject
environment: {
// this is the essential piece you're looking for
privileged: true,
},
});
一般来说,您可以在此处找到所有其他(构建)环境设置: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-codebuild.BuildEnvironment.html#privileged