Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Docker images in .gitlab-ci.yml

Here is my problem setup with GitLab and its integrated CI service. I have a current GitLab 8.1. and a gitlabci-multi-runner (0.6.2) with Docker support. After extending the ubuntu:precise image to include git and build-essentials (now named precise:base) I got the following .gitlab-ci.yml running:

image: precise:base
before_script:
   - apt-get install --yes cmake libmatio-dev libblas-dev libsqlite3-dev libcurl4-openssl-dev
   - apt-get install --yes libarchive-dev liblzma-dev

build:
  script:
    - mkdir build/
    - cd build
    - cmake -D CMAKE_BUILD_TYPE=Debug ../
    - make

Now my question is how to include more jobs on different images? Because I need to check if the code compiles (and later on works) on different operating systems like Ubuntu Precise, Ubuntu Trusty, CentOS 6, CentOS 7. To reduce the work I think the best way is to provide different Docker images as base.

Now the questions is how must the .gitlab-ci.yml look like to support this?

like image 752
M.K. aka Grisu Avatar asked Oct 28 '15 09:10

M.K. aka Grisu


People also ask

Can one Dockerfile build multiple images?

One approach to keeping Docker images small is using multistage builds. A multistage build allows you to use multiple images to build a final product. In a multistage build, you have a single Dockerfile, but can define multiple images inside it to help build the final image.

Can you combine 2 Docker images?

Docker doesn't do merges of the images, but there isn't anything stopping you combining the dockerfiles if available, and rolling into them into a fat image which you'd need to build.

Can a single container have multiple images?

Can we have a single container with multiple image like nginx + Redis + alpine ? You can have multiple processes inside a container but it wouldn't really be a best practice. Having NGINX and Redis in separate containers but inside the same pod would be better.

Can you have multiple GitLab-CI files?

No, you can't have multiple gitlab-ci files per repository.


2 Answers

You can define the image to use per job.

For instance:

before_script:
   - apt-get install --yes cmake libmatio-dev libblas-dev libsqlite3-dev libcurl4-openssl-dev
   - apt-get install --yes libarchive-dev liblzma-dev

build:precise:
  image: precise:base
  script:
    - mkdir build/
    - cd build
    - cmake -D CMAKE_BUILD_TYPE=Debug ../
    - make

build:trusty:
  image: trusty:base
  script:
    - mkdir build/
    - cd build
    - cmake -D CMAKE_BUILD_TYPE=Debug ../
    - make
like image 172
yjwong Avatar answered Sep 29 '22 05:09

yjwong


Your can use Anchors to make the .gitlab-ci.yml more clearly. (But this need GitLab 8.6 and GitLab Runner v1.1.1.)

Like this:

before_script:
   - apt-get install --yes cmake libmatio-dev libblas-dev libsqlite3-dev libcurl4-openssl-dev
   - apt-get install --yes libarchive-dev liblzma-dev

.build_template: &build_definition
  script:
    - mkdir build/
    - cd build
    - cmake -D CMAKE_BUILD_TYPE=Debug ../
    - make

build:precise:
  image: precise:base
  <<: *build_definition

build:trusty:
  image: trusty:base
  <<: *build_definition
like image 26
Jintao Zhang Avatar answered Sep 29 '22 03:09

Jintao Zhang