<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by kunj choksi on Medium]]></title>
        <description><![CDATA[Stories by kunj choksi on Medium]]></description>
        <link>https://medium.com/@kunj07soni?source=rss-aca0c412839f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TikwWHkTRbcqBU6c80FYWA.jpeg</url>
            <title>Stories by kunj choksi on Medium</title>
            <link>https://medium.com/@kunj07soni?source=rss-aca0c412839f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:05:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kunj07soni/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Ruby on Rails with Postgres + Docker + Microsoft Azure]]></title>
            <link>https://medium.com/@kunj07soni/rails-redis-postgres-on-azure-266cfe44414b?source=rss-aca0c412839f------2</link>
            <guid isPermaLink="false">https://medium.com/p/266cfe44414b</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[microsoft-azure]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[kunj choksi]]></dc:creator>
            <pubDate>Sun, 29 Sep 2024 15:35:45 GMT</pubDate>
            <atom:updated>2024-09-29T15:37:11.255Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>Prerequisites</li><li>Setup your amazing project</li><li>Add docker and docker-compose</li><li>Create Azure account</li><li>Setup Azure CLI</li><li>Create Azure Resource Group</li><li>Create Container Registry</li><li>Create a Web App for Container</li><li>Create Azure Database for PostgreSQL flexible server</li><li>Deploy docker app with Docker Compose to Azure</li><li>Play with your App</li></ol><p>Hola Amigos! So you want to build your own <strong>Ruby on Rails</strong> app and deploy it on <strong>Microsoft Azure with docker images</strong>. You are in the right spot!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*MOnYHsw9zRpSxjli.gif" /></figure><p>We’ll be using a couple of Azure Services listed below to build and deploy our Rails app</p><ol><li><strong>ACR — Azure Container Registry:</strong> A Container Registry where we will deploy our docker image</li><li><strong>Web App for Container:</strong> A web app to run a docker image from</li><li><strong>PostgreSQL flexible server:</strong> Postgres Database instance to store user data</li></ol><p>I’ll be covering everything step by step in this guide. So buckle up and let’s get started!</p><h3>Prerequisites:</h3><p>This handbook expects you to have a local setup of ROR (7.1)and you must have built a Hello World app with it.</p><p>Rails 7.1 is important (as it’s 2024!!!), as it comes with a <a href="https://edgeguides.rubyonrails.org/7_1_release_notes.html#generate-dockerfiles-for-new-rails-applications">default docker file</a> for you, so there is no hassle in creating your own.</p><p>Before we begin, let me tell you what OS I used to do the setup. At some stage, our paths might get separated, but don’t worry, I’ll clone myself for you to support till the end.</p><p>I’ve used a Macbook Silicon chip with a different configuration while making docker images for deploying on ACR (Azure Container Registry).</p><p>So, Let’s begin!</p><h3>Setup your amazing ROR project</h3><p>Let&#39;s start by creating your amazing ROR project.</p><pre>rails new amazing-project --database=postgresql</pre><p>I’ll let you do the rest of the magic for creating a modal, controller and pages of your choice.</p><p>Now, CD to your directory and do rails s. Head to your browser and go to this URL localhost:3000 , and if you see the below page,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*STm3o1S7U9YIDBRl.png" /></figure><p>You, my friend, have kicked off your journey! 🍻</p><h3>Add docker and docker-compose</h3><p>Now the 2nd step is to install docker and docker-compose on your machine.</p><p>For my Homebrew broos!</p><pre>brew install docker</pre><p>Now in your terminal, run the below command and you will see some output. Also, check the whale icon at the top.</p><pre>docker</pre><p>Optionally install docker-compose, if you want to run multiple containers on ACR.</p><pre>brew install docker-compose</pre><h3>Create Azure account</h3><p>Azure comes with free credits of $200 for 12 months to get started with, which covers almost everything that we need for this tutorial to publish the docker containerized app to Azure.</p><p>So to start with, go ahead and create a new account with your email and they may ask you for a credit card and charge you $1 for verification, but that will be reversed.</p><p>You must also create an Azure Subscription to play around with Azure resources.</p><blockquote>If you are student, they offer you a <a href="https://learn.microsoft.com/en-us/azure/education-hub/about-azure-for-students">student account</a> as well with no credit card info but with half of the credit.</blockquote><p>Once you have created an account, you should see the dashboard below, which has no resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tBv34sewD4WZITcV6ea9kQ.png" /></figure><h3>Setup Azure CLI</h3><p>Before we begin to create Azure resources, let’s set up the Azure CLI to manage create and manage Azure resources.</p><p>They have given nice documentation for doing the setup on Mac <a href="https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-macos">here</a> already, but if you are too lazy to visit their site, follow the below commands to do the setup.</p><pre>brew update &amp;&amp; brew install azure-cli</pre><p>For Windows users — <a href="https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli">visit this</a>.</p><p>For Linux users — <a href="https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=apt">check this out</a>.</p><p>To verify if your installation was successful, type az to your terminal and you should see some artwork by Azure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yirNoZTwb_QO7sTHLUuKtQ.png" /></figure><h3>Create Azure Resource Group</h3><p>An <a href="https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/manage-resource-groups-portal#what-is-a-resource-group">Azure Resource Group</a>(ARG) is an umbrella for all the resourcing you need to build, run and deploy your app. We’ll create an ARG to manage your resources such as the Web App, ACR (Azure Container Registry), and Storage Account.</p><blockquote>At this stage you must have Azure Subscription to continue, as any Resource group is created under Azure Subscription</blockquote><ol><li>Search <em>resource group</em> at top <em>search resources, services</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vwL3udTG8z6hufxXcRq0OA.png" /></figure><p>2. Enter your name and click on <em>Review and Create.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fbmLQyt50AU-qy1vTPLslQ.png" /></figure><p>3. Once created, you should see a landing page like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HE1S3vZm99MwYUfknYggHQ.png" /></figure><h3>Azure Container Registry (ACR)</h3><p>We want to deploy our app using a Docker container which requires a container registry to host our app on the cloud. Azure Container Registry (ACR) provides us with a convenient way to build, store and manage container images and artifacts in a private registry.</p><p>To create a new ACR, click on <em>+ Create </em>at the top of your resource group page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E38kU-t3zCEdkvG2AT7i7g.png" /></figure><p>Search and select Container Registry just as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6hUy5SteB3BfJAgIcGsKaQ.png" /></figure><p>Enter the name of the registry and click on <em>Review + Create</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CAfof6XwStNCaC5imo7MGA.png" /></figure><p>Click Create to continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WT14ptfnU81qzWFwvhS8Vg.png" /></figure><p>Once created it’ll take you to the deployment screen and take a minute to deploy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ywN7Cdg_97DWoCeDcgp_zg.png" /></figure><p>Once deployed, click on Go to Resource to review your ACR. On the dashboard, you’ll see information on which we will use some of them while deploying our Docker app.</p><ol><li><strong>Login server</strong>(<strong><em>amazingcontainer.azurecr.io</em></strong>): That is the server URL where we will log in and deploy our app.</li></ol><p>2. <strong>Repositories: </strong>Here it’ll list our deployed repositories (we will be visiting it in part when we have deployed our app using docker)</p><h3>Web App for Container</h3><p>Azure’s Web App for Containers is a service of the Azure App Service that allows us to run containerized web applications on both Windows and Linux. We will use it to deploy our docker containerized application with Postgres as a database, sidekiq, and Redis for cached database storage.</p><p>To begin with click on + Create in the resource group search for Web App for Container, and click Create to continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yTZa8l9g4zktOwsXaRWAw.png" /></figure><p>On the create screen below, add the name of your web app, the subscription should be whatever you have.</p><p>We will go with a couple of default values -</p><ol><li>Publish on Container</li><li>Linux container</li><li>East US as the region</li><li>Free F1 pricing plan</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vAb9JEEPiUHJvp7rUnWgXw.png" /></figure><p>You will be displayed different pricing plans as per your subscription, which could be different than what I have (As I am using the free version)</p><blockquote>The free version doesn’t have options to add a database with Web App for Container, you might need to create it separately (covered in the next section).</blockquote><p>Skip next to part of Docker by clicking next at the bottom. As we are going to deploy a cluster of Docker containers, we’ll use Docker compose, which allows us to pass in the configuration file.</p><p>Here also select Registry under the name of ACR, and skip part of selecting the configuration file, which we’ll cover later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZW7Yu3Y3C2NHC83hqoROKg.png" /></figure><p>Now, you skip all steps by clicking on Review + Create at the bottom or right-click next to review other options on your own.</p><p>On the review page click Create to continue. It’ll take you to the deployment screen and takes a couple of minutes to do its magic and deploy it.</p><h3>Azure Database for PostgreSQL flexible server</h3><p>We are using the PostgreSQL database to store our database schema. Azure Database for PostgreSQL is a fully managed database service with the Postgres database engine.</p><p>To create it click on + Create in the resource group search for PostgreSQL flexible server, and click Create to continue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q2yp7FoY610PjMoSZIlGlg.png" /></figure><p>Keep the default selections for subscription and resource groups. Enter the server name, and click on configure server, as the default selection might scare you.</p><p>For the sake of keeping costs low, I’ll be using a Burstable compute tire with minimal configuration. This will cost approx USD 14.72/ month.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UBleuW2wC33VCfROZ0p0Hw.png" /></figure><p>For the authentication, I’ll be using keeping PostgreSQL authentication only. Enter your username and password twice to continue. Remember the password, we’ll need it in our database.yml for production connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Urg_CDOHKYL6Q5ZNMb4SUQ.png" /></figure><p>I’ll keep the rest of the options default, and continue to create a PostgreSQL flexible server. As usual, it will take you to the deployment screen and take some time to deploy.</p><p>Once deployed, you’ll be required to do/get 3 things from the database to connect it with your app.</p><ol><li><strong>Database Connection details</strong>: Go to Settings &gt; Connect and find Connection details, which will have listed all configuration params required to connect your database</li><li><strong>Reset Password(Optional)</strong>: Open Security &gt; Authentication and find the option to reset your password and set the password of your choice</li><li><strong>Public Access</strong>: Click next to go to Networking. Here, we’ll keep public access enabled, as we have set passwords for it, so we can worry less about getting used by anyone other than us.</li></ol><h3>Reflect on What you have done so far</h3><p>At this stage, you have almost created everything you need to deploy your amazing project so far. So, go to your resource group and verify the list given.</p><ol><li>App Service Plan</li><li>Web App</li><li>Container Registry</li><li>Postgres Database Server</li></ol><h3>Deploy docker app with Docker Compose to Azure</h3><p>Now, as we have created everything we need on Azure, to deploy and manage, let’s start building our app with docker.</p><p>With Rails 7, you should have a docker file in your project, so no need to worry about creating one. To deploy a docker to ACR, we need to build it first on our local.</p><p>To build an image use the following command</p><pre>docker buildx build --platform linux/amd64 -t amazingproject:v1 .</pre><blockquote>Notice buildx in command here, as I previously mentioned I am using a mac with a silicon chip, so I need to make a build as per.</blockquote><p>For other platforms use the below command to create an image</p><pre>docker build -t amazingproject:v1 .</pre><p>We can also do a dry run of this image locally. For that make sure, you have done setting up environment variables, while setting up the database on Azure, we’ll be using env variables from application.yml.</p><p>To run the container for the docker image, use the below command</p><pre>docker run -it — platform linux/amd64 -p 3000:3000 amazingproject:v1</pre><p>If you get issues here with the missing secret key, you might not have done the setup for database or environment variables properly.</p><p>But we can still pass in environment variables explicitly as below</p><pre>docker run -it — platform linux/amd64 -p 3000:3000 -e SECRET_KEY_BASE=&lt;rails_secret_key&gt; -e AZURE_DATABASE_HOST=&lt;azure_database_host&gt; -e AZURE_DATABASE_USER=&lt;azure_database_user&gt; -e AZURE_DATABASE=&lt;azure_database&gt; -e AZURE_DATABASE_PASSWORD=&lt;azure_databaseb_password&gt; amazingproject:v1</pre><p>Once you start logging, head to the browser and go to URL <em>localhost:3000</em>, it should run the same as we run it with <em>rails s.</em></p><p>Now we have to tag that image with the below command</p><pre>docker tag amazingproject:v1 &lt;login-server&gt;/amazingproject:v1</pre><p>The login-server placeholder can be retrieved from the Azure Container Registry dashboard.</p><p>For me it will be <em>amazingcontainer.azurecr.io</em>, so I’ll be using that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*rTZxjNC0UryjNjjESqWwew.png" /></figure><p>Now login to your container registry through the below command,</p><pre>az acr login — name &lt;name-of-acr&gt;</pre><p>Here, the <em>name-of-acr</em> should be the name of your container registry. In my case, it is an <em>amazingcontainer.</em></p><p>You should be getting the below output after logging in with az cli.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*hV1AHoWmqBHxs80x2h_tpw.png" /></figure><p>Now that you have logged in, run the below command to deploy your local image to ACR.</p><pre>docker push &lt;login-server&gt;/&lt;docker-image-name&gt;:v1</pre><p>For me</p><ol><li>Login Server: amazingcontainer.azurecr.io</li><li>Docker image name: amazingproject</li></ol><p>It should take a few minutes and display the overall progress made during deployment.</p><p>Once deployed, head to the container under your project resource group and click on Repositories on the left side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*6A6mDCdXzJjAFaTlLtkOTg.png" /></figure><p>Upon successful upload, you should see the below repos in your container. 🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*S5_P1_ZhCMAfsbjqhYEUoA.png" /></figure><p>Now, you have everything you need to run your app on Web App. To run your app on Azure Web App, you need to deploy it, so head to your Web App within the same resource group and click on Deployment Center from the left side menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*Ka04Pg2MiDE2u87YXUu2zw.png" /></figure><p>As we choose a Web App for container service initially, we’ll have 2 options to manage the deployment of our app.</p><ol><li>Single Container (Optionally I’ll cover this)</li><li>Docker Compose</li></ol><p><strong><em>First</em></strong>, with Single Container(what you already have right now), select Single Container as Container type and select Azure Container Registry for source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t4jmH11eQk3LuEG01Gp48A.png" /></figure><p>You are required to select the registry, image, and tag associated with it. But we first need to grant access here.</p><p>To enable Admin access, go to the properties of your Azure Container Registry, select the Admin user checkbox and save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hLPcgF1nUOK4eOuExo1cw.png" /></figure><p>Now, go back to the Web App Deployment center and select Single Container, with all details — registry, image and tag. Once selected, click on Save at the top.</p><blockquote>Disregard the SCM(Source Control Management) error, we are not using username and password for SCM tools like Git.</blockquote><p>For the <strong><em>second option</em></strong> of Docker Compose, for the sack, I’ll include the Redis server for sidekiq. <em>I won’t be covering the setup of Redis with sidekiq, I’ll let you do that!</em></p><p>Head to the Deployment center and select Docker to compose for the container type. In the config text area, paste the below yml of docker-compose.</p><pre>services:<br>  web:<br>    image: amazingcontainer.azurecr.io/amazingproject:v1<br>    ports:<br>      - 3000:3000<br>    depends_on:<br>      - redis<br>  redis:<br>    image: &quot;redis:7-alpine&quot;<br>    ports:<br>      - 6379:6379<br>  sidekiq:<br>    image: amazingcontainer.azurecr.io/amazingproject:v1<br>    command: bundle exec sidekiq<br>    depends_on:<br>      - redis</pre><p>Notice that, we added 2 more services Redis and Sidekiq.</p><ol><li>redis: We’ll be using the official <a href="https://hub.docker.com/_/redis">Redis image</a>.</li><li>sidekiq: As sidekiq is a library, we use in our project, we use our project image for it which depends on Redis.</li></ol><blockquote>To let sidekiq use the redis image, when you do the setup of sidekiq in your project, make sure that you replace <strong><em>redis://localhost:6379/0</em></strong> with <strong><em>redis://redis:6379/0</em></strong> URL in the configuration.</blockquote><p>Once added, hit save! It will start deployment automatically.</p><p>You can check logs at 2 places —</p><ol><li>Deployment center &gt; Logs</li><li>Log Stream</li></ol><p>If you ask, which one is good, open up the Log stream, at least it’ll show a live log stream.</p><p>You’ll see the deployment logs over there, once complete check for the last log golden line — <strong><em>Container __for site __ initialized successfully and is ready to serve requests</em></strong></p><p>If you see that, you’s site is ready to use. You can find the site URL from the dashboard of the Web app. Open up your site and Pop a Beer 🍾</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*Vc7gTg85hvPsx_6X.gif" /></figure><p>You have reached the end of your journey Mi amiga. Thank you for reading it through and working along with me on your amazing project.</p><p>I hope you find this article helpful and that you were able to build whatever you were making.</p><p>On that note, You have a wonderful journey!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/0*VIa1-tO8Jh6Ifvjm" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=266cfe44414b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>