By default, Ghost uses a local SQLite database, and the filesystem as a storage.
In order to run Ghost as a "Stateless" app in Google Cloud Run, we need to:
- Use an external MySQL database
- Use an external storage engine
You can use whichever you want, Google Cloud MySQL, Amazon RDS, Azure MySQL, Compose MySQL, etc. I recommend using Google Cloud MySQL if you don't mind paying a small fee, to keep everything with the same provider. Personally, I chose Amazon RDS while developing, for their generous 12-months free tier. However, when I'll be ready for production, I will move to Google Cloud MySQL.
You can choose Google Cloud Storage (using ghost-v3-google-cloud-storage), Amazon S3 (using ghost-storage-adapter-s3), or any other storage adapter they support. Since we'll be running in Google Cloud Run, I recommend using Google Cloud Storage. This is what this example uses.
GCLOUD_PROJECT_ID=your-project-id sh push.sh
Now your image is waiting in your Google Container Registry, and ready to use by Google Cloud Run.
You will need to set some environment variables in your Google Cloud Run service before creating it. If you take a look at ./config.production.json
, you will see that the url
, the MySQL connection configs are needed, as well as the GCS bucket. Since Ghost uses nconf, you can easily set them as environment variables:
url = www.mydomain.com
database__connection__host = my-db.us-east-xyz.rds.amazonaws.com
database__connection__database = my-db
database__connection__user = my-db-user
database__connection__password = my-db-pass
storage__gcs__bucket = my-google-bucket
Refer to Ghost Configuration Docs for more info.
Note about url
: With Google Cloud Run, you can map your service to a custom domain. If you know in advance what it'll be, you can already set it. Otherwise, you can set it to your service's URL then restart it.
That's it! You are now running a FREE (if you used AWS RDS) Ghost blog on Google Cloud ๐