H.Husain
H.Husain

Reputation: 473

Error after Deploying strapi 4.23.0 to google app engine with postgres DB

I have been trying to deploy my strapi application to google app engine, but getting the below error after deployment in the error logs

Error: ENOENT: no such file or directory, mkdir '/workspace/.tmp' at Object.mkdirSync (node:fs:1373:26) at module.exports.makeDirSync (/layers/google.nodejs.yarn/yarn_modules/node_modules/fs-extra/lib/mkdirs/make-dir.js:23:13) at SqliteDialect.configure (/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/database/dist/index.js:936:26) at new Database (/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/database/dist/index.js:6185:18) at Database.init (/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/database/dist/index.js:6170:16) at Strapi.bootstrap (/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/strapi/dist/Strapi.js:372:39) at Strapi.load (/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/strapi/dist/Strapi.js:426:16)

Below is the error I am seeing on the frontend:

https://10615.ew.r.appspot.com/

Service Unavailable

Below is the old guide I have followed to deploy

https://docs-v3.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/google-app-engine.html

Below is my config:

Package.json

{
  "name": "backend",
  "version": "0.1.0",
  "private": true,
  "description": "A Strapi application",
  "license": "MIT",
  "author": {
    "name": "A Strapi developer"
  },
  "scripts": {
    "build": "strapi build",
    "develop": "strapi develop",
    "gcp-build": "strapi build",
    "start": "strapi start",
    "strapi": "strapi"
  },
  "dependencies": {
    "@strapi/plugin-i18n": "4.23.0",
    "@strapi/plugin-seo": "^1.9.8",
    "@strapi/plugin-users-permissions": "4.23.0",
    "@strapi/strapi": "4.23.0",
    "better-sqlite3": "8.6.0",
    "pg": "^8.11.5",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-router-dom": "5.3.4",
    "styled-components": "5.3.3"
  },
  "devDependencies": {},
  "engines": {
    "node": ">=18.0.0 <=20.x.x",
    "npm": ">=6.0.0"
  },
  "strapi": {
    "uuid": "4ab2-a874-3799d23b1640"
  }
}

app.yaml

runtime: nodejs18

instance_class: F2

env_variables:
  HOST: '0.0.0.0'
  NODE_ENV: 'production'
  DATABASE_NAME: 'DB_NAME'
  DATABASE_USERNAME: 'postgres'
  DATABASE_PASSWORD: 'DB_PASS'
  INSTANCE_CONNECTION_NAME: 'double-41web'

beta_settings:
  cloud_sql_instances: 'double-41web'

backend/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"),
    },
  },
});

backend/.gcloudignore

.gcloudignore
.git
.gitignore
node_modules/
#!include:.gitignore
!.env
yarn.lock

I have tried giving permission to some services:

role=roles/cloudsql.client

cloudsql.editor

storage.objectAdmin

appengine.deployer

logging.admin

Upvotes: 0

Views: 140

Answers (1)

antokhio
antokhio

Reputation: 2004

The error:

Error: ENOENT: no such file or directory, mkdir '/workspace/.tmp'

Means your strapi instance wants to start with default configuration (that is SQLite)

You have configuration issue, looks like the env_variables aren't passed correctly.

When you use backend/config/env/production you also have to use:

NODE_ENV=production yarn build
NODE_ENV=production yarn start

Hower when you pass env's like that:

env_variables:
  HOST: '0.0.0.0'
  NODE_ENV: 'production'
  DATABASE_NAME: 'DB_NAME'
  DATABASE_USERNAME: 'postgres'
  DATABASE_PASSWORD: 'DB_PASS'
  INSTANCE_CONNECTION_NAME: 'double-41web'

There is not much point having multiple configurations in /config folder. I would be better to remove /config/env and make sure all configurations read in default /config/ folder

Upvotes: 0

Related Questions