Tutorial: Poor Man’s Release/Shipping Process on GitLab

Image result for gitlab

Since the recent acquisition of GitHub by Microsoft, a lot of people and companies are migrating to GitLab. The GitLab offering is especially attractive to early-stage start-ups since they offer free 10000 CI minutes or, in other words, 10000 minutes on their CI servers. It is easy to move over the workload to your own Kubernetes cluster once you run out of them – there is an easy-to-use user interface available where you could do that with just a few clicks.

Because of that, some kind of way is needed by companies to implement the release process on GitLab. Obviously, there are a lot of great solutions out there. However, let me present the process that I thought of. Besides the primary requirements of all releases processes, this one also takes minimal resources in terms of money and time because it is implemented directly using the GitLab CI functionality.

Are you interested? Let’s begin.

The overarching idea of this release process is to use the GitLab’s embedded Docker registry and the tagging functionality. Differ

Image result for containers

ent branches are going to be used for different stages of the release process – development images, unit under test (UAT) images, and the final images. Those different branches will also contain information about what kind of binaries to pull into the resulting Docker image. After a certain number of iterations, the development image is promoted to the UAT image. After some testing by, for example, QA engineers and housekeeping (e.g. some documentation needs to be updated or clients informed), they will finally be released into the wild by retagging the image with the final version tag.

Let’s drill down into the finer details.

All GitLab repositories at this moment have a free, embedded Docker registry enabled. I recommend using a separate repository for this release process – maybe you do not want to always release a new development image once new code gets pushed. Also, you might accidentally one day conflate the branches used for the release process and the development. Obviously, you could “protect” them but still, I don’t think it is worth it.

First of all, you need a Dockerfile that will be used to build the image. This guide will not talk about it, it’s up to you to figure it out. My only recommendation is to think about it as if that image is going to be released to your users i.e. it has to have everything.
Afterward, you should create a .gitlab-ci.yml file in the root of your repository and start building the blocks for the docker image build. You should begin by specifying that it’s a docker-in-docker build and in the before_script part, you need to log in to the GitLab registry:

image: docker:stable

variables:
  DOCKER_DRIVER: overlay2

services:
- docker:dind

stages:
- build

before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com

The only stage that is needed is the build stage since that is the only thing we want to do in this repository. Adapt this for yourself if you want to embed the release process inside of your code repository (if you have some kind of .gitlab-ci.yml).

overlayfs supposedly (GitLab documentation says that) gives a better performance in docker-in-docker thus use it. We will not go into the results of benchmarks of different filesystems.

After, the image building action needs to be specified as part of the build stage in the .gitlab-ci.yml file. This is how I recommend you to do it:

build_image:
  only:
  - master
  stage: build
  script:
    - "docker build -t companyname ."
    - docker tag companyname registry.gitlab.com/companyname/coolproject/companyname:latest
    - docker push registry.gitlab.com/companyname/coolproject/companyname:latest

Replace companyname in this snippet with your own company name. Also, coolproject should be the name of your project in GitLab. Most people have named their main branch as master but change that again if it does not fit your case.

Furthermore, create branches named uat and release. They both will serve to represent the different parts of the release process outlined earlier. Perhaps in those branches you should leave a README.md file which tells how the release process works.

In those separate branches, you will have a slightly modified .gitlab-ci.yml file which will essentially just pull a Docker image, retag it, and upload it back to the registry.

In the uat branch, in the .gitlab-ci.yml file you should have something like this (the other parts are skipped for brevity):

variables:
  DOCKER_DRIVER: overlay2
  CURRENT_IMAGE: registry.gitlab.com/companyname/coolproject/companyname:latest
  UAT_IMAGE: registry.gitlab.com/companyname/coolproject/companyname:0.0.1-UAT

stages:
- retag

pull_latest_and_tag_uat:
  only:
  - uat
  stage: retag
  script:
    - docker pull $CURRENT_IMAGE
    - docker tag $CURRENT_IMAGE $UAT_IMAGE
    - docker push $UAT_IMAGE

As you can see, the newest development image is simply pulled, tagged, and uploaded back to the GitLab’s Docker registry.

Finally, in release the same essentially should be used except that this time we will tag $UAT_IMAGE with the tag 0.0.1:

variables:
  DOCKER_DRIVER: overlay2
  CURRENT_IMAGE: registry.gitlab.com/companyname/coolproject/companyname:0.0.1-UAT
  RELEASE_IMAGE: registry.gitlab.com/companyname/coolproject/companyname:0.0.1

stages:
- retag

pull_latest_and_tag_release:
  only:
  - release
  stage: retag
  script:
    - docker pull $CURRENT_IMAGE
    - docker tag $CURRENT_IMAGE $RELEASE_IMAGE
    - docker push $RELEASE_IMAGE

In the end, you will be left with a Docker image with a proper tag which went through the usual release phases: development, extensive testing, golden release. I also recommend locking the uat and release branches so that someone would not accidentally push something into those branches and overwrite your Docker images.

I hope this tutorial was useful. Happy hacking! Let me know if you run into any issues.

1 year anniversary of this blog – lessons, opinions, mistakes

It is really unbelievable but it has been more than one year since I have started writing this blog. The first one of my sporadic writings which are actually expressed by certain electricity charge combinations has rotated one time around the Sun. Over that time, I have learned some small lessons about blogging and life, and I wanted to share them with you, my dear readers.

Blogging is not really dead

First of all, it is really incredibly gratifying to share knowledge and your work with other people. Addiction is how I would describe it. It is thrilling to see how other people read your articles, they react to them, respond with criticism or with even more information about those topics that you are interested in yourself. In this way, the crystal clear nuggets of wisdom come out to the top no matter what. Even if you think that you researched all of the possible combinations or cases – there still might be something that you may have missed. This next thing did not happen to me personally but sometimes it even helps people to refine their political views on certain things. So, even though most bloggers are not paid at all to do this (like me), it is amazingly satisfying in non-fiscal ways.

Secondly, it is an excellent way to generate inwards traffic or, in other words, it is a marketing tool for your skills. Just like with free software, blogging is an opportunity for everyone to showcase their writing or other skills, and in that way generate clients for yourself. I do not have any hard numbers to share right now but interest in me has definitely increased and I feel like it has let me increase my rates a little bit. In general, this is what you should be aiming for instead of forcing your potential customers to come to you through paid advertisements and so on- you should attract them with free work that you do. I don’t remember where I heard it exactly but the majority of your work is supposed to be done for free, and only a fraction of everything should be paid. This means that your rates should be pretty high to be able to sustain yourself, and this is logical because the free “work” that you do is usually much more meaningful to you and more satisfying because in the end really the most valuable thing that we all have is time and it is utmost important to spend it on things that you like.

In comparison to others

Also, I noticed that blogging is largely like making videos on YouTube or doing any other creative work. In all of these mediums, the authors are just expressing what is on their minds – the only difference is the form of the end result. YouTubers often shout about content like Steve Ballmer shouted about developers – “Content!”, “Content!”, “Content!”. Bloggers, from my experience, should care about that a lot too – just that their end result is put into words, instead of moving pictures and audio.

Productivity tips

Over the year, I have also learned some productivity tips. Automatically checking your writing with services and add-ons such as Grammarly helps immensely. You do not want to annoy your readers with silly grammar errors. Also, I have tried using voice dictation to write blog posts automatically, and then afterward just reformatting the text and form. However, I realized that it is even slower for me. This is probably because I am so used to writing fast with a keyboard since I have been using computers since a very young age (got my first one at 6! I am deeply indebted to my parents for that). On the other hand, you still might find it useful if the words come out easier for you if you are saying them verbally instead of writing down.

Spammers can start causing trouble. I definitely recommend everyone to install a plugin to WordPress like Akismet which significantly reduces the number of spam comments that get through.

Getting the readers

Marketing is pretty important as well. Over the year, the main source of readers was Reddit and LinkedIn. After a bit of time, I think that Google started rating my site higher and I started gaining traction in the search results. Thus, the organic audience of my site increased dramatically. On the contrary, the retention rate of those people is not the best since the majority just come to the site for one single article, and then leave. In my opinion, you should spend around 10-20% of the total time that you spend on your site on marketing. What’s the use of your texts if no one is reading? The same principle applies to software, honestly. What’s the use of your programs if no one is using them?

Blogging topics

You can find inspiration for blogging topics on websites such as udemy, udacity. Search for currently popular courses and see what people are looking for. Also, you could search topically related subreddits on Reddit. That is the easiest way.

I would say that just writing about something that is going in your (professional) life is a method which is somewhere in the middle in terms of difficulty. Be careful, though, not to expose too much of your private information online.

The hardest but potentially the most rewarding method is to do your own original research about things that you heard and write the process how you did it, what you learned, what are the conclusions, and so on. There is a high chance that you will rank high on link aggregation sites like HN.

Medium et al. vs self-hosting

In the beginning, I used medium for my blog. However, I moved afterwardsto using my own WordPress. I did it because I think that it provides me with a much better control over my own website. Also, it provides me with more freedom because I can easily move from one host to another, and I get a lot of customization options. Backing up all posts and comments would be much harder in the unlikely case that medium was to go down permanently.

Profitability

It seems that for the majority of bloggers, affiliate marketing provides the most amount of money. However, I do not do that and I only have ordinary AdSense advertisements on my page. Let me tell you – unless you have thousands of page views, you will not get a lot of money. Furthermore, you have to consider your audience – my audience, programmers and IT professionals, are more likely to use adblockers which means that the profit from advertisements is even lower. So, unless you will become an authority in your own little nichè and you will blog good content constantly, do not expect to earn a lot of money from blogging. It is possible but hard, in my opinion at this moment.

What could be improved

I could certainly write more often and spend more time on this blog however it isn’t actually as easy as I thought it was. Also, my content could always be improved as I mentioned before in this text. I feel that because I am learning other foreign languages, my English skill in general diminished a little bit. That is one of the reasons I keep reading books – to maintain my linguistic abilities.

I feel that at the moment I post too rarely to maintain regular readers. The majority now just finds this blog through some search engine, reads what they need, and moves on. I do not have a lot of those readers which come back and comment. From my perspective, these are the users which you want to retain the most. If blogs were human beings then they would be water for them.

Conclusion

You should definitely take up blogging if you want to improve your writing skills and show off your work. It might be not the most rewarding thing you would do in terms of money but it is most definintely rewarding in terms of intagible things like satisfaction from work. Over a year I learned a lot of small lessons and I presented them to you in this article. I am considered a newbie in terms of length but however I feel that I learned a lot already. Here is to a better second year of blogging and thank you for reading! Happy hacking and see you on the next post.