This is me, André König - a software engineer from Hamburg, Germany. André König

  • Apr 19, 2024
  • 4 Min Read
  • Remix

Deploy a Remix App on Google Cloud Run

Scalable and Cost-Sensitive Deployment in Two Simple Steps

When deploying web applications, you encounter a vast array of choices. Generally, providers align into two categories: those providing extensive configuration options and those favoring a simpler "push & deploy" method.

Specifically regarding Remix, Jacob Paris authored an insightful article detailing hosting options for Remix applications in 2024. I highly recommend reading it to gain a comprehensive overview of the landscape.

While reading the article, you'll observe that nearly all the showcased providers lean towards the "push & deploy" model, with none representing the major cloud providers. Why, you might wonder? It boils down to Developer Experience! It's all about ramping up the velocity of you and your team. The highlighted providers are renowned for excelling in this aspect. As for the major cloud providers? Well, to be frank, they fall short in this regard.

A superior developer experience directly correlates with increased velocity for you and your team, ultimately boosting the 'feature to market' rate.

The major providers are more flexible, though, but the caveat is that you have to find your way through the jungle and fight with container images, container registries, scaling groups, the decision which orchestrator you want to use, etc.

But it doesn't have to be that way. Let me show you a way of deploying a Remix application on a major cloud provider without scarifying the developer experience:

In this short article, we will deploy a Remix application on Google Cloud Run in two simple steps.

Step 1: The initial setup

Major cloud providers are famous for their extensive permission systems, and the Google Cloud Platform is no exception. Admittedly, this is the most cumbersome part of the whole journey, but the good thing is, you only have to do it once.

Open your Cloud Shell and paste the following command into it (make sure to adjust the environment variable to suit your needs):

export PROJECT_ID=<your-project-id>
# e.g. europe-west1
export REGION=<your-region>
export APP_NAME=<your-app-name>
#
# Enable all required Google Cloud APIs
#
gcloud services enable artifactregistry.googleapis.com
gcloud services enable run.googleapis.com
gcloud services enable cloudbuild.googleapis.com
#
# Create a service account and bind the required roles to it
#
gcloud iam service-accounts create github-actions
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:github-actions@$PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/artifactregistry.admin"
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:github-actions@$PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/cloudbuild.builds.editor"
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:github-actions@$PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/run.admin"
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:github-actions@$PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/iam.serviceAccountUser"
gcloud projects add-iam-policy-binding $PROJECT_ID \
--member="serviceAccount:github-actions@$PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/storage.admin"
#
# Create a key file so that your GitHub Action can interact with the GCP
#
gcloud iam service-accounts keys create credentials.json \
--iam-account=github-actions@$PROJECT_ID.iam.gserviceaccount.com

The last command creates a key file, which you need for the configuration of the GitHub Actions workflow. So perform a cat credentials.json and copy the contents.

Step 2: Install your GitHub Actions workflow via getactions.dev

Open your terminal on your local machine and execute:

curl -s https://getactions.dev/deployment/google-cloud-run | sh

The installation script will ask you for:

  1. The name of your application.
  2. The region of your application (from Step 1).

Afterward, go to your repository settings on GitHub: Settings → Secrets and variables → Actions and create these two secrets:

  • GCP_PROJECT_ID: Your project ID (from Step 1)
  • GCP_CREDENTIALS: The key file of the created service account (from Step 1)

We're done. Now, when you commit these changes and push into the remote main branch, you will see that the GitHub Actions workflow will run and deploy your application accordingly.

The URL of the service will be visible in the workflow output as well.

Conclusion

In conclusion, with a modest initial setup, you can establish a seamless deployment pipeline for your Remix application on Google Cloud Run. If you prefer not to use a service account for the connection between your GitHub Actions workflow and the Google Cloud, I suggest you check out my article about Workload Identity Federation on GCP.


Thank You

I hope that you found this article insightful and valuable for your journey. If so, and you learned something new or would like to give feedback then let's connect on X at @ItsAndreKoenig. Additionally, if you need further assistance or have any queries, feel free to drop me an email or send me an async message.

One last thing!

Let me know how I'm doing by leaving a reaction.


You might also like these articles