<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wilson McCoubrey</title>
    <description>The latest articles on DEV Community by Wilson McCoubrey (@wmccoubrey).</description>
    <link>https://dev.to/wmccoubrey</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F9047%2Ff91096cb-9559-4f52-9226-5f53b482ce3e.jpg</url>
      <title>DEV Community: Wilson McCoubrey</title>
      <link>https://dev.to/wmccoubrey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wmccoubrey"/>
    <language>en</language>
    <item>
      <title>Setup Custom Domain for S3 Static Website with Cloudflare CDN</title>
      <dc:creator>Wilson McCoubrey</dc:creator>
      <pubDate>Wed, 09 Jan 2019 02:24:04 +0000</pubDate>
      <link>https://dev.to/wmccoubrey/setup-custom-domain-for-s3-static-website-with-cloudflare-cdn-2o8a</link>
      <guid>https://dev.to/wmccoubrey/setup-custom-domain-for-s3-static-website-with-cloudflare-cdn-2o8a</guid>
      <description>

&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;This post briefly describes a little bit of what I learned when looking to setup a custom domain and CDN for a static website hosted on S3.&lt;/p&gt;

&lt;h1&gt;
  
  
  TLDR
&lt;/h1&gt;

&lt;p&gt;Bucket name needs to match custom domain. E.g. to setup a custom domain of &lt;code&gt;wilsonmccoubrey.com&lt;/code&gt;, bucket name must be &lt;code&gt;wilsonmccoubrey.com&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Assumptions
&lt;/h1&gt;

&lt;p&gt;This quick guide assumes you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A static website running successfully inside a bucket in S3, accessible via the bucket url e.g. &lt;code&gt;http://&amp;lt;bucket name&amp;gt;.s3-website-&amp;lt;region&amp;gt;1.amazonaws.com/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A domain setup in cloudflare and nameservers setup&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Steps
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Set bucket name correctly
&lt;/h2&gt;

&lt;p&gt;When setting up your bucket, your &lt;em&gt;bucket name must match the custom domain&lt;/em&gt; which you want to serve the site from. For example, to setup a custom domain of &lt;code&gt;wilsonmccoubrey.com&lt;/code&gt;, bucket name must be &lt;code&gt;wilsonmccoubrey.com&lt;/code&gt;. I originally made this mistake and received 'NoSuchBucketException' in the browser after setting up my domain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add CNAME Record to Cloudflare
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EghpoF6D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8djvu2p5o4kb0unlm7f2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EghpoF6D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/8djvu2p5o4kb0unlm7f2.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Enable SSL (Optional, but recommended)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sX_2gAHy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d7h7q06oaei28mh60vtw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sX_2gAHy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d7h7q06oaei28mh60vtw.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h5UQLmiM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ugce9rht5vrxx0roab92.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h5UQLmiM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/ugce9rht5vrxx0roab92.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;


</description>
      <category>s3</category>
      <category>staticwebsite</category>
      <category>cloudflare</category>
      <category>customdomain</category>
    </item>
    <item>
      <title>Deploying Vue.JS App to S3 using GitLab CI</title>
      <dc:creator>Wilson McCoubrey</dc:creator>
      <pubDate>Wed, 09 Jan 2019 01:29:23 +0000</pubDate>
      <link>https://dev.to/wmccoubrey/deploying-vuejs-app-to-s3-using-gitlab-ci-1kek</link>
      <guid>https://dev.to/wmccoubrey/deploying-vuejs-app-to-s3-using-gitlab-ci-1kek</guid>
      <description>

&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;This is a quick guide on how I have used GitLab CI to deploy a Vue.JS application to an S3 bucket. I will also cover briefly how I setup the S3 bucket to host a static website.&lt;/p&gt;

&lt;h1&gt;
  
  
  Assumptions
&lt;/h1&gt;

&lt;p&gt;I am assuming you have the following setup successfully before beginning this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vue.JS application with &lt;code&gt;npm run build&lt;/code&gt; command defined

&lt;ul&gt;
&lt;li&gt;This command will build the Vue.JS application into the &lt;code&gt;dist/&lt;/code&gt; folder in the project&lt;/li&gt;
&lt;li&gt;This command comes pre-defined with most Vue.JS quick start tools, e.g. Vue CLI generated projects.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;S3 Bucket Setup to host a static website:

&lt;ul&gt;
&lt;li&gt;See &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/dev/HowDoIWebsiteConfiguration.html"&gt;these AWS docs&lt;/a&gt; to setup a bucket&lt;/li&gt;
&lt;li&gt;Ensure you set Index Document and Error Document both to be &lt;code&gt;index.html&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Git repo setup in GitLab&lt;/li&gt;
&lt;li&gt;IAM Setup with permissions to write to S3 bucket

&lt;ul&gt;
&lt;li&gt;Follow &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html#id_users_create_console"&gt;this guide&lt;/a&gt; to setup an IAM.&lt;/li&gt;
&lt;li&gt;Ensure you choose &lt;code&gt;Programmatic access&lt;/code&gt; and take a note of your access key and secret key, these will be used in GitLab config step.&lt;/li&gt;
&lt;li&gt;test&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Configuring GitLab CI
&lt;/h2&gt;

&lt;p&gt;Gitlab CI is a docker based CI system, in the below configuration file we specify a docker image which is to be used to run the deployment job. The docker image we will be using is an image I have published, see it &lt;a href="https://hub.docker.com/r/wilson208/circleci-awscli/"&gt;here&lt;/a&gt;, and it contains the following components which we need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS CLI&lt;/li&gt;
&lt;li&gt;Node.JS&lt;/li&gt;
&lt;li&gt;NPM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The below configuration file does the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Boots a container using the specified image&lt;/li&gt;
&lt;li&gt;Runs an &lt;code&gt;npm install&lt;/code&gt; command on the Vue.JS application&lt;/li&gt;
&lt;li&gt;Runs the &lt;code&gt;npm run build&lt;/code&gt; command to build the application into the &lt;code&gt;dist/&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;Copies the &lt;code&gt;dist/&lt;/code&gt; folder up to the S3 bucket root directory using the aws cli&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Create your &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file
&lt;/h3&gt;

&lt;p&gt;Place the below content inside &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; in the root of your project. Be sure to replace  with the name of your bucket. Do not commit and push this file yet.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;stages&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;deploy&lt;/span&gt;

&lt;span class="na"&gt;deploy web&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;stage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;deploy&lt;/span&gt;
  &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;wilson208/circleci-awscli:node&lt;/span&gt;

  &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${CI_COMMIT_REF_SLUG}&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;node_modules/&lt;/span&gt;

  &lt;span class="na"&gt;before_script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;npm install&lt;/span&gt;

  &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;npm run build&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;aws s3 rm s3://&amp;lt;bucket-name&amp;gt; --recursive&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;aws s3 cp --recursive ./dist s3://&amp;lt;bucket-name&amp;gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure CI Environment Variables
&lt;/h3&gt;

&lt;p&gt;Before committing the above file, the below variable need set inside the Gitlab repo settings. These settings will be provided as environment variables to the GitLab runner and will be used by the aws cli when authenticating the S3.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to your project page in Gitlab&lt;/li&gt;
&lt;li&gt;Click on settings&lt;/li&gt;
&lt;li&gt;Click on CI/CD&lt;/li&gt;
&lt;li&gt;Expand the variables section&lt;/li&gt;
&lt;li&gt;Enter the below environment variables:

&lt;ul&gt;
&lt;li&gt;AWS_ACCESS_KEY_ID&lt;/li&gt;
&lt;li&gt;AWS_SECRET_ACCESS_KEY&lt;/li&gt;
&lt;li&gt;AWS_DEFAULT_REGION&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oUfcfzAY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/npdeqn4gq0ofo2u5oz9m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oUfcfzAY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/npdeqn4gq0ofo2u5oz9m.png" alt="Gitlab CI/CD Settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Commit and Push
&lt;/h3&gt;

&lt;p&gt;Finally, commit and push the new &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file to the repo. Navigate to your project page in Gitlab, then to CI / CD, and you &lt;em&gt;should&lt;/em&gt; see a running job. With some luck this will be successful and will deploy to your bucket.&lt;/p&gt;

&lt;p&gt;If the deploy is successful, navigate the the bucket URL and you should see your Vue.JS application.&lt;/p&gt;

&lt;p&gt;Let me know in the comments if you have any issues and I will do my best to help you resolve them! &lt;/p&gt;


</description>
      <category>vue</category>
      <category>s3</category>
      <category>gitlab</category>
      <category>staticwebsite</category>
    </item>
  </channel>
</rss>
