April 19, 2019
Gitlab is becoming a more one stop shop for software engineers. The first impression is it is very simple like some of the introduction videos of course. :-)
As you can see in this brief introduction to GitLab CI
And here is a GitLab CI Quick Start
I recently tried to leverage the Gitlab CI for some of my projects and I am really impressed with the gitlab way of integration and simplicity. But the meanwhile you need to be prepared for the massive information there. You can easily get lost if you don’t really have a deep understanding of how things work there.
For me the most important reference page is GitLab CI/CD Pipeline Configuration Reference
Here is the doc for GitLab Runner Executors
Most of the GitLab CI projects are using docker executor but I eventually gave up on it for one of my project because of the customization I need. My app is Gatsby based and it has quite some files in node_modules. This type of project has a GitLab CI template as below:
# This file is a template, and might need editing before it works on your project. image: node:latest # This folder is cached between builds # http://docs.gitlab.com/ce/ci/yaml/README.html#cache cache: paths: - node_modules/ pages: script: - yarn install - ./node_modules/.bin/gatsby build --prefix-paths artifacts: paths: - public only: - master
Here is a typical runner log:
And the other stages in the pipeline also have the similiar entries in the beginning of the logs
Running with gitlab-runner 11.10.0 (3001a600) on test-runner FYmx5LMB Using Shell executor... Running on e20241b601c7... Reinitialized existing Git repository in /home/gitlab-runner/builds/FYmx5LMB/0/jli/gdemo/.git/ Fetching changes... Checking out 51c50abe as master... Removing .cache/ Removing node_modules/ Removing public/ Skipping object checkout, Git LFS is not installed. Skipping Git submodules setup Checking cache for default... Runtime platform arch=amd64 os=linux pid=3846 revision=3001a600 version=11.10.0 No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. Successfully extracted cache Downloading artifacts for build1 (199708756)... Runtime platform arch=amd64 os=linux pid=3870 revision=3001a600 version=11.10.0 Downloading artifacts from coordinator... ok id=199708756 responseStatus=200 OK token=xdF9zTdC $ echo "Before script section"
You can tell from the logs that the node_modules was cached and restored to avoid repeatitive module installation, this can improve the pipeline performance.
In the deploy part of the pipeline, my project needs to use git clone the other project and merge the generated content into that project, then commit and push the changes back to the other project’s repository. At this moment I was using shell executor to implement the logic since I need to put in the ssh credential for that project’s read/write access, and I don’t want to clone that project everytime the pipeline runs. The Shell Executor works but it needs to have some setup before pipeline works.
Maybe in the future I can figure out a way to use the Docker executor while at the same time to use the ssh credential and avoid the clone everytime. Please share your experience if you have a better way. Thanks for reading.
John Li's stuff for work, study and social activities
You can follow him on Twitter