Deploying to GCP

Hi Strapi Community,

Has anyone successfully deployed Strapi V4 to GCP App Engine?
I followed the instructions in the deployment guide but I am having no luck, I keep hitting the server wasn’t able to start properly error on GCP.

Below listed are few issues I am facing.

  1. The guide describes that I need to make a database.js file in ./config/env/production/ directory. However I noticed that the database file in the production directory is ignored, and database file in ./config/ is referenced (dev database.js).

./config/database.js

module.exports = ({ env }) => ({
  connection: {
    client: 'postgres',
    connection: {
      host: env('DATABASE_HOST', '0.0.0.0'),
      port: env.int('DATABASE_PORT', 5433),
      database: env('DATABASE_NAME', 'strapi'),
      user: env('DATABASE_USERNAME', 'strapi'),
      password: env('DATABASE_PASSWORD', 'secret'),
      ssl: env.bool('DATABASE_SSL', false),
    },
  },
});

./config/env/production/database.js

module.exports = ({ env }) => ({
    connection: {
      client: 'postgres',
      connection: {
        host: `/cloudsql/${env('INSTANCE_CONNECTION_NAME')}`,
        database: env('DATABASE_NAME'),
        user: env('DATABASE_USER'),
        password: env('DATABASE_PASSWORD'),
      },
    },
  });

the ./app.yaml file

service: strapi
runtime: nodejs16

instance_class: F2

env_variables:
  HOST: '0.0.0.0'
  NODE_ENV: 'production'
  DATABASE_NAME: 'strapi'
  DATABASE_USERNAME: 'strapi'
  DATABASE_PASSWORD: 'secret'
  INSTANCE_CONNECTION_NAME: 'instance-name-on-gcp-postgres-db'

beta_settings:
  cloud_sql_instances: 'instance-name-on-gcp-postgres-db'
  1. Due to above, I replaced the references in dev database.js with the production version.
  2. the latest error is showing the following -
"GET / HTTP/1.1" 500
2022-09-13 20:01:31 strapi[20220913t205411]  dev database file called!
2022-09-13 20:01:33 strapi[20220913t205411]  [2022-09-13 20:01:33.395] debug: ⛔️ Server wasn't able to start properly.
2022-09-13 20:01:33 strapi[20220913t205411]  [2022-09-13 20:01:33.397] error: no PostgreSQL user name specified in startup packet
2022-09-13 20:01:33 strapi[20220913t205411]  error: no PostgreSQL user name specified in startup packet
2022-09-13 20:01:33 strapi[20220913t205411]      at Parser.parseErrorMessage (/workspace/node_modules/pg-protocol/dist/parser.js:287:98)
2022-09-13 20:01:33 strapi[20220913t205411]      at Parser.handlePacket (/workspace/node_modules/pg-protocol/dist/parser.js:126:29)
2022-09-13 20:01:33 strapi[20220913t205411]      at Parser.parse (/workspace/node_modules/pg-protocol/dist/parser.js:39:38)
2022-09-13 20:01:33 strapi[20220913t205411]      at Socket.<anonymous> (/workspace/node_modules/pg-protocol/dist/index.js:11:42)
2022-09-13 20:01:33 strapi[20220913t205411]      at Socket.emit (node:events:527:28)
2022-09-13 20:01:33 strapi[20220913t205411]      at Socket.emit (node:domain:475:12)
2022-09-13 20:01:33 strapi[20220913t205411]      at addChunk (node:internal/streams/readable:315:12)
2022-09-13 20:01:33 strapi[20220913t205411]      at readableAddChunk (node:internal/streams/readable:289:9)
2022-09-13 20:01:33 strapi[20220913t205411]      at Socket.Readable.push (node:internal/streams/readable:228:10)
2022-09-13 20:01:33 strapi[20220913t205411]      at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

Regardless how I got here trying to patch the issues, the instructions on the guide page doesn’t work, even on a fresh install.



[details="System Information"]
- **Strapi Version**: 4.3.8
- **Operating System**: Mac Os 12.5
- **Database**: Postgres 13
- **Node Version**: * v14.15.5
- **NPM Version**: 6.14.11
- **Yarn Version**: 1.22.18
[/details]

---

okay, this was weird one.

I managed to fix it, but there is a much more pressing issue, which is that the database you would configure for production is somewhat useless.

The fix was simple, I changed the port in my ./config/database.js file from 5433 to 5432.
As I keep noticing, these issues didn’t exist for Strapi 3.x.x

Whilst my deployment of Strapi V4 has a ./config/env/production/database.js file, which doesn’t require a port as GAE use instance name, it still looks for a port, and I guess the only file the port was in is ./config/database.js file.

This begs the question, what is the ./config/env/production/database.js file doing, and do we now need to set up a port? is it really working?

If this is the case, then the only port number that works is 5432, which raises bunch of more concerns.

Been looking around the community a lot and V4 is not well supported compared to V3, the community is struggling to get common functionality that worked previously on V3 working on V4.

Hope this helps anyone else in the future!