<?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: Emmanuel</title>
    <description>The latest articles on DEV Community by Emmanuel (@obapelumi).</description>
    <link>https://dev.to/obapelumi</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%2F165350%2F9d1328c3-2bb0-4394-ae29-1ca44f42b04f.jpeg</url>
      <title>DEV Community: Emmanuel</title>
      <link>https://dev.to/obapelumi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/obapelumi"/>
    <language>en</language>
    <item>
      <title>Using WooCommerce as a headless Online Store</title>
      <dc:creator>Emmanuel</dc:creator>
      <pubDate>Sun, 01 Nov 2020 15:16:40 +0000</pubDate>
      <link>https://dev.to/obapelumi/using-woocommerce-as-a-headless-e-commerce-store-4lg4</link>
      <guid>https://dev.to/obapelumi/using-woocommerce-as-a-headless-e-commerce-store-4lg4</guid>
      <description>&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install WordPress &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Watch &lt;a href="https://www.youtube.com/watch?v=cG9kv5-5bPI&amp;amp;t=688s"&gt;this video&lt;/a&gt; and stop at step #3. Make sure you select uscentral1, useast1, or uswest1 to take advantage of google's free tier.&lt;/li&gt;
&lt;li&gt;Enable let's encrypt by running:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     sudo /opt/bitnami/bncert-tool
&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;Disable the Bitnami banner by running:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    sudo /opt/bitnami/apps/wordpress/bnconfig --disable_banner 1
    sudo /opt/bitnami/ctlscript.sh restart apache
&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;Configure the server to parse Authorization headers correctly when you make a request from the front end:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // Open the htttpd config file by running:        
    sudo nano /opt/bitnami/apps/wordpress/conf/httpd-app.conf

    // Add this to the bottom of the file:
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

    // Restart the server
    sudo  /opt/bitnami/ctlscript.sh restart apache
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install Woo-commerce plugin &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go to settings -&amp;gt; Permalinks and change from plain to custom: &lt;code&gt;/%postname%/&lt;/code&gt;and product base to custom: &lt;code&gt;/product/&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate your API keys. set them to read/write&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add products (set up a test CSV file for this)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install Axios on your front end we will use this for some basic auth stuff&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bonus Section: Connect to MySQL DB Remotely
&lt;/h2&gt;

&lt;p&gt;SSH into your VM and run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano /opt/bitnami/mysql/my.cnf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;comment out &lt;code&gt;bind-address=127.0.0.1&lt;/code&gt; and save the file.&lt;/p&gt;

&lt;p&gt;Next create a new db user with the following command:&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mysql -u root -p
# enter password
CREATE USER 'user'@'%' IDENTIFIED BY 'YOUR_PASSWORD';
GRANT ALL PRIVILEGES ON * . * TO 'user'@'%';
FLUSH PRIVILEGES;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
    <item>
      <title>Create a Free DB on Google Cloud</title>
      <dc:creator>Emmanuel</dc:creator>
      <pubDate>Thu, 15 Oct 2020 02:45:18 +0000</pubDate>
      <link>https://dev.to/obapelumi/create-a-free-db-on-google-cloud-33pi</link>
      <guid>https://dev.to/obapelumi/create-a-free-db-on-google-cloud-33pi</guid>
      <description>&lt;p&gt;Once you've created a Google Cloud Console account follow these steps to create a free DB:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a project&lt;/li&gt;
&lt;li&gt;Go to the Market place and search for MYSQL Bitnami and select &lt;strong&gt;MYSQL packaged by Bitnami&lt;/strong&gt; and click launch. &lt;/li&gt;
&lt;li&gt;Configure it with the cheapest possible options. Should be $5.65 if you select SSD for storage.&lt;/li&gt;
&lt;li&gt; Once the deployment is done take note of the Admin User and Password click SSH and enter the following command to edit your MySQL config: &lt;code&gt;sudo nano /opt/bitnami/mysql/conf/my.cnf&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Edit the file and change &lt;code&gt;bind-address=127.0.0.1&lt;/code&gt; to &lt;code&gt;bind-address=0.0.0.0&lt;/code&gt;. This configures your MySQL installation to allow remote connections.&lt;/li&gt;
&lt;li&gt;Restart the mysql server by running: &lt;code&gt;sudo /opt/bitnami/ctlscript.sh restart mysql&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Now we need a static IP address so go to VPC Networks -&amp;gt; External IP Addresses. For your MySQL deployment change the type from &lt;code&gt;Ephemeral&lt;/code&gt; to &lt;code&gt;Static&lt;/code&gt;. Fill the prompt and submit.&lt;/li&gt;
&lt;li&gt;Next, we need to allow external IPs access our VM. So still under VPC Networks go to Firewall and Click Create Firewall rule.
a. Enter the name and description
b. For targets select All instances in the network
c. For source IP ranges enter 0.0.0.0/0
d. For protocols and ports click Allow All
e. Leave the rest as is and click Create&lt;/li&gt;
&lt;li&gt;Now we can test our MySQL Database connection using TablePlus.
a. Host will be the static IP address from step 6
b. Port is 3306
c. User and Password will be the credentials from step 4&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it! If everything goes right then we have a Free MySQL DB that should cost almost nothing till things get really serious.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Adonis 5 db:seed command. </title>
      <dc:creator>Emmanuel</dc:creator>
      <pubDate>Fri, 22 May 2020 18:58:41 +0000</pubDate>
      <link>https://dev.to/obapelumi/adonis-5-db-seed-command-1gme</link>
      <guid>https://dev.to/obapelumi/adonis-5-db-seed-command-1gme</guid>
      <description>&lt;p&gt;I've been messing around with Adonis 5 and even though it's still in preview the framework is just awesome. Found the &lt;code&gt;db:seed&lt;/code&gt; command in the docs but it doesn't seem to have been shipped yet so I decided to write mine pending when the command is released. I tried to make with work just like it did in version 4. Here's what I came up with: &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Deploying Adonis.js 5.0 to Google App Engine From Version Control</title>
      <dc:creator>Emmanuel</dc:creator>
      <pubDate>Tue, 19 May 2020 10:04:11 +0000</pubDate>
      <link>https://dev.to/obapelumi/deploying-adonis-js-5-0-to-google-app-engine-from-version-control-1o33</link>
      <guid>https://dev.to/obapelumi/deploying-adonis-js-5-0-to-google-app-engine-from-version-control-1o33</guid>
      <description>&lt;p&gt;In the previous article, we deployed an Adonis.js 5.0 application from our local development environment to Google App Engine. In this post, I will show you how to set up Google Cloud Build to automate the deployment of our application. We'll connect a remote GitHub repository such that every time we push to the master branch our changes are deployed to Google App Engine.&lt;/p&gt;

&lt;p&gt;To get started let's run the following commands to push our code to a remote GitHub repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit -m "first commit"

git remote add origin &amp;lt;your-github-repository&amp;gt;

git push -u origin master

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Connecting Our GitHub Repository to Google Cloud
&lt;/h3&gt;

&lt;p&gt;To connect our GitHub repository:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://source.cloud.google.com/repos"&gt;Open up Cloud Source Repositories&lt;/a&gt; in Google Cloud Console.&lt;/li&gt;
&lt;li&gt;On the top right, click the &lt;strong&gt;Add Repository&lt;/strong&gt; button then select the &lt;strong&gt;Connect external repository&lt;/strong&gt; option.&lt;/li&gt;
&lt;li&gt;Select your project from the dropdown menu,  select GitHub from the &lt;strong&gt;Git provider&lt;/strong&gt; menu and then click the &lt;strong&gt;Connect to GitHub&lt;/strong&gt; button.&lt;/li&gt;
&lt;li&gt;Once you have authorized Google Cloud on your GitHub account you can then select the required repository and click the &lt;strong&gt;Connect selected repository button&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now every time you push code to your GitHub repository it gets mirrored on Google Cloud Source Repositories.&lt;/p&gt;

&lt;h3&gt;
  
  
  Defining our Cloud Build Steps
&lt;/h3&gt;

&lt;p&gt;To automate our deployment we need to tell Google Cloud Build what to do with the code it mirrored from GitHub. We do this in the &lt;code&gt;cloudbuild.yaml&lt;/code&gt; file. For our Adonis.js 5.0 application, we will require the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the Node.js dependencies in our &lt;code&gt;package.json&lt;/code&gt; file: We need to do this because we asked &lt;code&gt;git&lt;/code&gt; to ignore the &lt;code&gt;node_modules&lt;/code&gt; folder in the &lt;code&gt;.gitignore&lt;/code&gt; file of our project.&lt;/li&gt;
&lt;li&gt;Set environment variables: Adonis.js has a &lt;code&gt;.env&lt;/code&gt; file where environment variables are stored but we also removed it from version control for security reasons. However, we will keep the &lt;code&gt;.env&lt;/code&gt; file safe in a Google Cloud Storage Bucket. To make the &lt;code&gt;.env&lt;/code&gt; file available in our App Engine deployment, we will need to copy it from the Google Cloud Storage bucket to the deployment folder.&lt;/li&gt;
&lt;li&gt;Run the Adonis.js 5.0 build command: This will compile our Adonis.js 5.0 application into the &lt;code&gt;build&lt;/code&gt; folder. You can see more details about that &lt;a href="https://preview.adonisjs.com/guides/quick-start#compiling-for-production"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Copy the &lt;code&gt;app.yaml&lt;/code&gt; file into the build folder: Since we will be deploying only the contents of the build folder, we need to copy our &lt;code&gt;app.yaml&lt;/code&gt; file into it so Google App Engine knows how to run our application.&lt;/li&gt;
&lt;li&gt;Run the application on App Engine: In this step, we push the contents of the &lt;code&gt;build&lt;/code&gt; folder to Google App Engine for deployment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is an example of how we specify these steps in the &lt;code&gt;cloudbuild.yaml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# Install node.js dependencies&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node&lt;/span&gt;
    &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;install"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;# Fetch environment variables from storage&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gcr.io/cloud-builders/gsutil&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;[&lt;/span&gt;
        &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cp"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gs://crudecoding.appspot.com/deployment-files/${_ENV}.env"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.env"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt;
      &lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;# Run build script&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node&lt;/span&gt;
    &lt;span class="na"&gt;entrypoint&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ace"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;build"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--production"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;# Copy app.yaml into build folder&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gcr.io/cloud-builders/gsutil&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cp"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;app.yaml"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;build/app.yaml"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;# Deploy application&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gcr.io/cloud-builders/gcloud"&lt;/span&gt;
    &lt;span class="na"&gt;dir&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;build"&lt;/span&gt;
    &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;app"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;deploy"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What's happening in our &lt;code&gt;cloudbuild.yaml&lt;/code&gt; file?
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;name&lt;/strong&gt; parameter in each step specifies the tool Google Cloud Build should use in running the step. This could be a container image from DockerHub or one provided by Google. For example, when we specified &lt;code&gt;node&lt;/code&gt; in the &lt;code&gt;Run build script&lt;/code&gt; step, Google Cloud Build pulls the Node.js image from DockerHub.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;entrypoint&lt;/strong&gt; parameter specifies the command-line tool to be used and then the &lt;strong&gt;args&lt;/strong&gt; parameter specify each parameter passed to the command-line tool. For example in the &lt;code&gt;Install node.js dependencies&lt;/code&gt; step the Node.js image from DockerHub comes with &lt;strong&gt;npm&lt;/strong&gt; installed so we can use it as an entry point and supply &lt;code&gt;["install"]&lt;/code&gt; in &lt;strong&gt;args&lt;/strong&gt; so that we have the &lt;code&gt;npm install&lt;/code&gt;, or in the &lt;code&gt;Run build script&lt;/code&gt; step we supply &lt;code&gt;["ace", "build", "--production"]&lt;/code&gt; to &lt;code&gt;node&lt;/code&gt; to get &lt;code&gt;node ace build --production&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a Build Trigger
&lt;/h3&gt;

&lt;p&gt;Once we have created the &lt;code&gt;cloudbuild.yaml&lt;/code&gt; file in the root of our application and committed it to the remote repository, the final step is to create a trigger on Google Cloud Build. To do this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://console.cloud.google.com/cloud-build/triggers"&gt;Open the Triggers page&lt;/a&gt; in Google Cloud Console, select your project and click &lt;strong&gt;Create Trigger&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Fill out the name and description. &lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Event&lt;/strong&gt; select &lt;em&gt;push to a branch&lt;/em&gt;. &lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Source&lt;/strong&gt; select the repository you mirrored from GitHub earlier. Select &lt;em&gt;^master$&lt;/em&gt; to trigger a build every time there's a push to the master branch. &lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Build Configuration&lt;/strong&gt; select &lt;em&gt;Cloud Build Configuration file&lt;/em&gt; and leave the file location as &lt;em&gt;cloudbuild.yaml&lt;/em&gt; then click the &lt;strong&gt;create&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That should be all. If we did everything right when we push to the master branch on our GitHub repository our application gets deployed on Google App Engine. In the next article, we'll talk about how we can connect to the database and run migrations from Google Cloud Build.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Deploying Adonis.js 5.0 to Google App Engine (Part 1)</title>
      <dc:creator>Emmanuel</dc:creator>
      <pubDate>Wed, 29 Apr 2020 19:21:53 +0000</pubDate>
      <link>https://dev.to/obapelumi/deploying-adonis-js-5-0-app-to-google-app-engine-part-1-1g93</link>
      <guid>https://dev.to/obapelumi/deploying-adonis-js-5-0-app-to-google-app-engine-part-1-1g93</guid>
      <description>&lt;p&gt;Adonis.js is a powerful Node.js framework focused around developer ergonomics and stability. Version 5.0 promises a lot of exciting improvements and since it is currently in preview, I decided to have a go at it. My biggest curiosity was how to deploy to production. I had been exploring Google Cloud Platform's App Engine and decided to try it out with Adonis.js 5.0. In this article, I will walk through my entire experience, from building out the Adonis.js 5.0 application locally to deploying and setting up a  CI/CD pipeline on Google Cloud Platform. The deployment steps discussed in this article will likely apply to most Node.js applications so you should still find it helpful even if you do not use in Adonis.js. Let's get right to it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Our Adonis.js Application
&lt;/h3&gt;

&lt;p&gt;The application we'll be hosting is an API which supports CREATE, READ UPDATE and DELETE of blog posts. I have already written the code to make our blog work. You can clone the repository and follow the setup instructions: &lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Obapelumi" rel="noopener noreferrer"&gt;
        Obapelumi
      &lt;/a&gt; / &lt;a href="https://github.com/Obapelumi/adonisjs-5-blog" rel="noopener noreferrer"&gt;
        adonisjs-5-blog
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Simple Adonis.js 5.0 blog hosted on Google Cloud Platform
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Node.js Blog Hosted On Google Cloud Platform&lt;/h1&gt;

&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;Simple Adonis.js blog hosted on Google Cloud Platform&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Setup&lt;/h3&gt;

&lt;/div&gt;
&lt;p&gt;Install the adonis cli tool and run &lt;code&gt;npm install&lt;/code&gt; or &lt;code&gt;yarn install&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Once the installation is complete you will need to complete the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create a MySQL database: This application uses MySQL for data persistence. You will need to create a MySQL database and take note of the database name and other connection parameters.&lt;/li&gt;
&lt;li&gt;Generate your application key: Run &lt;code&gt;node ace generate:key&lt;/code&gt;. This key is used internally by the application for encryption purposes.&lt;/li&gt;
&lt;li&gt;Create a .env file based off &lt;code&gt;.env.example&lt;/code&gt; file and populate its contents accordingly.
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/010b72739f4915a0323b35d65d1de7704b0620d292dac62d770e36b016859a10/68747470733a2f2f30306539653634626163653765383634373735396531393161306466373266623038633730323665396231613861653531372d617069646174612e676f6f676c6575736572636f6e74656e742e636f6d2f646f776e6c6f61642f73746f726167652f76312f622f6372756465636f64696e672e61707073706f742e636f6d2f6f2f61727469636c65732532464465706c6f792d41646f6e69736a732d352d546f2d476f6f676c652d4170702d456e67696e6525324661646f6e69732e6a73253230656e762532307661726961626c65732e4a50473f716b3d414435754d457643646c5a342d5a6b314d653552367773514d4c6d5f763157724a46374c6d31706d556f454635462d5478627572545f4946674e444231504f72684867325552796a7948657874337353415846747830504771366b75312d67514c357834574d464c6173773232686d4f55364d3867344a4c2d526e35586f6936416a6265765837346f5055787979697252694f685f30634a545a756136715256482d70597344563448546c36505f47326378614b7a6c54445a455547346e4356657455716a316a52736d792d483775696b6b4b42747549444f71736a376267614c67316f47686e62396f4e695059725652724a4f6e4266362d4f66657233514952354d4c536a6e4c414b4754366b5a744d427a69377a6a35396c4956564b717850767971483764394270444375744b64514f45626a76744369684b7970537475416c3131366c6d72616b333831626d6b576956367744564b4d6c4d6452792d31476a4a375a5f696d496d795879414c727578397a6f4a72534b65592d7754516975762d395f59704c49696567786c624c374863727a666834645853326f2d725749704c584a4c795a51546b526b6741707a4d34666e54585658766868634b63436d764d65546c724c51734c384f343334646c354d7271523235562d7636594d3559595a43466830706c64494f55477a435562684763786b4e57494f764c623478756b674c6a346f735879537842394a55497951323841715f4b454955593346666b6741436d4251365f3863734974696d3853566855626477445836437963794e4b337a5154346d646f773944755a46364e384d71303134306470413032392d39756c37313662464e426f4f63574a416f364d4d567154753869415735572d726b3774616a4f704848616a5f745f564b577444584a6455547364346451316d2d706d76495330394b34674762494d3464314339463471304a6c466377456d5f747a5a6c4c5274793879487a597a5f4d53344e4c7354396c5258794138744e6a72316278587338536b4f5a4576796466557154455a317957704b39327253367168746e68454c396d367347352d2d6337786a5651524a4d457a3970356657626b38507966466769426458676b75636856516e4850624539356c4e32356f554248413759444175585f57384e2d41483858316370544c46374e45513177565059666371704551434a436937384369766f574a47343845354f4b774a48314b395762485f43387434545833476b47614676684a73375470343764306f5368495a357a5758497726697363613d31"&gt;&lt;img src="https://camo.githubusercontent.com/010b72739f4915a0323b35d65d1de7704b0620d292dac62d770e36b016859a10/68747470733a2f2f30306539653634626163653765383634373735396531393161306466373266623038633730323665396231613861653531372d617069646174612e676f6f676c6575736572636f6e74656e742e636f6d2f646f776e6c6f61642f73746f726167652f76312f622f6372756465636f64696e672e61707073706f742e636f6d2f6f2f61727469636c65732532464465706c6f792d41646f6e69736a732d352d546f2d476f6f676c652d4170702d456e67696e6525324661646f6e69732e6a73253230656e762532307661726961626c65732e4a50473f716b3d414435754d457643646c5a342d5a6b314d653552367773514d4c6d5f763157724a46374c6d31706d556f454635462d5478627572545f4946674e444231504f72684867325552796a7948657874337353415846747830504771366b75312d67514c357834574d464c6173773232686d4f55364d3867344a4c2d526e35586f6936416a6265765837346f5055787979697252694f685f30634a545a756136715256482d70597344563448546c36505f47326378614b7a6c54445a455547346e4356657455716a316a52736d792d483775696b6b4b42747549444f71736a376267614c67316f47686e62396f4e695059725652724a4f6e4266362d4f66657233514952354d4c536a6e4c414b4754366b5a744d427a69377a6a35396c4956564b717850767971483764394270444375744b64514f45626a76744369684b7970537475416c3131366c6d72616b333831626d6b576956367744564b4d6c4d6452792d31476a4a375a5f696d496d795879414c727578397a6f4a72534b65592d7754516975762d395f59704c49696567786c624c374863727a666834645853326f2d725749704c584a4c795a51546b526b6741707a4d34666e54585658766868634b63436d764d65546c724c51734c384f343334646c354d7271523235562d7636594d3559595a43466830706c64494f55477a435562684763786b4e57494f764c623478756b674c6a346f735879537842394a55497951323841715f4b454955593346666b6741436d4251365f3863734974696d3853566855626477445836437963794e4b337a5154346d646f773944755a46364e384d71303134306470413032392d39756c37313662464e426f4f63574a416f364d4d567154753869415735572d726b3774616a4f704848616a5f745f564b577444584a6455547364346451316d2d706d76495330394b34674762494d3464314339463471304a6c466377456d5f747a5a6c4c5274793879487a597a5f4d53344e4c7354396c5258794138744e6a72316278587338536b4f5a4576796466557154455a317957704b39327253367168746e68454c396d367347352d2d6337786a5651524a4d457a3970356657626b38507966466769426458676b75636856516e4850624539356c4e32356f554248413759444175585f57384e2d41483858316370544c46374e45513177565059666371704551434a436937384369766f574a47343845354f4b774a48314b395762485f43387434545833476b47614676684a73375470343764306f5368495a357a5758497726697363613d31" alt="Environment Variables"&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Create your database tables by running migrations: In the terminal run &lt;code&gt;node ace migration:run --force&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;You can now run &lt;code&gt;npm run dev&lt;/code&gt; or &lt;code&gt;yarn dev&lt;/code&gt; to start the local development&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Obapelumi/adonisjs-5-blog" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;h3&gt;
  
  
  Setting Up Our Google Cloud Project
&lt;/h3&gt;

&lt;p&gt;To deploy our application, we need to create a project on Google Cloud Platform or select an existing one on the &lt;a href="https://console.cloud.google.com/projectselector2/home/dashboard?_ga=2.241558535.482020037.1586799515-1848780715.1586799515" rel="noopener noreferrer"&gt;Project Selector Page&lt;/a&gt;. We will also need to enable billing but don't worry Google Cloud offers a generous free-tier which we will not exhaust.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deploying our Application To Google's App Engine
&lt;/h3&gt;

&lt;p&gt;Now that we have a project set up on Google Cloud we need to push code to Google's App Engine and give it instructions on how to run our app. To do this we need the Google Cloud SDK which gives us access to some Command Line Tools which we need for our deployment. You can find the installer for Windows, macOS or Linux &lt;a href="https://cloud.google.com/sdk/docs/downloads-interactive" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once the Cloud SDK has been successfully installed we can use it to connect to our Google Cloud Project. To do this let's open up our command-line and &lt;code&gt;cd&lt;/code&gt; into our Adonis.js 5.0 application's directory and then run &lt;code&gt;gcloud init&lt;/code&gt; and follow the command-line prompts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\Y&lt;/span&gt;our Adonis.js Project Directory&amp;gt;gcloud init
Welcome! This &lt;span class="nb"&gt;command &lt;/span&gt;will take you through the configuration of gcloud.

Pick configuration to use:
 &lt;span class="o"&gt;[&lt;/span&gt;1] Create a new configuration
Please enter your numeric choice:  1

Enter configuration name. Names start with a lower &lt;span class="k"&gt;case&lt;/span&gt; letter and 
contain only lower &lt;span class="k"&gt;case&lt;/span&gt; letters a-z, digits 0-9, and hyphens &lt;span class="s1"&gt;'-'&lt;/span&gt;:  adonis-js-5
Your current configuration has been &lt;span class="nb"&gt;set &lt;/span&gt;to: &lt;span class="o"&gt;[&lt;/span&gt;adonis-js-5]

Choose the account you would like to use to perform operations &lt;span class="k"&gt;for 
&lt;/span&gt;this configuration:
 &lt;span class="o"&gt;[&lt;/span&gt;1] Log &lt;span class="k"&gt;in &lt;/span&gt;with a new account
Please enter your numeric choice:  1

Your browser has been opened to visit: https://accounts.google.com/o/oauth2/auth?/.....
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The initialization steps will open up your browser and require you to authorize the Google Cloud SDK. Once this is done you can return to your command-line to complete the initialization.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;You are logged &lt;span class="k"&gt;in &lt;/span&gt;as: &lt;span class="o"&gt;[&lt;/span&gt;&amp;lt;google-account&amp;gt;].

Pick cloud project to use:
 &lt;span class="o"&gt;[&lt;/span&gt;1] voltaic-quest-274117
Please enter numeric choice or text value &lt;span class="o"&gt;(&lt;/span&gt;must exactly match list
item&lt;span class="o"&gt;)&lt;/span&gt;:  1

Your current project has been &lt;span class="nb"&gt;set &lt;/span&gt;to: &lt;span class="o"&gt;[&lt;/span&gt;voltaic-quest-274117].

.....
extra &lt;span class="nb"&gt;set &lt;/span&gt;up info from the google cloud SDK..
....

C:&lt;span class="se"&gt;\U&lt;/span&gt;sers&lt;span class="se"&gt;\Y&lt;/span&gt;our Adonis.js Project Directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we need to tell Google App Engine to run our application using &lt;strong&gt;Node.js 10&lt;/strong&gt;, specify environment variables and a start-up command for our application. To do this first we create an &lt;code&gt;app.yaml&lt;/code&gt; file in the root of our application with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;runtime:  nodejs10

env_variables: 
  PORT: &amp;lt;The Port Your Application Listens On&amp;gt;
  HOST: &amp;lt;mostly 127.0.0.1&amp;gt;
  NODE_ENV: &amp;lt;production or development&amp;gt;
  APP_KEY: &amp;lt;Your Application Key&amp;gt;
  DB_CONNECTION: &amp;lt;MySQL, Postgres or SQLite&amp;gt;
  DB_HOST: &amp;lt;Database Host IP Address&amp;gt;
  DB_USER: &amp;lt;Database User&amp;gt;
  DB_PASSWORD: &amp;lt;Database Password&amp;gt;
  DB_NAME: &amp;lt;Database Name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adonis.js 5.0 has a build step which compiles the TypeScript code written into JavaScript in the &lt;code&gt;build&lt;/code&gt; directory. Therefore, the entry point for our application will be &lt;code&gt;build/server.js&lt;/code&gt; By default, the App Engine will look for the &lt;code&gt;start&lt;/code&gt; script in our &lt;code&gt;package.json&lt;/code&gt; file so we can specify our start-up command there. Here's how that would look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "blog",
  "scripts": {
    "build": "node ace build",
    "dev": "node ace serve --watch",
    "start": "node build/server.js"
  },
  ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can run the following commands to compile and deploy our application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node ace build \\ Adonis.js 5.0 build step
gcloud app deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we did everything right we can visit &lt;code&gt;https://&amp;lt;our-project-id&amp;gt;.appspot.com&lt;/code&gt; to see the application running.&lt;/p&gt;

&lt;p&gt;In the next article, we will set up version control for our application and see how we can up Google Cloud to deploy our application once we push to our GitHub repository's master branch.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
