Deploy Your Shopify App to Heroku in Seconds

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MyrinNew
    Senior Member
    • Feb 2024
    • 5175

    #1

    Deploy Your Shopify App to Heroku in Seconds

    Deploying a Shopify app to Heroku often turns into a juggling act — managing environment variables, and running separate commands to keep both Shopify and Heroku in sync.


    To simplify this process, I built shopify-heroku-cli a lightweight CLI that syncs your Shopify app’s environment variables with Heroku and deploys your app in just a couple of commands.


    In this post, I’ll show you step-by-step how to deploy your Shopify app to Heroku using the tool.





    1. Prerequisites

    Before we start, make sure you have the following installed and configured:
    • Node.js >= 16
    • Shopify CLI — logged in to your Shopify app
    • Heroku CLI — logged in to your Heroku account
    • A Shopify app ready to deploy
    • A Heroku app created (you can create one with heroku create my-shopify-app)





    2. Install the CLI

    Install the CLI globally using npm:






    npm install -g shopify-heroku-cli








    This makes the shopify-heroku command available system-wide.





    3. Sync Environment Variables

    The first step is to set your Shopify app environment variables on your Heroku app.


    You can do this with a single command:






    shopify-heroku set-env your-heroku-app-name








    This command automatically:
    • Reads your Shopify environment variables
    • Pushes them to your Heroku app
    • Sets SHOPIFY_API_KEY, SHOPIFY_API_SECRET, and SHOPIFY_APP_URL automatically


    If you have multiple Shopify config files (like shopify.app.live.toml), you can specify one:






    shopify-heroku set-env your-heroku-app-name -c live











    4. Create a heroku.yml File

    Next, you’ll need a heroku.yml to tell Heroku how to build your app (using Docker):






    echo -e "build:\n docker:\n web: Dockerfile" > heroku.yml








    Commit the file to your repo:






    git add .
    git commit -m "feat: add heroku yml file"











    5. Deploy to Heroku

    Now you’re ready to deploy your Shopify app:






    shopify-heroku deploy your-heroku-app-name








    This command will:
    • Ensure your Heroku app is configured for container deployment
    • Set up the correct git remote (if missing)
    • Automatically detect your main branch (main or master)
    • Push your code to Heroku for deployment


    Once complete, you can open your app directly:






    heroku open --app your-heroku-app-name











    6. Update the Shopify App URL

    After deployment, you’ll need to update your app URL in your Shopify configuration file (shopify.app.toml) to point to your Heroku domain.


    Example:






    application_url = "https://your-heroku-app-name.herokuapp.com"








    Then deploy your app to Shopify again to update the URL:






    npm run deploy











    7. (Optional) Automate Your Deploy Workflow

    You can easily wrap this workflow into a script inside your package.json:






    "scripts": {
    "deploy:heroku": "shopify-heroku set-env your-heroku-app-name && shopify-heroku deploy your-heroku-app-name"
    }








    Now you can deploy to Heroku with a single command:






    npm run deploy:heroku











    Why This Tool Helps

    Manually deploying a Shopify app to Heroku often means switching between CLIs, copying environment variables, and repeating the same setup steps every time.


    With shopify-heroku-cli, that entire process is automated — letting you focus on building features instead of managing deployment details.





    Get Started

    Install it globally from npm:






    npm install -g shopify-heroku-cli







    Explore the full documentation and source code:


    GitHub: imohamadnashaat/shopify-heroku-cli


    npm: shopify-heroku-cli


    shopify-heroku-cli makes deploying Shopify apps to Heroku faster and simpler by bringing both workflows into one place.


    It’s an open project — feedback, ideas, and contributions are always welcome.


    Happy coding!




    More...
Working...