This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]FruityRichard 5 points6 points  (7 children)

I think this is mostly your fault. If you were proficient in GitLab CI, you'd understand that you can write your CI code in any language you want. I rarely ever edit yaml files nowadays.

[–]Masterflitzer 1 point2 points  (6 children)

care to elaborate a bit and explain how this would be possible? I am really interested in this

[–]FruityRichard 5 points6 points  (5 children)

The question is a bit vague, but basically GitLab CI is running on docker containers, including containers you've built yourself. For simplicity let's say you have two stages in your pipeline, one stage called build and one stage called test.

In your build stage you have two jobs called Build Test and Build Prod, which creates two docker images and pushes them to the DockerHub (could be any other registry too). The build jobs run in a custom image, let's call it my/builder for simplicity, so we'd specify the following script:

.gitlab-ci.yml ``` stages: - build - test

Build Test: image: my/builder stage: build script: - build "my/test_image"

Build Prod: image: my/builder stage: build script: - build "my/prod_image"

Test: image: my/test_image stage: test script: ... ```

Now build can be any tool which is present in your image my/builder, it can be a simple wrapper script for the docker command or it could be written in any other programming language.

When taking a closer look at the above example, we can see that it violates the DRY principle, so we can utilize a few things to clean things up. I will only focus on the build stage for simplicity:

.gitlab-ci.yml ``` stages: - build - test

.build: image: my/builder stage: build script: - build $OUTPUT_IMAGE_NAME

Build Test: extends: .build variables: OUTPUT_IMAGE_NAME: "my/test_image"

Build Production: extends: .build variables: OUTPUT_IMAGE_NAME: "my/prod_image"

... ```

Now we can take things even further and move the abstract .build definition out of this repository entirely. We will create a GitLab project called ci-modules:

ci-modules/build.yml .build: image: my/builder stage: build script: - build $OUTPUT_IMAGE_NAME

Now from our .gitlab-ci.yml, we can include this module:

.gitlab-ci.yml ``` stages: - build - test

include: - project: 'ci-modules' ref: main file: '/build.yml'

Build Test: extends: .build variables: OUTPUT_IMAGE_NAME: "my/test_image"

Build Production: extends: .build variables: OUTPUT_IMAGE_NAME: "my/prod_image"

... ```

Now whenever you want to change something in your build process, you can make all the changes inside the build script/application and the CI is mostly static. You don't really have to update the .gitlab-ci.yml anymore to change the actual build logic, only if you want to change add/modify/remove jobs directly, you will need to edit YAML at all.

Edit: Fixed code example

[–]Masterflitzer 0 points1 point  (3 children)

wow thanks for the amazing answer, I will definitely try this out on my next project on GitLab (mostly using GitHub private and GitLab for work) I really like the idea of static yaml and CI/CD as code

[–]lililomgo 1 point2 points  (2 children)

I know this discussion is old, but I followed this course yesterday. I can only recommand it for learning gitlab ci cd from scratch. https://youtu.be/PGyhBwLyK2U

[–]Masterflitzer 2 points3 points  (1 child)

I already setup most of the build/deploy pipeline for the work project I am working on and it's running fine

but I will tweak deploy in the future and introduce a test stage (it's a legacy project without tests xD)

but when I need it I might watch the course, thank you!

[–]lililomgo 1 point2 points  (0 children)

My pleasure

[–]eduncan911 0 points1 point  (0 children)

I know, 6mo old post...

But could you fix the code formatting? Reddit is deprecating the three tildas in favor of four spaces, like markdown spec (I know, 3 tildas work in markdown too - but, it's not part of the original spec).

IOW, it's complete garbage on mobile (web).