Search code examples
compilationcontinuous-integrationgitlab-cicicdmultiplatform

Best practice for multi-platform CI/CD


I am new to CI/CD and I want to create a CI/CD pipeline on gitlab that compiles my code on:

  • MacOS
  • Linux x86
  • Windows

So far, I have been doing it only on Linux using the following strategy:

  1. I use a shared gitlab runner
  2. The gitlab runner pulls a docker image that I have created that has as a base image ubuntu:22.04 and has all the dependencies for my project
  3. The instructions on the .gitlab-ci.yml file are executed and my code is compiled producing the shared library .so that I save as an artifact.

Here is my .gitlab-ci.yml file:

stages:
- docker
- build

build_docker_image:
  stage: docker
  image: docker:20.10.16
  before_script:
    - docker login -u $REGISTRY_USER -p $REGISTRY_PASS
  script:
    - docker build -t "$REGISTRY_USER/my_dependencies:latest" .
    - docker push "$REGISTRY_USER/my_dependencies:latest"
  rules:
    - changes:
        - Dockerfile

build_and_test:
  stage: build  
  image: "$REGISTRY_USER/my_dependencies:latest"
  script:
    - mkdir build
    - cd build
    - cmake ..
    - make 
  artifacts:
    paths:
      - build/libtest.so
  


Now, i want to produce the shared libraries on MacOs and Windows. If I understood well, I cannot use Docker containers because they cannot use an osx or a windows base image, right ? I thought of using two virtual machines (osx and windows) and installing beforehand all the dependencies in each one. Is this a correct way ?

Thanks a lot and sorry for any ambiguities in my question, I am new to all this.


Solution

  • If you can find a way to build both the macOS and Windows versions on a Linux machine, that would likely be the simplest solution.

    If that is not possible, your only three options are probably:

    1. Use an OSX and Windows Machine (as you mentioned) and install GitLab as Shell-Runner, which is available for both platforms.
    2. Use GitLab's Hosted Runners, which are available both in OSX and Windows Versions.
    3. Experiment with OSX and Windows Containers. There are “workarounds” like dockurr/windows or docker-OSX, but success heavily depends on which OS Functions your code actually uses.