DEV Community

Cover image for Deploying a Shopify Node App Docker Image to GCP
Dean Andreakis
Dean Andreakis

Posted on

Deploying a Shopify Node App Docker Image to GCP

In my last post I showed how to take a Shopify node app and dockerize it. In this post I will show you how to take that docker image and deploy it to GCP using Google Artifact Registry and Google Cloud Run services. I will also show the Shopify app configuration, installation and execution in a Shopify development store used for testing.

Prerequisites

We will assume that:

  1. A GCP account has been created at console.cloud.google.com
  2. A project has been created in GCP for your Shopify app
  3. The gcloud CLI has been installed
  4. The docker CLI has been installed

Setup Google Cloud Platform (GCP)

We will first setup GCP to accept and store the docker container image and then to deploy and run that image on Google Cloud Run.

An overview of these steps can be found here but I will show the specific commands for my dockerized Shopify node app named "shnode":

  • In IAM add the Artifact Registry Administrator role to your GCP user.
  • Go to the Artifact Registry service and make sure the API is enabled.
  • In the Artifact Registry select the "create a repository" button. Make sure you select type "Docker" for the repository type.
  • Authenticate to the repository as follows:
gcloud auth configure-docker us-west4-docker.pkg.dev
Enter fullscreen mode Exit fullscreen mode

where us-west4-docker.pkg.dev is the location of the repository we created. We can see this information in the list of repositories:
Screen Shot 2021-09-09 at 4.59.13 PM

  • Tag your docker image as follows:
docker tag shnode us-west4-docker.pkg.dev/shopify-319117/shnode/shnode:1.0
Enter fullscreen mode Exit fullscreen mode

where the format is us-west4-docker.pkg.dev/my-gcp-project/my-repo/my-image:tag1

  • Push the container to GCP Artifact Registry:
docker push us-west4-docker.pkg.dev/shopify-319117/shnode/shnode:1.0
Enter fullscreen mode Exit fullscreen mode
  • Create a GCP Cloud Run service: Go to GCP Cloud Run and select the "create a service" button. Once you create a service you will be able to see the URL of the service. We will refer to this URL as HOST in the next section where we setup the Shopify app itself:
    Screen Shot 2021-09-09 at 5.33.46 PM

  • Deploy the image to GCP Cloud Run and start it up:

gcloud run deploy --image us-west4-docker.pkg.dev/shopify-319117/shnode/shnode:1.0
Enter fullscreen mode Exit fullscreen mode

Setup Shopify App

The Shopify node app must be setup properly in order for it to be installed and executed in a Shopify store. We will assume that the Shopify app has already been created in your Shopify partner account.

  • Go to the App setup page for your app in your Shopify partner account and make sure the URL's in the URLs section match the HOST URL from above when we created the GCP Cloud Run service: Screen Shot 2021-09-09 at 5.23.46 PM
  • In your Shopify partner account install the app to your development store using the "test your app" section of the app details page: Screen Shot 2021-09-09 at 5.44.01 PM
  • The Shopify app source tree itself includes a .env file that has a HOST environment variable. Make sure this matches the HOST URL from above when we created the GCP Cloud Run service. If you update this .env file then you will have to rebuild your docker image and re-deploy. To rebuild go to the root of your Shopify app source tree and issue the following command:
docker build -t shnode .
Enter fullscreen mode Exit fullscreen mode

where "shnode" is the image name. At this point you can continue the deployment from the above section "Setup Google Cloud Platform (GCP)" where we tag the docker image.

Top comments (0)