Dockerfile + CI for C build I recently built a CI for my course project in C. I made 3 stages, to build docker image, compile my C sources and run the said project.

That said, i think i could've do way better here but i don't really know how. I don't have a really big experience with CI, and even if that one works i would like to hear about what you think about it.

What i would like to improve is scalability, generality (there probably will be a need at some point to separate my dockerfiles per subproject (main-atoi is a subproject), ...

Source code here : Gitlab

Docker file

FROM debian:stretch
RUN apt-get update \
&amp;&amp; apt-get install gcc g++ -y

ADD ./ /home

VOLUME /home/build /home/build


.gitlab-ci.yml

stages:
- build-image
- build
- run

before_script:
- docker info

build-image:
  stage: build-image
  tags:
  - build-docker
  script:
  - docker build -t artandor/debian9-cpp:v1-tp1 .

build:
  stage: build
  tags:
  - cours
  script:
  - docker run -v /home/build:/home/build --rm artandor/debian9-cpp:v1-tp1 gcc -Wall -Werror /home/main-atoi/myatoibase.c /home/main-atoi/main-atoi.c -o /home/build/main-test

run:
  stage: run
  dependencies:
  - build
  tags:
  - cours
  script:
  - docker run -v /home/build:/home/build --rm artandor/debian9-cpp:v1-tp1 /home/build/main-test
  - cp /home/build/main-test ./
  artifacts:
    name: "Main Atoi Binary - $CI_COMMIT_REF_NAME"
    paths:
    - ./main-test
You can have a separate project for your Dockfile and let gitlab keep the image in a container repository. That way you will not need to rebuild the image every build and you can reuse the container in other project without rebuilding it.