Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 67

Cloud Deployment Strategies

Recommended resources

Hello again! Congratulations on reaching the final implementation step of our capstone project.

In our last lesson, we built the backend process to fetch and display order customizations for the merchant, effectively closing the loop on our app's core feature. Your Product Customizer app is now feature-complete, connecting a customer-facing customization tool on the product page all the way to a merchant-facing view within your app's dashboard.

Today, we take your app from your local machine to the world. Our learning outcome is to deploy the full-stack application to a cloud hosting provider (e.g., Fly.io, Heroku). This is the crucial final step that transforms your project from a development prototype into a live, portfolio-ready application that could be installed on any Shopify store.

The "Why" of Deployment: Beyond localhost

Throughout this project, you've been running the app locally using npm run dev. This command starts a development server and, thanks to ngrok, creates a temporary, public tunnel to your machine so Shopify's servers can communicate with your app.

This setup is perfect for development, but it's not a permanent solution. For an app to be used by merchants, it needs to live on a production server. Here’s why:

  • Availability: A production server runs 24/7. Your local machine doesn't need to be on and connected to the internet for the app to work.
  • Stability: ngrok tunnels are temporary and can change, which is unsuitable for a live app. A production server provides a stable, permanent URL.
  • Performance & Scalability: Cloud hosting providers are optimized to handle web traffic, manage resources, and can scale up if your app becomes popular.

Your background in IT infrastructure services gives you a head start in understanding these concepts. We are essentially moving our application from a local development environment to a managed, cloud-hosted one. The Shopify CLI app template makes this transition smooth by including a Dockerfile. This file acts as a blueprint to create a standardized, portable container with our Node.js application and all its dependencies, which modern hosting platforms are designed to run.


Choosing a Hosting Provider

There are many excellent cloud platforms to host a Node.js application. Shopify officially provides documentation for several popular choices.

Shopify App Hosting Options
Common cloud hosting providers for Shopify applications. We will focus on Fly.io.

For this lesson, we will focus on Fly.io. It is highly recommended by Shopify, has an excellent free tier that's perfect for portfolio projects, and integrates seamlessly with the Docker-based workflow of the Shopify app template. While Heroku and DigitalOcean are also fantastic options, Fly.io offers a very direct path to getting our app live for free.

Let's begin by understanding the general deployment process.

About deployment

Shopify's official documentation provides a great overview of what deployment entails. This will give you the high-level context before we dive into the specific commands for Fly.io.

Please read the sections 'How it works' and 'Hosting and deployment options'. This will clarify the relationship between your code, the hosting service, and Shopify. Note the providers listed, including the link to Fly.io's documentation.


Hands-On: Deploying Your App to Fly.io

We will now walk through the step-by-step process of deploying your app. The following video provides a clear visual guide for deploying a starter app to Fly.io, Heroku, and DigitalOcean. We will follow the Fly.io portion of it.

How to Host Your Shopify App STEP BY STEP | Fly.io, Heroku, and DigitalOcean

This video by Dev With Alex is an excellent, practical walkthrough of the deployment process. We will use it as our primary guide. We'll focus on the Fly.io deployment, which is covered first.

Please watch the section on deploying to Fly.io (03:20 - 11:24). Follow along with the steps, but pause before running the final 'deploy' command. We will review the environment variable configuration in detail first, as it's the most critical part.

Let's break down the process you just saw in the video into concrete steps.

Step 1: Install Fly.io CLI and Login

First, you need to install the command-line tool for Fly.io and authenticate your machine.

  1. Install flyctl: Follow the instructions on the official Fly.io documentation to install flyctl for your operating system.
  2. Login: Open your terminal in your project's root directory and run flyctl auth login. This will open a browser window for you to sign up or log in to your Fly.io account.

Step 2: Initialize the App on Fly.io

The launch command inspects your project, creates a configuration file, and registers your app with Fly.io's platform.

  1. In your terminal, run: flyctl launch
  2. You will be prompted for a few things:
    • App Name: Choose a unique name for your app (e.g., yourname-product-customizer). This becomes part of its URL.
    • Region: Select a region close to you or your users.
    • Postgres Database: Your app doesn't need a database, so select "No".
    • Deploy now?: Select "No". We need to set up our environment variables first.

This command creates a fly.toml file in your project. This file contains the configuration for your Fly.io deployment.

Step 3: Configure URLs and Secrets

This is the most important step. Your live app needs to know its own public URL and your Shopify API credentials.

  1. Get Your App's Hostname: The flyctl launch command will have reserved a hostname for you, which you can also find in your Fly.io dashboard. It will look like https://<your-app-name>.fly.dev. Copy this URL.

  2. Update Shopify Partner Dashboard:

    • Navigate to your Partner Dashboard > Apps > Your App > App setup.
    • In the "App URL" field, replace the ngrok address with your new Fly.io URL (https://<your-app-name>.fly.dev).
    • In the "Allowed redirection URL(s)", replace the ngrok URL with your new callback URL: https://<your-app-name>.fly.dev/api/auth/callback.
    • Save your changes. Your app will not authenticate without this step.
  3. Set Secrets in Fly.io: API keys and other secrets should never be stored in your fly.toml file or committed to Git. We use Fly.io's secrets manager. Run the following commands in your terminal, replacing the placeholders with your actual values from your project's .env file.

    # Set the public host URL for your app
    flyctl secrets set HOST="https://<your-app-name>.fly.dev"
    
    # Set your Shopify API Key
    flyctl secrets set SHOPIFY_API_KEY="YOUR_SHOPIFY_API_KEY"
    
    # Set your Shopify API Secret
    flyctl secrets set SHOPIFY_API_SECRET="YOUR_SHOPIFY_API_SECRET"
    
    # Set the scopes your app requires
    flyctl secrets set SCOPES="write_products,read_products,read_orders" 
    

    Note: The scopes should match what you have in your .env file.

Test your understanding!

A fellow developer asks you why you're using flyctl secrets set instead of just adding the API keys to the [env] section of the fly.toml file. What is the reason for this?

Show answer

The fly.toml file is typically committed to your Git repository. Placing sensitive credentials like SHOPIFY_API_SECRET in this file would expose them in your source code, which is a major security risk. flyctl secrets set encrypts these values and stores them securely on Fly.io's platform, injecting them into your application's environment only at runtime.

Step 4: Deploy the App

Now that the configuration is complete, you can deploy the application.

  1. In your terminal, run: flyctl deploy

This command will:

  • Read your fly.toml and Dockerfile.
  • Build a container image of your application.
  • Push the image to Fly.io's registry.
  • Start the application container in the cloud.

This process may take several minutes.

Step 5: Verify the Deployment

Once the deploy command finishes successfully:

  1. Go to your development store's Shopify Admin.
  2. Navigate to the "Apps" section and open your Product Customizer app.
  3. The app should load just as it did locally, but now it's being served from your live fly.dev URL. You can open your browser's developer tools and check the Network tab to confirm that the requests are going to your Fly.io address.

Congratulations! Your app is now live on the internet.


Conclusion

You have successfully taken your full-stack Shopify application from a local development environment and deployed it to a production-ready cloud host. This is the final and most critical step in making your software available to users and is a massive achievement.

Key Takeaways:

  • Deployment moves an app from a temporary development server to a permanent, stable, and publicly accessible hosting environment.
  • Modern hosting providers like Fly.io use containerization (via a Dockerfile) to package and run applications consistently.
  • The critical deployment workflow involves initializing the app (flyctl launch), configuring its public URL in the Shopify Partner Dashboard, securely setting environment secrets (flyctl secrets set), and finally, deploying the code (flyctl deploy).

You have now built and deployed a complete, end-to-end solution—a testament to your full-stack capabilities and a fantastic project for your freelance portfolio.


Next Steps

Your app is now a functioning, deployed piece of software. The final step in preparing this for your portfolio is to ensure it's well-documented. In our very last lesson, we will focus on the final learning outcome: Write clear documentation for the project to include in a professional portfolio. This will involve creating a high-quality README.md file for your project's GitHub repository, explaining what the app does, how it works, and how to set it up.