{"componentChunkName":"component---src-templates-post-template-js","path":"/posts/cicd-for-jekyll-websites","result":{"data":{"markdownRemark":{"id":"18a9c24e-bab1-5761-93e0-9f8d9682e106","html":"<h1 id=\"cicd-for-jekyll-websites\" style=\"position:relative;\"><a href=\"#cicd-for-jekyll-websites\" aria-label=\"cicd for jekyll websites permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>CICD for Jekyll Websites</h1>\n<h2 id=\"intro\" style=\"position:relative;\"><a href=\"#intro\" aria-label=\"intro permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Intro</h2>\n<p>I am going to show you how easy it is to set up a simple pipeline that will be able to automatically deploy the latest changes of your jekyll website everytime you push to master.\nThis ensures that the latest deployed copy of your website is always in sync with the master branch, and simplifies the deployment by controlling it with familiar git tools.</p>\n<h2 id=\"pre-requisites\" style=\"position:relative;\"><a href=\"#pre-requisites\" aria-label=\"pre requisites permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Pre-requisites</h2>\n<p>In order to follow along you will need</p>\n<ul>\n<li>A jekyll blog, with the source code stored on github (CodeCommit works too, but no integration for other VCS providers)</li>\n<li>A deployment target for the blog (I am deploying to S3)</li>\n<li>An AWS account</li>\n</ul>\n<h2 id=\"deploying-the-site\" style=\"position:relative;\"><a href=\"#deploying-the-site\" aria-label=\"deploying the site permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Deploying the site</h2>\n<p>In order to deploy my blog I have to create an S3 bucket with website setup. This is extremely simple, just follow these steps</p>\n<ul>\n<li>Create the bucket by running the command <code class=\"language-text\">aws s3 mb s3://&lt;my-bucket-name&gt;</code></li>\n<li>Setup the website configuration on the bucket: <a href=\"https://docs.aws.amazon.com/AmazonS3/latest/dev/EnableWebsiteHosting.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">details here</a></li>\n</ul>\n<p>Now in order to deploy the website, all I have to do is run the following\n<code class=\"language-text\">jekyll build &amp;&amp; aws s3 sync _site s3://&lt;my-bucket-name&gt;</code></p>\n<p>Unfortunately, this requires that I have the correct AWS credentials whenever I run this command, and I still have to invoke it manually each time there’s an update.\nSo, using AWS CodePipeline I can set this up automatically!</p>\n<h2 id=\"automating-the-deployment\" style=\"position:relative;\"><a href=\"#automating-the-deployment\" aria-label=\"automating the deployment permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Automating the deployment</h2>\n<p>First we need to create a <code class=\"language-text\">buildspec.yml</code> file which will tell the pipeline how to build the blog/website/whatever program you’re creating.\nBy convention, it’s easier if you keep this file in the root of your project directory. </p>\n<p>The <code class=\"language-text\">buildspec.yml</code></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">version: 0.2\nphases:\n  install:\n    commands:\n      - gem install jekyll  \n  pre_build:\n    commands:\n      - bundle install\n  build:\n    commands: \n      - echo &quot;Building site&quot;\n      - JEKYLL_ENV=production jekyll build \n      - echo &quot;Copying to S3&quot;\n      - aws s3 sync _site s3://$BUCKET_NAME\n      - echo &quot;Success&quot;</code></pre></div>\n<p>Now, we need to set up AWS CodePipeline and CodeBuild to run this on each push to master.\nWe do this via CodePipeline. I use CloudFormation to template the pipeline, so I can easily provision (and update/remove) AWS resources. I save the template under <code class=\"language-text\">ci/cicd.yml</code>.\nThe template can be found on <a href=\"https://github.com/jhuizy/website/tree/master/ci/cicd.yml\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">this website’s repo</a>.</p>\n<p>The template will provision a CodePipeline with a source stage and a build stage. The source stage will trigger based on the parameters of the template. The build stage simply delegates to our buildspec.yml. The bucket it will deploy to is specified as a parameter in the template.</p>\n<p>Given the template is located at <code class=\"language-text\">ci/cicd.yml</code>, you can deploy the template as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">aws cloudformation deploy \n  --stack-name website-cicd \\\n  --capabilities CAPABILITY_NAMED_IAM \\\n  --template-file ci/cicd.yml \\\n  --parameter-overrides \\\n      GithubBranch=master \\\n      GithubRepo=&lt;Your repo&gt; \\\n      GithubOwner=&lt;Your github username&gt; \\\n      GithubToken=&lt;Your github token&gt; \\\n      BucketName=&lt;Bucket to deploy to&gt; </code></pre></div>\n<p>Once that has successfully completed, you should be able to push any changes on your blog, and it will automatically deploy to the specified S3 bucket.</p>\n<h2 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Conclusion</h2>\n<p>As you can see it’s very simple to add CICD for a simple jekyll blog using AWS CodePipeline. Although pretty pointless and probably overkill for this type of project, this can easily be extended to support multiple different types of projects, as most of the work is done in the <code class=\"language-text\">buildspec.yml</code>.</p>","fields":{"slug":"/posts/cicd-for-jekyll-websites","tagSlugs":["/tag/post/","/tag/jekyll/","/tag/cicd/"]},"frontmatter":{"date":"2018-04-09T00:00:00.000Z","description":"How to set up continuous integration and deployment for a jekyll blog using AWS tools","tags":["post","jekyll","cicd"],"title":"CICD for Jekyll Websites","socialImage":"/media/cicd-header.jpeg"}}},"pageContext":{"slug":"/posts/cicd-for-jekyll-websites"}}}