<?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 Midhun Balan on Medium]]></title>
        <description><![CDATA[Stories by Midhun Balan on Medium]]></description>
        <link>https://medium.com/@midhunbalan.dev?source=rss-909d5ab7ec2d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8cnDeRSIHAHV_1ac_tJjaQ@2x.jpeg</url>
            <title>Stories by Midhun Balan on Medium</title>
            <link>https://medium.com/@midhunbalan.dev?source=rss-909d5ab7ec2d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 19:23:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@midhunbalan.dev/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[Understanding @EnableConfigurationProperties in Spring Boot]]></title>
            <link>https://medium.com/@midhunbalan.dev/understanding-enableconfigurationproperties-in-spring-boot-9dff88acf8a2?source=rss-909d5ab7ec2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9dff88acf8a2</guid>
            <dc:creator><![CDATA[Midhun Balan]]></dc:creator>
            <pubDate>Tue, 22 Oct 2024 12:17:38 GMT</pubDate>
            <atom:updated>2024-10-22T12:17:38.341Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In modern Spring Boot applications, managing configurations through externalized properties is essential for flexibility and environment-specific customizations.</p><p>One powerful feature in Spring Boot that facilitates this is the @EnableConfigurationProperties annotation. In this article, we’ll explore how it works, why it’s useful, and how to use it effectively in a real-world application.</p><p>As usual, this article begins by addressing three key questions: <strong><em>what, why, and how</em></strong>, followed by an example. It explores the purpose, usage, and benefits of utilizing <strong><em>@EnableConfigurationProperties</em></strong> for managing application configurations. So, let’s dive in!</p><h3>What is @EnableConfigurationProperties?</h3><p>@EnableConfigurationProperties is an annotation in Spring Boot that is used to enable support for configuration properties. It works hand-in-hand with another annotation called @ConfigurationProperties, which is used to bind external configuration (such as values from a properties or YAML file) to a POJO (Plain Old Java Object).</p><p>Refere the below link if you want to learn more about the ConfigurationProperties annotation: <a href="https://medium.com/@midhunbalan.dev/understanding-configurationproperties-annotation-in-springboot-674550f51f9a">https://medium.com/@midhunbalan.dev/understanding-configurationproperties-annotation-in-springboot-674550f51f9a</a></p><p>This feature provides a type-safe way to manage configurations and allows you to cleanly group related properties into separate classes, promoting modularity in your application configuration.</p><h3>How Does It Work?</h3><ul><li><strong>@ConfigurationProperties</strong>: This annotation defines a class where external configuration properties will be mapped. You can specify a prefix that matches the keys in your application.properties or application.yml file.</li><li><strong>@EnableConfigurationProperties</strong>: This annotation is applied to a Spring configuration class and specifies which configuration properties classes should be bound from external configuration sources.</li></ul><h3>Why Use @EnableConfigurationProperties?</h3><ol><li>Configuration properties are mapped directly to strongly-typed Java objects. This helps avoid common mistakes like typos in property keys and incorrect data types.</li><li>You can separate different sets of properties (e.g., database, mail server, API settings) into their own POJOs, which improves the maintainability of your code.</li><li>Spring profiles (e.g., dev, prod) are often used in applications. By externalizing configuration using @EnableConfigurationProperties, you can easily load different configurations depending on the active profile.</li><li>Spring Boot automatically maps properties from the environment or configuration files into your Java objects, requiring minimal boilerplate code.</li></ol><h3>Example: Using @EnableConfigurationProperties in a Real Project</h3><p>Let’s walk through a real-world example of how to use @EnableConfigurationProperties to load database configuration properties in a Spring Boot application.</p><p>So in this project, what we are going to achieve is to enable two configuration class in your project.</p><h3>Step 1: Create the Configuration Properties Classes</h3><p>We start by defining a class that will hold our database configuration properties. We annotate this class with @ConfigurationProperties and specify the prefix (database) that matches the keys in the properties file.</p><p><strong>AppProperties.java</strong></p><pre>package com.configmanager.config;<br><br>import lombok.Data;<br>import org.springframework.boot.context.properties.ConfigurationProperties;<br>@Data<br>@ConfigurationProperties(prefix = &quot;app&quot;)<br>public class AppProperties {<br>    private String name;<br>    private String version;<br>}</pre><p><strong>DatabaseProperties.java</strong></p><pre>package com.configmanager.config;<br><br>import lombok.Data;<br>import org.springframework.boot.context.properties.ConfigurationProperties;<br>@Data<br>@ConfigurationProperties(prefix = &quot;database&quot;)<br>public class DatabaseProperties {<br>    private String url;<br>    private String username;<br>    private String password;<br>}</pre><h3>Step 2: Enable Configuration Properties</h3><p>Next, we need to tell Spring Boot to enable the configuration properties class we just created. This is where @EnableConfigurationProperties comes in.</p><p>We create a configuration class and annotate it with @EnableConfigurationProperties, passing DatabaseProperties.class and AppProperties.class as parameters to indicate which properties class to enable.</p><pre>package com.configmanager.config;<br><br>import org.springframework.boot.context.properties.EnableConfigurationProperties;<br>import org.springframework.context.annotation.Configuration;<br>@Configuration<br>@EnableConfigurationProperties({AppProperties.class, DatabaseProperties.class})<br>public class AppConfig {<br>}</pre><h3>Step 3: Define External Configuration</h3><p>The next step is to add the actual configuration values in application.properties (or application.yml). The property keys must match the prefix and fields in the DatabaseProperties class and AppProperties class.</p><pre>spring.application.name=ConfigPropEnabler<br><br># Application properties<br>app.name=My Application<br>app.version=1.0.0<br># Database properties<br>database.url=jdbc:mysql://localhost:3306/mydb<br>database.username=root<br>database.password=secret</pre><h3>Step 4: Use the Properties in a Spring Rest Controller</h3><p>To demonstrate how to access the bound configuration properties in your application, let’s inject DatabaseProperties and AppProperties into a controller and print the values.</p><pre>package com.configmanager.api;<br><br>import com.configmanager.config.AppProperties;<br>import com.configmanager.config.DatabaseProperties;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.RestController;<br>@RestController<br>public class ConfigPropEnablerApiEndPoint {<br>    private final AppProperties appProperties;<br>    private final DatabaseProperties databaseProperties;<br>    @Autowired<br>    public ConfigPropEnablerApiEndPoint(AppProperties appProperties, DatabaseProperties databaseProperties) {<br>        this.appProperties = appProperties;<br>        this.databaseProperties = databaseProperties;<br>    }<br>    @GetMapping(&quot;/info&quot;)<br>    public String getAppInfo() {<br>        return &quot;App Name: &quot; + appProperties.getName() + &quot;, Version: &quot; + appProperties.getVersion();<br>    }<br>    @GetMapping(&quot;/dbinfo&quot;)<br>    public String getDbInfo() {<br>        return &quot;DB URL: &quot; + databaseProperties.getUrl() + &quot;, Username: &quot; + databaseProperties.getUsername();<br>    }<br>}</pre><p>When you run your Spring Boot application, you should see the following output in the console, while hitting the apis.</p><h3><strong>Output:</strong></h3><p><strong>/info</strong> api</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hK55k1vAqtcm-Rwh0Zgnsw.png" /></figure><p><strong>/dbinfo</strong> api</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eTUHy61J0jD-0NxMfZEXFg.png" /></figure><h3>Conclusion</h3><p>@EnableConfigurationProperties is an essential tool in Spring Boot for managing externalized configuration. By binding external properties to strongly-typed Java objects, it promotes clean, maintainable, and modular configuration management. Whether you&#39;re dealing with database settings, API keys, or other environment-specific settings, @EnableConfigurationProperties can significantly simplify your code and make it more flexible.</p><p>To summarize:</p><ul><li>Use @ConfigurationProperties to define classes for external configurations.</li><li>Use @EnableConfigurationProperties to enable the binding of those properties into Spring components.</li><li>You can easily manage multiple environments by combining this with Spring profiles.</li></ul><p>By adopting this pattern, you’ll have a more robust, organized, and flexible configuration management system in your Spring Boot application!</p><p>Github URL: <a href="https://github.com/MyArticleHub/ConfigPropEnabler">https://github.com/MyArticleHub/ConfigMaster</a></p><p>Thank you so much for reading! Feel free to leave a comment if you have any questions. Have a wonderful day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9dff88acf8a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding @ConfigurationProperties Annotation in SpringBoot]]></title>
            <link>https://medium.com/@midhunbalan.dev/understanding-configurationproperties-annotation-in-springboot-674550f51f9a?source=rss-909d5ab7ec2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/674550f51f9a</guid>
            <dc:creator><![CDATA[Midhun Balan]]></dc:creator>
            <pubDate>Fri, 18 Oct 2024 10:52:06 GMT</pubDate>
            <atom:updated>2024-10-23T19:23:43.958Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*fI4XaGAbGGnUCid43SK7Yw.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>If you are a developer working on a Spring Boot application, you’re likely familiar with <strong>application properties</strong> used to manage externalized settings such as environment configurations, database connections, and custom properties.</p><p>The challenge arises in how to handle or read these properties efficiently and professionally. The solution is the <strong><em>@ConfigurationProperties </em></strong>annotation, which allows developers to map external configurations directly to Java objects.</p><p>As usual, this article begins by addressing three key questions: <strong><em>what, why, and how</em></strong>, followed by an example. It explores the purpose, usage, and benefits of utilizing <strong><em>@ConfigurationProperties </em></strong>for managing application configurations. So, let’s dive in!</p><h3>1. What is @ConfigurationProperties Annotation?</h3><p>While discussing this section, we need to explore the use of the @Value annotation and understand its distinctions from other approaches. To do so, we can divide this section into three parts:</p><ol><li>What is the @Value annotation?</li><li>What is the @ConfigurationProperties annotation?</li><li>The key differences between @Value and @ConfigurationProperties.</li></ol><p>Let’s dive into each part.</p><h4>a. What is @Value annotation?</h4><p>The @Value annotation in Spring Boot is used to inject values from external sources like properties files (application.properties or application.yml), environment variables, or system properties into Spring-managed components (beans). It allows you to wire configuration values into your application easily.<br>Example:</p><pre>import org.springframework.beans.factory.annotation.Value;<br>import org.springframework.stereotype.Component;<br><br>@Component<br>public class AppConfig {<br>    // Injecting property value<br>    @Value(&quot;${app.name}&quot;)<br>    private String appName;<br>    @Value(&quot;${app.version}&quot;)<br>    private String appVersion;<br>    // Method to display values<br>    public void printAppInfo() {<br>        System.out.println(&quot;App Name: &quot; + appName);<br>        System.out.println(&quot;App Version: &quot; + appVersion);<br>    }<br>}</pre><h4>b. What is @ConfigurationProperties Annotation?</h4><p>The <strong><em>@ConfigurationProperties </em></strong>annotation in Spring Boot is used to link or bind external configuration properties defined in <strong><em>application.properties</em></strong> or <strong><em>application.yml</em></strong> to a Plain Old Java Object (POJO).</p><p>This simplifies the management of application-specific settings, ensuring a clean and organized approach.</p><p><strong>Key Features</strong>:</p><ol><li>Lets you directly map configuration values to fields in a Java object.</li><li>Works with nested properties and complex data structures.</li><li>Provides type safety with strong validation of properties when the application starts.</li></ol><h4>c. Difference between @Value and @ConfigurationProperties annotations.</h4><p><strong>@Value Annotation</strong></p><ul><li>Used for injecting individual values from properties files or environment variables.</li><li>Simple and direct, ideal for one-off injections or when only a few properties are needed.</li><li>Injects a specific property using the property key.</li></ul><p><strong>@ConfigurationProperties Annotation</strong></p><ul><li>Used to bind a group of related properties to a Java object.</li><li>More powerful for handling multiple, structured properties (e.g., nested properties) at once, and useful for managing complex configurations.</li><li>Binds an entire class to a set of related properties, usually with a common prefix.</li></ul><h3>2. Why Use @ConfigurationProperties Annotation?</h3><p>Using <strong><em>@ConfigurationProperties </em></strong>provides several advantages:</p><ul><li>Application configurations are decoupled from the business logic, promoting cleaner code.</li><li>Unlike reading configuration values directly from Environment or <strong><em>@Value</em></strong> , <strong><em>@ConfigurationProperties </em></strong>ensures that properties are bound to types correctly.</li><li>It allows for grouping related configurations together under a specific prefix, making the properties easier to manage and understand.</li></ul><h3>3. How @ConfigurationProperties Works</h3><p>At its core, <strong><em>@ConfigurationProperties </em></strong>maps property values defined in the configuration file (like application.yml or application.properties) to fields in a Java class. The key aspect is that you specify a prefix for properties to be bound.</p><p>Let’s walk through an example where we use <strong><em>@ConfigurationProperties </em></strong>to load application-specific settings.</p><h3>4. Example: Using the @ConfigurationProperties Annotation in Spring Boot</h3><blockquote>Note:The dependencies used in this project are <strong>Spring Boot Starter Web</strong> and <strong>Lombok</strong>.</blockquote><h4><strong>Step 1: Define Configuration Properties in </strong><strong>application.properites file.</strong></h4><p>In this example, we configure the name, description, and version of an application. These are the properties we want to map.</p><p><strong>application</strong>.<strong>properties</strong></p><pre>spring.application.name=ConfigMaster<br><br>app.name=ConfigApp<br>app.description=A site for config management<br>app.version=1.0</pre><h4><strong>Step 2: Create a POJO to Bind the Properties</strong></h4><pre>package com.configmaster.config;<br><br>import lombok.Data;<br>import org.springframework.boot.context.properties.ConfigurationProperties;<br>import org.springframework.context.annotation.Configuration;<br><br>@Configuration<br>@Data<br>@ConfigurationProperties(prefix = &quot;app&quot;)<br>public class AppProperties {<br>    private String name;<br>    private String description;<br>    private String version;<br>}</pre><p>In this class, the <strong><em>@ConfigurationProperties </em></strong>annotation indicates that the properties with the prefix &quot;app&quot; should be bound to the fields of AppProperties.</p><h4>Step 3: Injecting the Configuration in Your Application</h4><p>Now, you can inject the AppProperties class wherever it’s needed. For instance, in a controller or service class, you can access the configuration values:</p><pre>package com.configmaster.api;<br><br>import com.configmaster.config.AppProperties;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.RequestMapping;<br>import org.springframework.web.bind.annotation.RestController;<br><br>@RestController<br>@RequestMapping(&quot;/config&quot;)<br>public class ConfigTestApiEndPoint {<br>    private final AppProperties appProperties;<br><br>    @Autowired<br>    public ConfigTestApiEndPoint(AppProperties appProperties) {<br>        this.appProperties = appProperties;<br>    }<br><br>    @GetMapping(&quot;/info&quot;)<br>    public String getAppInfo() {<br>        return &quot;App Name: &quot; + appProperties.getName() +<br>                &quot;, Description: &quot; + appProperties.getDescription() +<br>                &quot;, Version: &quot; + appProperties.getVersion();<br>    }<br>}</pre><p>The @<strong><em>ConfigTestApiEndPoint</em></strong> class accesses the properties defined in <strong><em>AppProperties</em></strong> and can return them as part of a REST endpoint.</p><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XrabgrCGw73BR5FEi8q22A.png" /></figure><h3>Conclusion</h3><ul><li>The @ConfigurationProperties annotation in Spring Boot offers a powerful and flexible way to manage external configuration properties.</li><li>It promotes better separation of concerns by decoupling configuration from business logic, ensures type safety, and allows for easy validation of property values.</li><li>By leveraging this annotation, you can keep your code clean, maintainable, and scalable, making it a crucial part of modern Spring Boot applications.</li><li>For any project that requires organized management of configuration data, @ConfigurationProperties is a must-use tool!</li></ul><p>Github URL: <a href="https://github.com/MyArticleHub/ConfigMaster">https://github.com/MyArticleHub/ConfigMaster</a></p><p>Thank you so much for reading! Feel free to leave a comment if you have any questions. Have a wonderful day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=674550f51f9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Cloud Run: What, Why and How ]]></title>
            <link>https://medium.com/@midhunbalan.dev/google-cloud-run-what-why-and-how-806e048df811?source=rss-909d5ab7ec2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/806e048df811</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[google-cloud-run]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Midhun Balan]]></dc:creator>
            <pubDate>Wed, 06 Dec 2023 17:25:48 GMT</pubDate>
            <atom:updated>2024-07-17T06:58:11.200Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Cloud Run: What, Why and How</h3><p>Google Cloud provides many features, and one of them is Google Cloud Run. This article is tailored specifically for beginners seeking to acquire knowledge about Google Cloud Run, providing a comprehensive and accessible guide to facilitate their learning journey. Whenever I embark on learning new topics, I conscientiously consider these three questions — what, why, and how — guiding my efforts to comprehensively understand and address each aspect. In this article, I will endeavor to address these three questions and illustrate concepts through a few examples.</p><h3>1. What is Google Cloud Run?</h3><p>When we explore the Google Cloud cheat sheet’s compute section, we will encounter the following options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jbV7khneMZ579GpQmiFwwg.png" /><figcaption>img 1: Google cloud compute options*</figcaption></figure><p>Cloud Run is a compute option provided by the Google Cloud Platform, representing a fully managed compute platform. This innovative solution from Google Cloud enables you to seamlessly run containerized applications in a serverless environment.</p><p>Here, you might find yourself pondering over two terms. What does “containerized application” signify? And what is the essence of a “serverless environment”?</p><p>We will go one by one.</p><h3>1.1 What does “containerized application” signify?</h3><p>Containerized applications are applications that run within an isolated package of code called containers. These containers include all the dependencies that an application might need to run on any host operating system, such as libraries, configuration files, and frameworks, amalgamated into a single lightweight executable file.</p><p>Here, we are not delving deep into the Docker aspect but will cover the basics.</p><p>Docker is a containerization platform used to package applications. It is a tool designed to simplify the creation, deployment, and execution of applications by utilizing containers.</p><p>Docker comes into play during the deployment stage.</p><p>When you examine the SDLC (Software Development Life Cycle), containerization (Dockerfile) becomes a part of the build phase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U9J3UfqiDhaUIrTyMd3mJg.png" /><figcaption>img 2: Container/Docker file in SDLC life cycle</figcaption></figure><h3>1.2 What is the essence of a “serverless environment”?</h3><p>Serverless is a cloud-native development model enabling developers to construct and execute applications without the need to oversee servers.</p><p>In the context of Cloud Run, it is designed to simplify the deployment and management of applications for developers, alleviating concerns about the underlying infrastructure.</p><h3>1.3. Key Features</h3><p>Here are the key features of google cloud run.</p><ul><li>Automatically scale your application in response to incoming requests. → It scale down to zero when there is no traffic → Reducing costs and optimizing resource utilization</li><li>Pay as you go pricing model makes it cost effective for various workloads</li><li>Can be integrated with continuous integration and continuous deployment (CI/CD) pipelines to automate the deployment of containerized applications.</li><li>Provides automatic and built-in load balancing to distribute incoming requests across multiple instances of your application.</li><li>Authentication and AuthorizationYou can use Google Cloud Identity-Aware Proxy (IAP) for authentication and Cloud Identity and Access Management (IAM) for authorization to secure your applications running on Cloud Run.</li><li>You can manage configuration and secrets by using environment variables and Google Cloud Secret Manager.</li><li>Cloud Run can be easily integrated with other Google Cloud services, such as Cloud Storage, Cloud Firestore, and Cloud Pub/Sub, to build a variety of cloud-native applications.</li></ul><h3>2. Why do we need cloud run?</h3><p>Developers are encouraged to explore Google Cloud Run as it heralds a paradigm shift in the deployment and management of applications, presenting an immersive and transformative journey in the realm of development.</p><ul><li><strong>Focus on Innovation, Not Infrastructure</strong>: Cloud Run liberates developers from the burdens of managing servers, allowing them to concentrate solely on building robust, scalable applications. By eliminating infrastructure concerns, developers can allocate more time and energy to crafting innovative solutions and enhancing user experiences.</li><li><strong>Streamlined Deployment Process</strong>: With Cloud Run, deployment becomes seamless. Developers can swiftly deploy containerized applications without grappling with the complexities of configuring and maintaining servers. This streamlined process enables quicker iterations and faster time-to-market for new features and updates.</li><li><strong>Scalability Without Complexity</strong>: The auto-scaling nature of Cloud Run ensures applications can effortlessly handle fluctuating traffic demands. Developers don’t need to worry about scaling configurations; the platform dynamically adjusts resources, ensuring optimal performance without manual intervention.</li><li><strong>Optimized Cost Structure</strong>: The pay-as-you-go model of Cloud Run translates into cost efficiency. Developers only pay for the resources consumed during application execution, eliminating the need to provision and pay for idle resources. This cost optimization is especially beneficial for startups and businesses with varying traffic patterns.</li><li><strong>Global Accessibility and Reliability</strong>: Google’s infrastructure spans the globe, allowing developers to deploy applications closer to users for reduced latency and improved performance. Additionally, the reliability of Google Cloud ensures high availability, enabling developers to provide consistent services to users across different regions.</li><li><strong>Developer Empowerment and Agility</strong>: Cloud Run empowers developers by providing a platform that fosters agility. Its compatibility with container technology allows for flexibility and portability across various environments, ensuring that developers have the freedom to innovate without constraints.</li><li><strong>Future-Ready Infrastructure</strong>: By embracing a container-based approach, Cloud Run future-proofs applications. Developers can easily transition and scale applications across different cloud environments or on-premises setups, ensuring flexibility and adaptability as technology landscapes evolve.</li></ul><p>However, Cloud Run may not be the best choice for all scenarios. Here are cases where you might want to consider alternative hosting options:</p><ul><li><strong>Stateful Applications</strong>: If your application relies on maintaining state on the server, such as in-memory caches, session data, or local file storage, Cloud Run is not suitable. State should be managed externally.</li><li><strong>Long-Running Background Tasks</strong>: Cloud Run is designed for short-lived HTTP requests, and it may not be the best choice for running long-running background processes or batch jobs.</li><li><strong>Highly Customized Infrastructure</strong>: If your application has very specific infrastructure requirements that cannot be met within Cloud Run’s constraints, you may need a more customizable solution like Google Kubernetes Engine (GKE) or Compute Engine.</li><li><strong>Complex Networking Configurations</strong>: For applications requiring complex networking configurations, like VPNs, custom subnets, or custom load balancers, other Google Cloud offerings might be more suitable.</li></ul><p>The decision to use Google Cloud Run should be based on your specific application’s requirements, scalability needs, and architectural considerations. It’s essential to evaluate whether Cloud Run aligns with your use case and desired operational model.</p><h3>3. How to use google cloud run?</h3><p>Note: It is possible to deploy to Google Cloud Run using containerization. However, if you prefer not to use containerization, you can deploy directly to Google Cloud Run using the <strong>gcloud</strong> command. We will see both options in this article.</p><p>Below are the steps you need to follow to create and deploy a Google Cloud Run project.</p><p><strong>Prerequisites</strong>:</p><ul><li>You must have a Google account, create a Google Cloud Project, and enable billing for the project.</li><li>Make sure that the necessary APIs, like the Cloud Run API, are enabled for your project</li><li>If you haven’t already, install the Google Cloud CLI (gcloud) and configure it with your project and preferred region.</li></ul><p><strong>Steps</strong>:</p><ul><li>Configure containerization for your project.</li><li>Containerize your application using docker</li><li>Push your container image to Artifact Registry.</li><li>From the Google Cloud Run dashboard, select the container image and deploy it to Cloud Run.</li></ul><p>Here we are going to see how to deploy a react application to the google cloud run. These are the steps we have to follow to achieve that.</p><ol><li>Create a react project and add Dockerfile and nginx configuration to it.</li><li>Build the react application using the configuration and run it in localhost.</li><li>Once it is working fine in localhost, push the docker image file to artifact registery and deploy it to the cloud run.</li></ol><p>Let’s go…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*HLuSfZeL9m4sdstgmhiA_A.gif" /></figure><h3>3.1 Create a react project and add Dockerfile and nginx configuration to it.</h3><p>Here i have added a small react project(using npx create-react-app) to display the current date and time, and the time will change every second.</p><p>Here is the sample code for that.</p><pre>import { useEffect, useState } from &quot;react&quot;;<br>import &quot;./App.css&quot;;</pre><pre>function App() {<br>  let [date, setDate] = useState(new Date());<br>  useEffect(() =&gt; {<br>    let timer = setInterval(() =&gt; setDate(new Date()), 1000);<br>    return function cleanup() {<br>      clearInterval(timer);<br>    };<br>  });<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;p&gt; Date: {date.toLocaleDateString()} &lt;/p&gt;<br>      &lt;h2&gt; Time:{date.toLocaleTimeString()} &lt;/h2&gt;<br>    &lt;/div&gt;<br>  );<br>}<br>export default App;</pre><p>Once that is done, you have to add the following configuration in your project</p><ol><li>Docker configuration, and</li><li>nginx configuration</li></ol><p><strong>Docker configuration</strong></p><p>In your project root, create a file with the name Dockerfile and add the following lines there</p><pre>FROM node:16.15.1 as build<br>WORKDIR /app<br>COPY package*.json .<br>RUN npm install<br>COPY . . <br>RUN npm run build<br><br><br>FROM nginx:1.19 <br>COPY ./nginx/nginx.conf /etc/nginx/nginx.conf<br>COPY --from=build /app/build /usr/share/nginx/html<br>EXPOSE 8080</pre><p><strong>nginx configuration</strong></p><pre>worker_processes  1;<br><br>events {<br>  worker_connections  1024;<br>}<br>http {<br>  server {<br>    listen 8080;<br>    server_name  localhost;<br>    root   /usr/share/nginx/html;<br>    index  index.html index.htm;<br>    include /etc/nginx/mime.types;<br>    gzip on;<br>    gzip_min_length 1000;<br>    gzip_proxied expired no-cache no-store private auth;<br>    gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;<br>    location / {<br>      try_files $uri $uri/ /index.html;<br>    }<br>  }<br>}</pre><p>Source code for your reference:</p><pre>https://github.com/MidhunBalan/gcp_cloud_run_example/tree/main/react-timer</pre><h3>3.2 Build the react application using the configuration and run it in localhost.</h3><p>Use the following commands to run this project through Docker</p><pre>To Build The Application<br>	docker build -t app .<br>To Run Docker App<br>	docker run -p 8080:8080 app</pre><p>Note: If you are using m1 or m2 or m3 chip, you must use the below command to build it.</p><pre>docker buildx build  --platform linux/amd64  -t app .</pre><p>Once you succesfully build the docker app, you can open your docker desktop and check whether your app is running or not and simply type <a href="http://localhost:8080/">localhost:8080</a> in your browser and see the app running fine in your localhost.</p><h3>3.3 Push the docker image file to artifact registery and deploy it to the cloud run.</h3><p>Here we are going to use the gcloud commands. Make sure that you have gcloud installed in your machine.</p><p><strong>Step1:</strong> Enable google cloud artifactregistry service through gcloud command</p><pre>gcloud services enable artifactregistry.googleapis.com</pre><p>Step2: Create artifact repository with a name</p><pre>gcloud artifacts repositories create {repo-name} --repository-format=docker --location=us-central1 --description=&quot;created repo&quot;</pre><p>Step3: Configure and upload/push the docker image t</p><pre>gcloud auth configure-docker us-central1-docker.pkg.dev<br><br>docker tag {local-image-name} us-central1-docker.pkg.dev/{project-name}/{repo-name}/{gcp-image-name}<br><br>docker push us-central1-docker.pkg.dev/{project-name}/{repo-name}/{gcp-image-name}</pre><p>Once you pushed your changes to artifact registry, you can open the gcloud artifact registry page and simply click on the image and deploy to google cloud run.</p><blockquote><strong>Additional Notes: <br></strong>Is it possible to deploy to the google cloud run without using docker?<br>Yes. It is possible. <br>Google has already provided a splendid documentation on this topic. Within the following article, you’ll discover a step-by-step guide on deploying a Node.js application to Google Cloud Run without the need for Docker. <a href="https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-nodejs-service">https://cloud.google.com/run/docs/quickstarts/build-and-deploy/deploy-nodejs-service</a></blockquote><p>That encapsulates the essence of this topic. Welcome your thoughts and feedback below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=806e048df811" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>