2
\$\begingroup\$

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 \
&& 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
\$\endgroup\$
  • \$\begingroup\$ I added the code. Sorry for not respecting the guidelines, but it seemed to be a bit big to add it here. Thanks. \$\endgroup\$ – Artandor Oct 2 '18 at 9:01
  • 1
    \$\begingroup\$ Actually, that's fairly small for Code Review :-). Thanks for including the code; I hope you get good reviews (I'm not sufficiently skilled with Docker or Gitlab to answer it myself, I'm afraid). \$\endgroup\$ – Toby Speight Oct 2 '18 at 9:13
1
\$\begingroup\$

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.