Skip to content

Commit

Permalink
ci: Build a windows docker image and publish it to the registry
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ptitjano committed May 14, 2024
1 parent 5712f42 commit 825f976
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
65 changes: 65 additions & 0 deletions .gitlab/pipeline/build-windows.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions docker/Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 825f976

Please sign in to comment.