# Google App Engine

✋ CAUTION

This third-party deployment guide might not be up-to-date with Strapi v4. Contributions (opens new window) are most welcome.

In this guide we are going to:

# New Strapi project

When the setup completes, register an admin user using the form which opens in the browser. This user will be only relevant in local development.

The sqlite database is created at .tmp/data.db.

Login, but don't add content-types yet. Close the browser. Quit the running app.

# Initial commit

This may be a good point to commit the files in their initial state.

cd my-project
git init
git add .
git commit -m first

# Install the Cloud SDK CLI tool

Cloud SDK: Command Line Interface (opens new window)

# New App Engine project

Create a new App Engine (opens new window) project.

Select the region, such as europe-west.

  • Language: Node JS
  • Environment: Standard (or Flexible)

(A note on performance and cost: the Standard Environment is sufficient for development, but it may not be for production. Review the resources your application will need to determine the cost. When you sign up for Google App Engine, it offers a certain amount of free credits which will not be billed.)

Create the project. Take note of the instance identifier, which is in the form of <instance_id>:<region>:<instance_name>.

Check if gcloud lists the project:

gcloud projects list

Run init to authenticate the cli, and select current cloud project.

gcloud init

# Create the database (PostgreSQL)

Create the Cloud SQL database (opens new window) which the app is going to use.

Take note of the user name (default is postgres) and password.

The first database will be created with the name postgres. This cannot be deleted.

Create another database, named strapi for example. It may be useful to delete and and re-create this while you are experimenting with the application setup.

# Create app.yaml and .gcloudignore

Create the app.yaml file in the project root.

The instance identifier looks like myapi-123456:europe-west1:myapi.

The myapi-123456 part is the project identifier. (The number is automatically added to short project names).

The following is an example config for Standard Environment or Flexible Environment.

Create .gcloudignore in the project root.

.gcloudignore
.git
.gitignore
node_modules/
#!include:.gitignore
!.env
yarn.lock  # If you're using Yarn

In the case of Strapi, the admin UI will have to be re-built after every deploy, and so we don't deploy local build artifacts, cache files and so on by including the .gitignore entries.

# Adding .gitkeep to database folder

Google App Engine does not give mkdir permissions and the database/migrations folder is required for deployments. Make sure git keeps track of the database/migrations folder by adding a .gitkeep file to the folder. Use the following command:

touch .gitkeep

# Configure the database

The PostgreSQL database will need the pg package.

yarn add pg

Adding the production database configuration for connect to GCP SQL.

# Auto-build after deploy

After deployment, the admin UI has to be re-built. This generates the contents of the build folder on the server.

In package.json, add the gcp-build command to scripts:

{
  "scripts": {
    "gcp-build": "strapi build"
  }
}

# Deploy

gcloud app deploy app.yaml --project myapi-123456

Watch the logs:

gcloud app logs tail --project=myapi-123456 -s default

Open the admin page and register and admin user.

https://myapp-123456.appspot.com/admin/

# File uploading to Google Cloud Storage

Lith/strapi-provider-upload-google-cloud-storage (opens new window)

yarn add strapi-provider-upload-google-cloud-storage

Deploy so that the server app includes the dependency from package.json.

Follow the documentation of the plugin (opens new window) for the full configuration.

# Post-setup configuration

CORS

CORS is enabled by default, allowing * origin. You may want to limit the allowed origins.

Read the documentation here.

Changing the admin url

config/env/production/admin.js