Building Windows Containers with AWS CodeBuild

2019-05-19 03:44发布

问题:

I'm getting started with the CI/CD functionality of AWS. To this point, I have been creating my docker image locally on Windows Server 2016, based on the microsoft/windowsservercore image, and manually pushing it to the ECR (amazon container registry).

At this point, I'm not trying to compile the application in CodeBuild. I'm only trying to build the container. Locally, the binaries are in a sub-directory and copied into the container.

The CodeBuild project is failing with an error: image operating system "windows" cannot be used on this platform

I'm pretty sure that's because the build environment is linux based.

Does anyone know if it's possible to create a Custom Build Environment for AWS that would support building a Windows container image?

回答1:

AWS CodeBuild does not support a Windows build environment, but it is in the works. You can sign up here for notifications about CodeBuild support for Windows.

However, CodeBuild runs all builds on Docker. Building Docker images in a Windows Docker container is not yet supported by Microsoft (see this GitHub issue for details).



回答2:

As pointed out by Clare's answer, Docker-in-Docker (DIND) isn't supported on the Windows Server platform right now, and AWS CodeBuild runs builds exclusively in Docker; not directly on top of the OS. On a side note, AWS CodeBuild support for Windows Server is Generally Available now.

--

It's not AWS CodeBuild, but you can build your own, automated container build system on AWS, using a few services together. Here's what it might look like at a high level:

  1. Deploy new EC2 instance using Amazon Machine Image (AMI) "Windows Server 2016 with Containers"
  2. Commit new code change to Git
  3. Push change to AWS CodeCommit repository
  4. CodeCommit triggers a Lambda function
  5. Lambda function invokes AWS Systems Manager - Run Command
  6. Run Command calls the AWS-RunPowerShellScript document, targeting the Window Server instance (ie. by tag or instance ID)
  7. PowerShell script clones the CodeCommit repository, builds container image, and pushes to Elastic Container Registry (ECR)

You'll need to make sure the EC2 instance(s) have access to AWS Systems Manager through their IAM Instance Profile. I haven't put this into practice yet, but it has been on my backlog for a while. Feel free to give it a shot.



回答3:

Since this answer came up towards the top of my google search and is outdated, it should be noted that as of May 25, 2018 that AWS does provide a windows image for codebuild.



回答4:

This functionality is not yet available in CodeBuild.