Strapi Cloud Deployment Error - Connection Issue with Postgres on GCP

[details=“System Information”]

  • Strapi Version: 4.7.0
  • Operating System: Strapi Cloud
  • Database: PostGres 14 - GCP
  • Node Version: v16.20.0
  • NPM Version: 8.19.4

I recently subscribed to Strapi Cloud and linked my GitHub repository to it. I have ensured that all variables are in place and the database I am using for Strapi Cloud is Postgres, which is hosted on Google Cloud Platform (GCP) with allowance to all IPV4 IPs. The project is working perfectly fine locally in development mode. However, I am facing a connection error when trying to build and deploy the project on Strapi Cloud.

I have checked and verified that the database credentials and connection string are correct. I have also ensured that the necessary ports are open for inbound and outbound traffic. Despite my efforts, I am still unable to resolve the connection error

here is my database.js

module.exports = ({ env }) => {
  const path = require("path");
  var ip = require("ip");
  const client = env("DATABASE_CLIENT", "postgres"); //sql

  const connections = {
    mysql: {
      client: "mysql",
      connection:
        env("ENVIRONMENT") === "production"
          ? {
              socketPath: `/cloudsql/${env("SQL_SOCKET_PATH")}`,
              database: env("SQL_DATABASE_NAME"),
              user: env("SQL_DATABASE_USERNAME"),
              password: env("SQL_DATABASE_PASSWORD"),
              ssl: env.bool("SQL_DATABASE_SSL"),
              max: env.int("SQL_POOL_MAX", 100),
            }
          : {
              host: env("SQL_DATABASE_HOST"),
              port: env.int("SQL_DATABASE_PORT"),
              database: env("SQL_DATABASE_NAME"),
              user: env("SQL_DATABASE_USERNAME"),
              password: env("SQL_DATABASE_PASSWORD"),
              ssl: env.bool("SQL_DATABASE_SSL"),
              max: env.int("SQL_POOL_MAX", 100),
            },
      debug: true,
      pool: {
        min: env.int("SQL_POOL_MIN", 2),
        max: env.int("SQL_POOL_MAX", 100),
      },
    },
    postgres: {
      client: "postgres",
      connection:
        env("ENVIRONMENT") === "production"
          ? {
              socketPath: env(
                "POSTGRESQL_SOCKET_HOST"
              ),
              database: env("POSTGRESQL_DATABASE_NAME"),
              user: env("POSTGRESQL_DATABASE_USERNAME"),
              password: env("POSTGRESQL_DATABASE_PASSWORD"),
              ssl: env.bool("POSTGRESQL_DATABASE_SSL") && {
                key: env("DATABASE_SSL_KEY", undefined),
                cert: env("DATABASE_SSL_CERT", undefined),
                ca: env("DATABASE_SSL_CA", undefined),
                capath: env("DATABASE_SSL_CAPATH", undefined),
                cipher: env("DATABASE_SSL_CIPHER", undefined),
                rejectUnauthorized: env.bool(
                  "DATABASE_SSL_REJECT_UNAUTHORIZED",
                  true
                ),
              },
              schema: env("POSTGRESQL_DATABASE_SCHEMA", "public"),
            }
          : {
              host: env("POSTGRESQL_DATABASE_HOST"),
              port: env.int("POSTGRESQL_DATABASE_PORT"),
              database: env("POSTGRESQL_DATABASE_NAME"),
              user: env("POSTGRESQL_DATABASE_USERNAME"),
              password: env("POSTGRESQL_DATABASE_PASSWORD"),
              ssl: env.bool("POSTGRESQL_DATABASE_SSL", false) && {
                key: env("DATABASE_SSL_KEY", undefined),
                cert: env("DATABASE_SSL_CERT", undefined),
                ca: env("DATABASE_SSL_CA", undefined),
                capath: env("DATABASE_SSL_CAPATH", undefined),
                cipher: env("DATABASE_SSL_CIPHER", undefined),
                rejectUnauthorized: env.bool(
                  "DATABASE_SSL_REJECT_UNAUTHORIZED",
                  true
                ),
              },
              schema: env("POSTGRESQL_DATABASE_SCHEMA", "public"),
            },
      debug: true,
      pool: {
        min: env.int("POSTGRESQL_DATABASE_POOL_MIN", 2),
        max: env.int("POSTGRESQL_DATABASE_POOL_MAX", 100),
      },
    },
    sqlite: {
      client: "sqlite3",
      connection: {
        filename: path.join(
          __dirname,
          "..",
          env("DATABASE_FILENAME", "data.db")
        ),
      },
      useNullAsDefault: true,
    },
  };

  const output = {
    connection: {
      ...connections[client],
      acquireConnectionTimeout: env.int("DATABASE_CONNECTION_TIMEOUT", 60000),
    },
  };

  return output;
};

GCP sql instance network settings:

and these are variables defined in strapi cloud:


Build Log:

[2023-04-12 18:36:19] ╭──────────── git repo clone ───────────╼
[2023-04-12 18:36:19] │  › fetching app source code
[2023-04-12 18:36:19] │ => Selecting branch "main"
[2023-04-12 18:36:20] │ => Checking out commit "5bfb7sdfdsfsdfsdb9c50"
[2023-04-12 18:36:20] │ 
[2023-04-12 18:36:20] │  ✔ cloned repo to /.app_platform_workspace
[2023-04-12 18:36:20] ╰────────────────────────────────────────╼
[2023-04-12 18:36:20] 
[2023-04-12 18:36:21]  › configuring build-time app environment variables:
[2023-04-12 18:36:21]      POSTGRESQL_DATABASE_HOST POSTGRESQL_DATABASE_NAME SQL_DATABASE_SSL POSTGRESQL_SOCKET_HOST CLIENT_APP_REPOSITORY SQL_DATABASE_NAME SQL_DATABASE_PORT SQL_DATABASE_HOST DATABASE_CLIENT POSTGRESQL_DATABASE_SCHEMA CLIENT_APP_REPOSITORY_BRANCH TRACKING_UUID SQL_POOL_MIN AUDIT_LOGS_ENABLED POSTGRESQL_DATABASE_POOL_MAX SQL_DATABASE_PASSWORD POSTGRESQL_DATABASE_PORT POSTGRESQL_DATABASE_SSL POSTGRESQL_DATABASE_USERNAME POSTGRESQL_DATABASE_POOL_MIN HOST POSTGRESQL_DATABASE_PASSWORD ENVIRONMENT SQL_DATABASE_USERNAME BASE_DIRECTORY SQL_POOL_MAX
[2023-04-12 18:36:21] ╭──────────── dockerfile build ───────────╼
[2023-04-12 18:36:21] │  › using dockerfile /.app_platform_workspace/Dockerfile
[2023-04-12 18:36:21] │  › using build context /.app_platform_workspace/
[2023-04-12 18:36:21] │ 
[2023-04-12 18:36:21] │ INFO[0000] Retrieving image manifest node:16-alpine     
[2023-04-12 18:36:21] │ INFO[0000] Retrieving image library/node:16-alpine from registry mirror <registry-uri-0> 
[2023-04-12 18:36:22] │ INFO[0000] Retrieving image manifest node:16-alpine     
[2023-04-12 18:36:22] │ INFO[0000] Returning cached image manifest              
[2023-04-12 18:36:22] │ INFO[0000] Built cross stage deps: map[]                
[2023-04-12 18:36:22] │ INFO[0000] Retrieving image manifest node:16-alpine     
[2023-04-12 18:36:22] │ INFO[0000] Returning cached image manifest              
[2023-04-12 18:36:22] │ INFO[0000] Retrieving image manifest node:16-alpine     
[2023-04-12 18:36:22] │ INFO[0000] Returning cached image manifest              
[2023-04-12 18:36:22] │ INFO[0000] Executing 0 build triggers                   
[2023-04-12 18:36:22] │ INFO[0000] Building stage 'node:16-alpine' [idx: '0', base-idx: '-1'] 
[2023-04-12 18:36:22] │ INFO[0000] Checking for cached layer <registry-uri-1> 
[2023-04-12 18:36:22] │ INFO[0000] Using caching version of cmd: RUN apk add --no-cache git rsync jq 
[2023-04-12 18:36:22] │ INFO[0000] Checking for cached layer <registry-uri-2> 
[2023-04-12 18:36:22] �
[2023-04-12 18:36:22] │ INFO[0001] Unpacking rootfs as cmd COPY . $BUILD_DIR requires it. 
[2023-04-12 18:36:24] │ INFO[0003] Initializing snapshotter ...                 
[2023-04-12 18:36:24] │ INFO[0003] Taking snapshot of full filesystem...        
[2023-04-12 18:36:25] │ INFO[0003] RUN apk add --no-cache git rsync jq          
[2023-04-12 18:36:25] │ INFO[0003] Found cached layer, extracting to filesystem 
[2023-04-12 18:36:25] │ INFO[0004] ENV BUILD_DIR "/home/build"                  
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] │ INFO[0004] ENV APP_DIR "/home/app"                      
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] │ INFO[0004] WORKDIR $APP_DIR                             
[2023-04-12 18:36:25] │ INFO[0004] Cmd: workdir                                 
[2023-04-12 18:36:25] │ INFO[0004] Changed working directory to /home/app       
[2023-04-12 18:36:25] │ INFO[0004] Creating directory /home/app                 
[2023-04-12 18:36:25] │ INFO[0004] Taking snapshot of files...                  
[2023-04-12 18:36:25] │ INFO[0004] COPY . $BUILD_DIR                            
[2023-04-12 18:36:25] │ INFO[0004] Taking snapshot of files...                  
[2023-04-12 18:36:25] │ INFO[0004] ARG CLIENT_APP_REPOSITORY                    
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] │ INFO[0004] ENV CLIENT_APP_REPOSITORY $CLIENT_APP_REPOSITORY 
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] │ INFO[0004] ARG CLIENT_APP_REPOSITORY_BRANCH="main"      
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] │ INFO[0004] ENV CLIENT_APP_REPOSITORY_BRANCH $CLIENT_APP_REPOSITORY_BRANCH 
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] │ INFO[0004] ARG TRACKING_UUID                            
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] │ INFO[0004] ENV TRACKING_UUID $TRACKING_UUID             
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] │ INFO[0004] ARG BASE_DIRECTORY=""                        
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] │ INFO[0004] ENV BASE_DIRECTORY $BASE_DIRECTORY           
[2023-04-12 18:36:25] │ INFO[0004] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:25] 
[2023-04-12 18:36:25] │ INFO[0004] Cmd: /bin/sh                                 
[2023-04-12 18:36:25] │ INFO[0004] Args: [-c git clone --depth 1 --single-branch --branch $CLIENT_APP_REPOSITORY_BRANCH $CLIENT_APP_REPOSITORY .] 
[2023-04-12 18:36:25] │ INFO[0004] Running: [/bin/sh -c git clone --depth 1 --single-branch --branch $CLIENT_APP_REPOSITORY_BRANCH $CLIENT_APP_REPOSITORY .] 
[2023-04-12 18:36:25] │ Cloning into '.'...
[2023-04-12 18:36:28] │ INFO[0006] Taking snapshot of files...                  
[2023-04-12 18:36:28] │ INFO[0007] WORKDIR "$APP_DIR/$BASE_DIRECTORY"           
[2023-04-12 18:36:28] │ INFO[0007] Cmd: workdir                                 
[2023-04-12 18:36:28] │ INFO[0007] Changed working directory to /home/app/backend 
[2023-04-12 18:36:28] │ INFO[0007] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:36:28] │ INFO[0007] RUN ${BUILD_DIR}/scripts/override-application-files.sh &&     ${BUILD_DIR}/scripts/override-application-tracking-uuid.sh &&     ${BUILD_DIR}/scripts/add-dependency.sh "strapi-provider-upload-strapi-cloud" "file:${BUILD_DIR}/overrides/packages/strapi-provider-upload-strapi-cloud" &&     ${BUILD_DIR}/scripts/add-dependency.sh "strapi-provider-email-strapi-cloud" "file:${BUILD_DIR}/overrides/packages/strapi-provider-email-strapi-cloud" &&     ${BUILD_DIR}/scripts/add-dependency.sh "pg" "^8.7.3" 
[2023-04-12 18:36:28] │ INFO[0007] Pushing layer <registry-uri-3> to cache now 
[2023-04-12 18:36:28] │ INFO[0007] Pushing image to <registry-uri-4> 
[2023-04-12 18:36:29] │ INFO[0007] Cmd: /bin/sh                                 
[2023-04-12 18:36:29] │ INFO[0007] Args: [-c ${BUILD_DIR}/scripts/override-application-files.sh &&     ${BUILD_DIR}/scripts/override-application-tracking-uuid.sh &&     ${BUILD_DIR}/scripts/add-dependency.sh "strapi-provider-upload-strapi-cloud" "file:${BUILD_DIR}/overrides/packages/strapi-provider-upload-strapi-cloud" &&     ${BUILD_DIR}/scripts/add-dependency.sh "strapi-provider-email-strapi-cloud" "file:${BUILD_DIR}/overrides/packages/strapi-provider-email-strapi-cloud" &&     ${BUILD_DIR}/scripts/add-dependency.sh "pg" "^8.7.3"] 
[2023-04-12 18:36:29] │ INFO[0007] Running: [/bin/sh -c ${BUILD_DIR}/scripts/override-application-files.sh &&     ${BUILD_DIR}/scripts/override-application-tracking-uuid.sh &&     ${BUILD_DIR}/scripts/add-dependency.sh "strapi-provider-upload-strapi-cloud" "file:${BUILD_DIR}/overrides/packages/strapi-provider-upload-strapi-cloud" &&     ${BUILD_DIR}/scripts/add-dependency.sh "strapi-provider-email-strapi-cloud" "file:${BUILD_DIR}/overrides/packages/strapi-provider-email-strapi-cloud" &&     ${BUILD_DIR}/scripts/add-dependency.sh "pg" "^8.7.3"] 
[2023-04-12 18:36:29] │ INFO[0008] Taking snapshot of files...                  
[2023-04-12 18:36:29] │ INFO[0008] Pushing layer <registry-uri-5> to cache now 
[2023-04-12 18:36:29] │ INFO[0008] Pushing image to <registry-uri-6> 
[2023-04-12 18:36:29] │ INFO[0008] RUN ${BUILD_DIR}/scripts/install-dependencies.sh &&     ${BUILD_DIR}/scripts/node-package-manager.sh run build 
[2023-04-12 18:36:29] │ INFO[0008] Cmd: /bin/sh                                 
[2023-04-12 18:36:29] │ INFO[0008] Args: [-c ${B
[2023-04-12 18:36:29] │ INFO[0008] Running: [/bin/sh -c ${BUILD_DIR}/scripts/install-dependencies.sh &&     ${BUILD_DIR}/scripts/node-package-manager.sh run build] 
[2023-04-12 18:36:30] │ INFO[0008] Pushed <registry-uri-7> 
[2023-04-12 18:36:33] │ npm WARN EBADENGINE Unsupported engine {
[2023-04-12 18:36:33] │ npm WARN EBADENGINE   package: 'strapi-plugin-populate-deep@0.1.2',
[2023-04-12 18:36:33] │ npm WARN EBADENGINE   required: { node: '>=12.x. <=16.x.x', npm: '>=6.0.0' },
[2023-04-12 18:36:33] │ npm WARN EBADENGINE   current: { node: 'v16.20.0', npm: '8.19.4' }
[2023-04-12 18:36:33] │ npm WARN EBADENGINE }
[2023-04-12 18:36:34] │ INFO[0013] Pushed <registry-uri-8> 
[2023-04-12 18:36:56] │ npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
[2023-04-12 18:36:56] │ npm WARN deprecated uuid@3.3.2: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
[2023-04-12 18:37:36] │ 
[2023-04-12 18:37:36] │ added 1540 packages, and audited 1541 packages in 1m
[2023-04-12 18:37:36] │ 
[2023-04-12 18:37:36] │ 131 packages are looking for funding
[2023-04-12 18:37:36] │   run `npm fund` for details
[2023-04-12 18:37:36] │ 
[2023-04-12 18:37:36] │ 7 vulnerabilities (2 moderate, 4 high, 1 critical)
[2023-04-12 18:37:36] │ 
[2023-04-12 18:37:36] │ To address issues that do not require attention, run:
[2023-04-12 18:37:36] │   npm audit fix
[2023-04-12 18:37:36] │ 
[2023-04-12 18:37:36] │ Some issues need review, and may require choosing
[2023-04-12 18:37:36] │ a different dependency.
[2023-04-12 18:37:36] │ 
[2023-04-12 18:37:36] │ Run `npm audit` for details.
[2023-04-12 18:37:36] │ npm notice 
[2023-04-12 18:37:36] │ npm notice New major version of npm available! 8.19.4 -> 9.6.4
[2023-04-12 18:37:36] │ npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.6.4>
[2023-04-12 18:37:36] │ npm notice Run `npm install -g npm@9.6.4` to update!
[2023-04-12 18:37:36] │ npm notice 
[2023-04-12 18:37:37] │ 
[2023-04-12 18:37:37] │ > backend@0.1.0 build
[2023-04-12 18:37:37] │ > strapi build
[2023-04-12 18:37:37] │ 
[2023-04-12 18:37:40] │ Building your admin UI with development configuration...
[2023-04-12 18:37:41] │ ℹ Compiling Webpack
[2023-04-12 18:38:04] │ ✔ Webpack: Compiled successfully in 22.55s
[2023-04-12 18:38:06] │ Admin UI built successfully
[2023-04-12 18:38:13] │ INFO[0112] Taking snapshot of files...                  
[2023-04-12 18:38:34] │ INFO[0133] Pushing layer <registry-uri-9> to cache now 
[2023-04-12 18:38:34] │ INFO[0133] Pushing image to <registry-uri-10> 
[2023-04-12 18:38:35] │ INFO[0134] ENTRYPOINT ["/home/build/entrypoint.sh", "run", "start"] 
[2023-04-12 18:38:35] │ INFO[0134] No files changed in this command, skipping snapshotting. 
[2023-04-12 18:38:49] │ INFO[0148] Pushed <registry-uri-11> 
[2023-04-12 18:38:49] │ INFO[0148] Pushing image to <image-12> 
[2023-04-12 18:38:50] │ INFO[0149] Pushed <registry-uri-13> 
[2023-04-12 18:38:50] │ 
[2023-04-12 18:38:50] │  ✔ built and uploaded app container image to DOCR
[2023-04-12 18:38:50] ╰──────────────────────────────────────────╼
[2023-04-12 18:38:50] 
[2023-04-12 18:38:50]  ✔  build complete 
[2023-04-12 18:38:50] 

Deploy Logs:

[2023-04-12 18:41:09] 
[2023-04-12 18:41:09] > backend@0.1.0 start
[2023-04-12 18:41:09] > strapi start
[2023-04-12 18:41:09] 
[2023-04-12 18:41:19] [2023-04-12 18:41:19.286] debug: ⛔️ Server wasn't able to start properly.
[2023-04-12 18:41:19] [2023-04-12 18:41:19.291] error: connect ECONNREFUSED 127.0.0.1:3306
[2023-04-12 18:41:19] Error: connect ECONNREFUSED 127.0.0.1:3306
[2023-04-12 18:41:19]     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16)

When using strapi cloud please do use the help widget bottom right corner and the support team can help you from there :slight_smile: Should be on your dashboard bottom right :slight_smile:

I see no help widget on my Strapi cloud dashboard.

Problem Solved @Eventyret , actually help widget does not shows up in safari Browser but works well in chrome. thanks :slight_smile: