{"id":79520,"date":"2020-10-01T16:00:09","date_gmt":"2020-10-01T13:00:09","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-set-up-automatic-builds-for-docker-images-on-github-cloudsavvy-it\/"},"modified":"2020-10-01T16:00:09","modified_gmt":"2020-10-01T13:00:09","slug":"how-to-set-up-automatic-builds-for-docker-images-on-github-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-set-up-automatic-builds-for-docker-images-on-github-cloudsavvy-it\/","title":{"rendered":"#How to Set Up Automatic Builds for Docker Images on GitHub \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a430291ed870\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a430291ed870\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-set-up-automatic-builds-for-docker-images-on-github-cloudsavvy-it\/#GitHubs_New_Container_Registry\" >GitHub\u2019s New Container Registry<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-set-up-automatic-builds-for-docker-images-on-github-cloudsavvy-it\/#How_to_Set_Up_Automatic_Builds_to_GitHub_Packages\" >How to Set Up Automatic Builds to GitHub Packages<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Set Up Automatic Builds for Docker Images on GitHub \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-7125 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/8368c5db7ca6d88d13b368b6b54c1b2a\/p\/uploads\/2020\/10\/d6528811.png\" alt=\"GitHub logo.\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>GitHub has a feature called GitHub Actions that run automatic builds, tests, and other <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">script<\/a>s whenever you make changes to a repository. One handy use case of this is automatically building and pushing Docker containers to a container registry.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"GitHubs_New_Container_Registry\"><\/span>GitHub\u2019s New Container Registry<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>GitHub\u2019s new container registry, called GitHub Container Registry, is a bit different than most registries like the Docker Hub.\u00a0It functions as an extension of GitHub Packages, a package storage system that associates packages with their source code repositories. Packages can be built and pushed from the repository, often automatically with the help of a GitHub Actions pipeline.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-7139 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/07febf22226b20066eb89f2bb48895df\/p\/uploads\/2020\/09\/a93a8568-1.png\" alt=\"GitHub Container Registry.\" width=\"700\" height=\"253\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>GitHub Container Registry is simply adding Docker-specific compatibility to GitHub Packages, making it function like a container registry for purposes of running <code>docker pull<\/code>\u00a0and other CLI commands.<\/p>\n<p>You don\u2019t need to publish to GitHub\u2019s container registry\u2014you can still publish to the Docker Hub from an action with some configuration. The prebuilt actions work with GHCR out of the box though, so it\u2019s a lot simpler to set up.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Set_Up_Automatic_Builds_to_GitHub_Packages\"><\/span>How to Set Up Automatic Builds to GitHub Packages<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To start, you\u2019ll need a repository. Even if you are only publishing packages, you\u2019ll still need a repo, because the format for GHCR is:<\/p>\n<pre>ghcr.io\/username\/repository\/image:version<\/pre>\n<p>Set up a repo, then click on \u201cActions\u201d to create a new action. Under \u201cMore Continuous Integration Workflows,\u201d click \u201cPublish Docker Container.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-7122 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/2d2b67e90510de2b30afe8634bf05354\/p\/uploads\/2020\/09\/a868be70.png\" alt=\"Set up your repo.\" width=\"700\" height=\"401\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This generates a starter template, which needs a few changes to work. First, the <code>IMAGE_NAME<\/code>\u00a0variable needs to be changed to your image name.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-7140 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/8990b12dde70d164428ebad85daff277\/p\/uploads\/2020\/09\/5bf0cff7.png\" alt=\"Change IMAGE_NAME\u00a0variable to your image name.\" width=\"700\" height=\"410\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Then, on line 39, you\u2019ll find where it logs into GHCR.<\/p>\n<pre>run: echo \"${{ secrets.CR_PAT }}\" | docker login https:\/\/ghcr.io -u ${{ github.actor }} --password-stdin<\/pre>\n<p>Currently, the only supported authentication scheme is Personal Access Tokens (PATs), which isn\u2019t great for security because they grant account-wide access. GitHub knows this, and is working on a better fix for the future, but in the meantime if you want to use GHCR from a GitHub Actions workflow, you\u2019ll need to store a PAT in the Secrets for your repository, because obviously just pasting it in here would be horrendous.<\/p>\n<p>First, you\u2019ll need to head over to Settings &gt; Developer Settings &gt; Personal Access Tokens and create a new token. This token needs <code>write:packages<\/code>\u00a0and <code>delete:packages<\/code>\u00a0settings. Note that for some reason, selecting write packages automatically selects \u201cFull Control Of Repositories,\u201d which you have to uncheck.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-7142 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/40dfcdfbb7d7fcb07ca5194769b06af0\/p\/uploads\/2020\/09\/a868be70-1.png\" alt=\"Create a new token with write:packages\u00a0and delete:packages\u00a0settings. \" width=\"700\" height=\"360\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Then, head over to the repository\u2019s settings, and create a new secret called <code>CR_PAT<\/code>, to match the action.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-7143 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/343f25618187f35de1f0517d3db972be\/p\/uploads\/2020\/09\/78245f8b.png\" alt=\"Create a new secret called CR_PAT.\" width=\"700\" height=\"422\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Head back to the action, and click \u201cStart Commit\u201d to push it to the repository.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-7144 size-medium\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/788a7ebe496303e4da51064a7c4f7fec\/p\/uploads\/2020\/09\/04cbc96b-300x289.png\" alt=\"Click &quot;Start Commit&quot; to push the new file to the repository.\" width=\"300\" height=\"289\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Once it\u2019s committed, it will trigger a workflow to run and build the package. You can monitor the status of all running workflows under the \u201cActions\u201d tab. Here, it failed because the default actions expects there to be tests to run, which this image didn\u2019t have.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-7145 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/57bd73ecb4ecf2004e3353ee297a1cfa\/p\/uploads\/2020\/09\/6322e752.png\" alt=\"Monitor the status of all running workflows under the &quot;Actions&quot; tab.\" width=\"700\" height=\"252\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Once it\u2019s successful, you should see the container in the registry, under \u201cPackages\u201d on the repository\u2019s main page, or under the packages on your profile.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"imgchk9 alignnone wp-image-7146 size-full\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/05c292702e76703ec33283891efdde92\/p\/uploads\/2020\/09\/a93a8568-2.png\" alt=\"A successful package build.\" width=\"700\" height=\"253\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/>\n<\/div>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener noreferrer\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/7138\/how-to-set-up-automatic-builds-for-docker-images-on-github\/\" target=\"_blank\" rel=\"noopener noreferrer\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Set Up Automatic Builds for Docker Images on GitHub \u2013 CloudSavvy IT&#8221; GitHub has a feature called GitHub Actions that run automatic builds, tests, and other scripts whenever you make changes to a repository. One handy use case of this is automatically building and pushing Docker containers to a container registry. GitHub\u2019s New&#8230;<\/p>\n","protected":false},"author":1,"featured_media":79521,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/d6528811.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-79520","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/79520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=79520"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/79520\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/79521"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=79520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=79520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=79520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}