2
votes

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?

5

5 Answers

3
votes

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
votes

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.

0
votes

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.

0
votes

This functionality is not yet available in CodeBuild.

0
votes

Give this a try. It uses a AWS Step Function triggered by Lambda to orchestrate an ephemeral EC2 instance for building Windows containers using an AWS Code Pipeline Custom Action.

This is from an AWS code sample but I contributed and made some pipeline run context related variables available to the EC2 instance as environment variables in case your build script needs things like the pipeline execution id.

https://github.com/aws-samples/aws-codepipeline-custom-action

The blog post for the article is here https://aws.amazon.com/blogs/devops/building-windows-containers-with-aws-codepipeline-and-custom-actions/