6

I am trying to build windows container using https://gitlab.com, but I didnot find if this is supported or not.

I made a test with a really simple Dockerfile:

FROM mcr.microsoft.com/windows/servercore:ltsc2019
CMD echo "Hello World from Windows"

Using .gitlab-ci.yml

image: docker
services:
- docker:dind

variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_DRIVER: overlay2

before_script:
  - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY

windows:
  stage: build
  script:
  - docker build -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG} . 
  - docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}

It fails with :

image operating system "windows" cannot be used on this platform
ERROR: Job failed: exit code 1

Looking for the documentation of gitlab-runner, it seems supported https://docs.gitlab.com/runner/executors/#selecting-the-executor.

Is there a way to build a windows container from the online service ?

3
  • And what is the configuration of the runner? It looks like you're running a Linux docker runner using Linux container. Jan 28, 2019 at 19:23
  • @JakubKania: I guess the runner use the default configuration, how can I configure to use a windows runner ? my tests are available in gitlab.com/mpromonet/dockertest
    – mpromonet
    Jan 28, 2019 at 20:32
  • Set up your own runner instead of using a shared one. Jan 28, 2019 at 20:50

3 Answers 3

7

Since January 2020 it is possible to build a windows container using online service using the Windows Shared Runners (beta).

Today, we are happy to announce that Windows Shared Runners hosted by GitLab is available in beta. As we are starting to roll out this important service to our community, we invite you to help shape the direction of CI/CD tooling for the Windows ecosystem on GitLab.com

For instance, using the following .gitlab-ci.yml

windows:
  stage: build
  tags:
  - shared-windows
  - windows
  - windows-1809
  script:
  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  - docker build -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG} . 
  - docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:${CI_COMMIT_REF_SLUG}

With a simple Dockerfile

FROM mcr.microsoft.com/windows/servercore:ltsc2019
CMD echo "Hello World from Windows"

The pipeline execution result enter image description here

8
  • Have you tried this configuration you provided before posting? I'm just wondering because I noticed you're using the shared runners although one of the limitations is that we can't use image or service in the configuration, as stated here: docs.gitlab.com/ee/user/gitlab_com/…
    – FC.Araujo
    Dec 2, 2020 at 20:55
  • @FC.Araujo: yes it was running when I posted the answer, and it was running yesterday gitlab.com/mpromonet/dockerwindows/-/jobs/446698288
    – mpromonet
    Dec 4, 2020 at 12:26
  • Awesome @mpromonet, it's surprising the documentation probably is not matching 100%, thanks for sharing! 👍
    – FC.Araujo
    Dec 6, 2020 at 7:30
  • Yep probably! Would you be able to give it a try just to double-check pls? I'm planning to have a windows shared runner on a private instance soon and probably I'm gonna be able to test as well in a couple of days.
    – FC.Araujo
    Dec 8, 2020 at 7:18
  • @FC.Araujo: removing image works to, answer was updated removing this confusing field, that is not needed
    – mpromonet
    Dec 10, 2020 at 12:04
3

This should be supported with GitLab 1.11 (May 2019)

Windows Container Executor for GitLab Runner

In GitLab 11.11 we are pleased to add a new executor to the GitLab Runner for using Docker containers on Windows.

https://about.gitlab.com/images/11_11/windows-container.png

Previously, using the shell executor to orchestrate Docker commands was the primary approach for Windows, but with this update you are now able to use Docker containers on Windows directly, in much the same way as if they were on Linux hosts.
This opens up the door for more advanced kinds of pipeline orchestration and management for our users of Microsoft platforms.

Included with this update is improved support for PowerShell throughout GitLab CI/CD, as well as new helper images for various versions of Windows containers.
Please note that your own Windows runners can be used with GitLab.com, but are not currently available as part of the shared public fleet.

This is from issue 535: see the documentation "Using Windows containers".

It has limitations, but it is a good first step.

2

As far as I know, the runners provided by GitLab.com are all Linux based. You'll need to provide your own runner with a Windows-based Docker engine to build a Windows Docker image.

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.