From ee7f446154c323084633795edfe40f8aa31d19ed Mon Sep 17 00:00:00 2001 From: Jean Felder Date: Fri, 26 Apr 2024 17:11:54 +0200 Subject: [PATCH] ci: Build a windows docker image and publish it to the registry This change allows to build a windows docker image of `sfcgal` and publish it to the registry. The docker image is built on 3 different occasions: - a new Merge Request (manual, does not block the next stages) - a new tag (automatic) - a push to master (automatic) The merge request job one is manual because this CI is quite slow. Indeed, windows runners are still in beta and the VMs take some time to start (up to 5 minutes) and they do not have a lot of compute ressources. According to gitlab tickets, the situation should improve in Q4 2024. The `dockerfile` uses a base docker image which already contains `sfcgal` dependencies built with vcpkg (mostly boost and cgal). Indeed, windows base image provided by gitlab already contain `vcpkg`, `cmake` and visual studio c++ compiler but compiling `boost` and `cgal` with `vcpkg` can take longer than the runner timeout (2h). These images will be used by `pysfcgal` to build a windows wheel. --- .gitlab-ci.yml | 1 + .gitlab/pipeline/build-windows.yml | 65 ++++++++++++++++++++++++++++++ NEWS | 1 + docker/Dockerfile.windows | 18 +++++++++ 4 files changed, 85 insertions(+) create mode 100644 .gitlab/pipeline/build-windows.yml create mode 100644 docker/Dockerfile.windows diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 93847664..92874bcc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,6 +30,7 @@ include: - local: /.gitlab/pipeline/sonar.yml - local: /.gitlab/pipeline/lint-code.yml - local: /.gitlab/pipeline/test-code.yml + - local: /.gitlab/pipeline/build-windows.yml sast: stage: test diff --git a/.gitlab/pipeline/build-windows.yml b/.gitlab/pipeline/build-windows.yml new file mode 100644 index 00000000..d64e8197 --- /dev/null +++ b/.gitlab/pipeline/build-windows.yml @@ -0,0 +1,65 @@ +build:windows: + stage: build + tags: + - saas-windows-medium-amd64 + rules: + # on default branch + - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH + when: always + # on a tag + - if: $CI_COMMIT_TAG + when: always + # on a MR if previous jobs are successful + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + when: manual + allow_failure: true + before_script: + - Start-Service -Name "docker" + - docker login -u $env:CI_REGISTRY_USER -p $env:CI_REGISTRY_PASSWORD $env:CI_REGISTRY + script: + - (docker pull $env:CI_REGISTRY_IMAGE':'windows-latest) -or ($true) + - docker build + --pull + --cache-from $env:CI_REGISTRY_IMAGE':'windows-latest + --tag $env:CI_REGISTRY_IMAGE':'windows-$env:CI_COMMIT_SHA + -f docker\Dockerfile.windows + . + - docker push $env:CI_REGISTRY_IMAGE':'windows-$env:CI_COMMIT_SHA + after_script: + - docker logout $env:CI_REGISTRY + + +push:windows-latest: + stage: deploy + tags: + - saas-windows-medium-amd64 + only: + refs: + - master + before_script: + - Start-Service -Name "docker" + - docker login -u $env:CI_REGISTRY_USER -p $env:CI_REGISTRY_PASSWORD $env:CI_REGISTRY + script: + - docker pull $env:CI_REGISTRY_IMAGE':'windows-$env:CI_COMMIT_SHA + - docker tag $env:CI_REGISTRY_IMAGE':'windows-$env:CI_COMMIT_SHA $env:CI_REGISTRY_IMAGE':'windows-latest + - docker push $env:CI_REGISTRY_IMAGE':'windows-latest + after_script: + - docker logout $env:CI_REGISTRY + + +push:windows-tag: + stage: deploy + tags: + - saas-windows-medium-amd64 + only: + refs: + - tags + before_script: + - Start-Service -Name "docker" + - docker login -u $env:CI_REGISTRY_USER -p $env:CI_REGISTRY_PASSWORD $env:CI_REGISTRY + script: + - docker pull $env:CI_REGISTRY_IMAGE':'windows-$env:CI_COMMIT_SHA + - docker tag $env:CI_REGISTRY_IMAGE':'windows-$env:CI_COMMIT_SHA $env:CI_REGISTRY_IMAGE':'windows-$env:CI_COMMIT_REF_NAME + - docker push $env:CI_REGISTRY_IMAGE':'windows-$env:CI_COMMIT_REF_NAME + after_script: + - docker logout $env:CI_REGISTRY diff --git a/NEWS b/NEWS index 6629701d..aa1aadc4 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ 1.5.2 (2024-03-XX): * Expose as_vtk to C Api (Loïc Bartoletti) * Fix build with boost 1.85 (Dirk Stöcker, Fixes #266) + * Add a CI job to build a windows docker image (Jean Felder) 1.5.1 (2023-12-21): * Rewrite and fix visibility algorithm (Loïc Bartoletti) * Apply clang-tidy fixes (Loïc Bartoletti) diff --git a/docker/Dockerfile.windows b/docker/Dockerfile.windows new file mode 100644 index 00000000..cea66bd6 --- /dev/null +++ b/docker/Dockerfile.windows @@ -0,0 +1,18 @@ +# Use sfcgal dependencies images +FROM sfcgal/sfcgal-build-deps:windows-latest + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +WORKDIR "c:\SFCGAL" +COPY . ./ + +RUN cmake -S . -B build \ + -DCMAKE_BUILD_TYPE=Release \ + -DSFCGAL_BUILD_TESTS=OFF \ + -DCMAKE_TOOLCHAIN_FILE="\"$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake\""; \ + cmake --build build --config Release + +# Restore the default Windows shell for correct batch processing. +SHELL ["cmd", "/S", "/C"] + +ENTRYPOINT ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]