简体   繁体   中英

How to build a custom AWS CodeBuild image from a .NET Framework image

I am trying to see if I can create a custom AWS CodeBuild build image for an old .NET Framework application.

I can pull and use mcr.microsoft.com/dotnet/framework/sdk:4.8 directly in the build project, but when I tried to create a dockerfile with just from mcr.microsoft.com/dotnet/framework/sdk:4.8 and push it to ECR the build project throws the error:

BUILD_CONTAINER_UNABLE_TO_PULL_IMAGE: Unable to pull customer's container image. CannotPullContainerError: a Windows version 10.0.19042-based image is incompatible with a 10.0.17763 host

My Windows version is 10.0.19042, so I am assuming that the problem is that I am building the image and pushing it myself.

Is there a way to create an image with compatible base Windows version?

I was able to resolve this by leveraging the Docker manifest.

docker manifest inspect mcr.microsoft.com/dotnet/framework/sdk:4.8

I looked for the version of Windows used by CodeBuild, 10.0.17763.2928 (Windows Server 2019), and then used the hash of the proper version.

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8@sha256:fa53215891bfa80f70d5266f08942dd6e83a7b61f3701b700b19b4aba2dc1060

I then pointed my CDK codebuild.WindowsBuildImage.from_asset() props to ecr_assets.DockerImageAssetProps() to a folder containing a Dockerfile with just the above FROM statement.

# Declare a new CodeBuild project
build_project = codebuild.PipelineProject(self, "Build", 
    environment = codebuild.BuildEnvironment(
        build_image=codebuild.WindowsBuildImage.from_asset(self,
            "CustomBuildImage",
            props=ecr_assets.DockerImageAssetProps(
                directory="App/build_image"
            ),
            image_type=codebuild.WindowsImageType.SERVER_2019
        )
    ),
    environment_variables = {
        'PACKAGE_BUCKET': codebuild.BuildEnvironmentVariable(value = artifacts_bucket.bucket_name),
    },
)

The biggest downside to this is that the container takes about 5 minutes to load before it starts executing the buildspec, because Windows...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM