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 ?

mpromonet
  • 11,326
  • 43
  • 62
  • 91
  • And what is the configuration of the runner? It looks like you're running a Linux docker runner using Linux container. – Jakub Kania Jan 28 '19 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 https://gitlab.com/mpromonet/dockertest – mpromonet Jan 28 '19 at 20:32
  • Set up your own runner instead of using a shared one. – Jakub Kania Jan 28 '19 at 20:50

3 Answers3

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

mpromonet
  • 11,326
  • 43
  • 62
  • 91
  • 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: https://docs.gitlab.com/ee/user/gitlab_com/#limitations-and-known-issues – FC.Araujo Dec 02 '20 at 20:55
  • @FC.Araujo: yes it was running when I posted the answer, and it was running yesterday https://gitlab.com/mpromonet/dockerwindows/-/jobs/446698288 – mpromonet Dec 04 '20 at 12:26
  • Awesome @mpromonet, it's surprising the documentation probably is not matching 100%, thanks for sharing! – FC.Araujo Dec 06 '20 at 07: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 08 '20 at 07:18
  • @FC.Araujo: removing image works to, answer was updated removing this confusing field, that is not needed – mpromonet Dec 10 '20 at 12:04
  • @mpromonet did you try to use the image within the container registry? Like calling the $CI_IMAGE_REGISTRY:master in your case for compiling any code? – thecatbehindthemask Oct 15 '21 at 13:38
  • Anychance you can share your runner config.toml for this setup ? Anychance your runner is installed on top of windows and not a linux cluster ? – user2725255 May 27 '22 at 13:08
  • This example use the gitlab.com shared runner. – mpromonet May 27 '22 at 16:56
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.

mpromonet
  • 11,326
  • 43
  • 62
  • 91
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
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.

King Chung Huang
  • 5,026
  • 28
  • 24