{"id":41,"date":"2019-05-08T10:29:09","date_gmt":"2019-05-08T08:29:09","guid":{"rendered":"http:\/\/blog.nikster.de\/wordpress\/?p=41"},"modified":"2020-02-27T13:06:49","modified_gmt":"2020-02-27T11:06:49","slug":"how-to-install-and-connect-a-gitlab-runner","status":"publish","type":"post","link":"https:\/\/blog.nikster.de\/wordpress\/index.php\/2019\/05\/08\/how-to-install-and-connect-a-gitlab-runner\/","title":{"rendered":"How to install and connect a gitlab runner"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">What&#8217;s a gitlab runner and what do I need it for?<\/h4>\n\n\n\n<p>gitlab runners are worker nodes that can be connected to gitlab to run jobs on.<br>I use the docker executor a lot to build images, but you can run any sort of jobs on them like shell\/$language scripts for testing, building, etc., whatever you configure in your projects(ci-\/cd-) pipeline (by using .gitlab-ci.yaml or the auto dev-ops pipeline).<br><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">What&#8217;s this about?<\/h4>\n\n\n\n<p>In this post I&#8217;ll cover how to set up a runner and connect it to gitlab.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get install -y apt-transport-https ca-certificates software-properties-common<\/code><\/pre>\n\n\n\n<p>make sure to install latest ca-certificates and the packages needed to conveniently manage apt repositories.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -L https:\/\/packages.gitlab.com\/install\/repositories\/runner\/gitlab-runner\/script.deb.sh | bash<\/code><\/pre>\n\n\n\n<p>execute the script.deb.sh, provided by gitlab. This basically identifies your OS Version (in my case: debian stretch), inserts the correct repository in you sources.list and imports the gpg.key. If it doesn&#8217;t work for some reason, just manually do apt-add-repository, wget gpg.key, apt-key add gpg.key.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get -y install gitlab-runner<\/code><\/pre>\n\n\n\n<p> install the gitlab-runner package<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gitlab-runner register<\/code><\/pre>\n\n\n\n<p>and register the runner.<br>This will ask for:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>your gitlab url <\/li><li>a token<\/li><\/ul>\n\n\n\n<p>To get the token:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>log in to your gitlab admin account (standard: root)<\/li><li>click the little tool icon (admin area) on the top left\/middle.<\/li><li>select runners on the left sidebar<\/li><li>copy the token<\/li><\/ul>\n\n\n\n<p>That&#8217;s it!<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>If you come here from <a href=\"https:\/\/blog.nikster.de\/wordpress\/index.php\/2019\/05\/06\/how-to-install-gitlab-and-work-with-it\/\">&#8220;how to set up gitlab and work with it&#8221;<\/a> and used self signed certificates from the <a href=\"https:\/\/blog.nikster.de\/wordpress\/index.php\/2019\/05\/05\/how-to-ssl-certificates-for-your-services\/\">how to<\/a>.<br>Then you should import your CA-Certificate on the runner.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp ca-root.crt \/usr\/local\/share\/ca-certificates\/ca-root.crt\nupdate-ca-certificates\nsystemctl daemon-reload\nsystemctl restart gitlab-runner<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Tips<\/h4>\n\n\n\n<p>If you plan to use your runner for building docker images (e.g. you want to build a <a rel=\"noreferrer noopener\" aria-label=\"pipeline (opens in a new tab)\" href=\"https:\/\/blog.nikster.de\/wordpress\/index.php\/2020\/01\/26\/how-to-set-up-a-devops-pipeline-with-gitlab-and-kubernetes\/\" target=\"_blank\">pipeline<\/a>) , you&#8217;ll need to configure some additional things:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vi \/etc\/gitlab-runner\/config.toml\n\n[[runners]]\n  executor = \"docker\"\n    environment = [\"DOCKER_AUTH_CONFIG={\\\"auths\\\": { \\\"gitlab.my.domain\\\": { \\\"auth\\\": \\\"base64encodedcreds\\\" }}}\"]\n\n[runners.docker]\n    tls-ca-file = \"\/etc\/ssl\/certs\/ca-root.pem\"\n    tls_verify = false\n    volumes = [\"\/var\/run\/docker.sock:\/var\/run\/docker.sock\",\"\/cache\"]\n    dns = [\"192.168.178.33\"]<\/code><\/pre>\n\n\n\n<p><strong>DOCKER_AUTH_CONFIG<\/strong> is available under ~\/.docker\/config.json after you have issued:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker login -u usernme https:\/\/gitlab.your.domain:4567 <\/code><\/pre>\n\n\n\n<p><strong>tls-ca-file<\/strong> might prove useful if you are working with <a rel=\"noreferrer noopener\" aria-label=\"self-signed certs (opens in a new tab)\" href=\"https:\/\/blog.nikster.de\/wordpress\/index.php\/2019\/05\/05\/how-to-ssl-certificates-for-your-services\/\" target=\"_blank\">self-signed certs<\/a>.<br><strong>tls_verify = false<\/strong> disables verification <br><strong>dns<\/strong> tells docker to use a specific dns server, this helps if you encounter &#8220;cannot resolve..&#8221; errors.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h4 class=\"wp-block-heading\">Troubleshooting Tips<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>check your firewall<\/li><li>check the config: (everything gitlab related and important is configured in \/etc\/gitlab-runner\/config.toml)<\/li><li>if docker still complains about dns, try to add dns servers to \/etc\/docker\/daemon.json<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>\"dns\": &#91;\"192.168.178.33\",\"192.168.178.1\"]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>What&#8217;s a gitlab runner and what do I need it for? gitlab runners are worker nodes that can be connected to gitlab to run jobs on.I use the docker executor a lot to build images, but you can run any sort of jobs on them like shell\/$language scripts for testing, building, etc., whatever you configure &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.nikster.de\/wordpress\/index.php\/2019\/05\/08\/how-to-install-and-connect-a-gitlab-runner\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to install and connect a gitlab runner&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[24,15,13,14,18,12,23],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-git","tag-connect","tag-debian","tag-git","tag-gitlab","tag-how-to","tag-howto","tag-setup","entry"],"_links":{"self":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":3,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":93,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/41\/revisions\/93"}],"wp:attachment":[{"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nikster.de\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}