<?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: David Oliveira</title>
    <description>The latest articles on DEV Community by David Oliveira (@davidoliveira).</description>
    <link>https://dev.to/davidoliveira</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%2F373366%2Fa89c4717-5f09-4ba3-b499-b92a8f982f7f.png</url>
      <title>DEV Community: David Oliveira</title>
      <link>https://dev.to/davidoliveira</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidoliveira"/>
    <language>en</language>
    <item>
      <title>Setup Hasura at Google Cloud Run</title>
      <dc:creator>David Oliveira</dc:creator>
      <pubDate>Sat, 30 May 2020 15:23:48 +0000</pubDate>
      <link>https://dev.to/davidoliveira/setup-hasura-at-google-cloud-run-42i8</link>
      <guid>https://dev.to/davidoliveira/setup-hasura-at-google-cloud-run-42i8</guid>
      <description>&lt;p&gt;UPDATE 01/11/2022: When I wrote this, there was no official guide about this, but now, there is, so you should check this: &lt;a href="https://hasura.io/docs/latest/enterprise/getting-started/quickstart-google-cloud-run/" rel="noopener noreferrer"&gt;https://hasura.io/docs/latest/enterprise/getting-started/quickstart-google-cloud-run/&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;This walkthrough is about how we can setup an &lt;a href="https://hasura.io/" rel="noopener noreferrer"&gt;Hasura&lt;/a&gt; instance on Google Cloud Run, using your database hosted at Google Cloud through the &lt;a href="https://cloud.google.com/sql/docs/postgres/sql-proxy" rel="noopener noreferrer"&gt;Cloud SQL Proxy&lt;/a&gt; without having to build your own container with the Hasura and Cloud SQL Proxy embedded. I will also show to you, step by step how you can do it from the Google Cloud Platform interface. Yeah, I'm not a command-line guy, my memory works better with images, but everything you will see below could be done by gcloud command-line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hasura
&lt;/h2&gt;

&lt;p&gt;I will assume that you know Hasura already, but if not, here's a quick catch up. Why Hasura? Hasura is an open source engine that connects to your databases &amp;amp; microservices and auto-generates a production-ready GraphQL backend.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High performance GraphQL serverArrow forward: Hasura’s compiler approach avoids the N+1 problem. Get thousands of GraphQL queries/sec on ~50MB of RAM.&lt;/li&gt;
&lt;li&gt;Planet-scale workloads with PostgreSQLArrow forward Hasura works with your favourite Postgres flavours and extensions. Read how we’ve taken Hasura to over 100TB databases and other experiments with the cutting-edge Postgres ecosystem.&lt;/li&gt;
&lt;li&gt;Scaling to 1 million GraphQL subscriptionsArrow forward
Hasura provides scalable &amp;amp; secure GraphQL subscriptions out-of-the-box.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Google Cloud Run
&lt;/h2&gt;

&lt;p&gt;Why deploy at Cloud Run? Cloud Run abstracts away all infrastructure management by automatically scaling up and down from zero almost instantaneously—depending on traffic. Cloud Run only charges you for the exact resources you use.  And you get a free SSL domain like &lt;a href="https://something.a.run.app" rel="noopener noreferrer"&gt;https://something.a.run.app&lt;/a&gt; which for a back-end service is more than enough for a lot of scenarios.&lt;/p&gt;

&lt;h1&gt;
  
  
  Google Cloud Pre-Configs
&lt;/h1&gt;

&lt;h2&gt;
  
  
  IAM Permissions
&lt;/h2&gt;

&lt;p&gt;Before you can start using the Google Cloud Run resource, and if you are not the administrator, at least you need to have the "Cloud Run Admin" and "Service Account User"  roles assigned to your account from your &lt;a href="https://console.cloud.google.com/iam-admin/iam" rel="noopener noreferrer"&gt;IAM&lt;/a&gt; options.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fem44x4hpfdengavph9oa.JPG" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2Fem44x4hpfdengavph9oa.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you are ready to start here: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8vee2tj9hh91ft59vx26.png" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2F8vee2tj9hh91ft59vx26.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Depending on your &lt;a href="https://console.cloud.google.com/marketplace/details/google-cloud-platform/cloud-run" rel="noopener noreferrer"&gt;options&lt;/a&gt;, you will see "Start Using Cloud Run" or "Go To Cloud Run", click on it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Enable Cloud SQL Admin API
&lt;/h2&gt;

&lt;p&gt;If Cloud SQL Admin API has not been used in project before or it is disabled, you have to enable it &lt;a href="https://console.developers.google.com/apis/api/sqladmin.googleapis.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;here&lt;/strong&gt;&lt;/a&gt; or the container running Hasura will fail the connection to the database.&lt;/p&gt;
&lt;h2&gt;
  
  
  Create a Service Account for Hasura
&lt;/h2&gt;

&lt;p&gt;Or your Cloud Run instance won't have permissions to use the Cloud SQL Proxy, so you need to create a service account with the Role "Cloud SQL Client". First &lt;a href="https://console.cloud.google.com/iam-admin/serviceaccounts" rel="noopener noreferrer"&gt;create the service&lt;/a&gt; account and the add the role.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F95tls13l87v1gqamkj14.JPG" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2F95tls13l87v1gqamkj14.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Push the Hasura Image
&lt;/h2&gt;

&lt;p&gt;Before you go ahead, you will need to enter the Container Image URL of Hasura in order to have it available later. To do this, we will need a little bit of command-line. Open the cloud shell:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd2e128l2q2jbhyihboha.JPG" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2Fd2e128l2q2jbhyihboha.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
And run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull hasura/graphql-engine
docker tag docker.io/hasura/graphql-engine:latest [HOSTNAME]/[PROJECT-ID]/[IMAGE]
docker push [HOSTNAME]/[PROJECT-ID]/[IMAGE]
gcloud container images list-tags [HOSTNAME]/[PROJECT-ID]/[IMAGE]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the values you should use for [HOSTNAME]/[PROJECT-ID]/[IMAGE] &lt;a href="https://cloud.google.com/container-registry/docs/pushing-and-pulling#pulling_images_from_a_registry" rel="noopener noreferrer"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;&lt;br&gt;
In my case I used: eu.gcr.io/grizzly-987e4/hasura&lt;br&gt;
You may need to &lt;a href="https://console.cloud.google.com/apis/library/containerregistry.googleapis.com" rel="noopener noreferrer"&gt;enable&lt;/a&gt; the Google Container Registry API in Cloud Console&lt;/p&gt;
&lt;h1&gt;
  
  
  Google Cloud Run Setup
&lt;/h1&gt;

&lt;p&gt;Finally we are ready to start the setup of an Cloud Run instance with Hasura &lt;a href="https://console.cloud.google.com/run/create" rel="noopener noreferrer"&gt;&lt;em&gt;here&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Service Settings
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1st Step
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F887p9d51iou8j7a60jsx.JPG" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2F887p9d51iou8j7a60jsx.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2nd Step
&lt;/h3&gt;

&lt;p&gt;You will need to enter the Container Image URL of Hasura that we push it earlier.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F47z0qq4u1or4zj4m2dvr.png" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2F47z0qq4u1or4zj4m2dvr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnlhfsmtre39zhrj3rqta.png" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2Fnlhfsmtre39zhrj3rqta.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  3rd Step
&lt;/h3&gt;

&lt;p&gt;Now you need to set Hasura configs at Advanced Settings, where you can set the Container, Variables and Connections. I will assume that you know the meaning of the Hasura variables to set an instance.&lt;/p&gt;
&lt;h4&gt;
  
  
  Container
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fyvukx8hpnqxk830djcxb.png" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2Fyvukx8hpnqxk830djcxb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Variables
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ft83ho3mfc5hfei2u0x4q.png" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2Ft83ho3mfc5hfei2u0x4q.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And now the tricky part, usually, an connection string structure is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres://&amp;lt;user&amp;gt;:&amp;lt;password&amp;gt;@&amp;lt;host&amp;gt;/&amp;lt;database&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here is the little detail in HASURA_GRAPHQL_DATABASE_URL that does the magic of not needing to embed the Cloud SQL Proxy into the container, look to the host variable as a querystring parameter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;postgres://&amp;lt;user&amp;gt;:&amp;lt;password&amp;gt;@/&amp;lt;database&amp;gt;?host=/cloudsql/&amp;lt;instance_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The instance_name you can grab it from the SQL section of your account, look for the Instance connection name:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxikqrmy57y7efbbqlvel.JPG" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2Fxikqrmy57y7efbbqlvel.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Connections
&lt;/h4&gt;

&lt;p&gt;Now, let's return to the configuration where you need to also select the Cloud SQL Connection, the same of the above.&lt;/p&gt;

&lt;p&gt;And now, if everything is OK, you are ready to click on "Create" and check the success. If anything goes wrong you can check the Logs section.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Folif21heryzbvzpscx08.JPG" class="article-body-image-wrapper"&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-uploads.s3.amazonaws.com%2Fi%2Folif21heryzbvzpscx08.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have any questions or if something is not clear, post your comments and I will try to help you.&lt;/p&gt;

</description>
      <category>hasura</category>
      <category>cloudrun</category>
      <category>graphql</category>
      <category>postgres</category>
    </item>
  </channel>
</rss>
