我一直在尝试将我的 Strapi 应用程序部署到谷歌应用程序引擎,但部署后在错误日志中出现以下错误
错误:ENOENT:没有这样的文件或目录,mkdir '/workspace/.tmp' 在 Object.mkdirSync (节点:fs:1373:26) 在 module.exports.makeDirSync (/layers/google.nodejs.yarn/yarn_modules/node_modules/fs-extra/lib/mkdirs/make-dir.js:23:13) 在 SqliteDialect.configure (/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/database/dist/index.js:936:26) 在新数据库(/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/database/dist/index.js:6185:18) 在Database.init(/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/database/dist/index.js:6170:16) 在 Strapi.bootstrap (/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/strapi/dist/Strapi.js:372:39) 在 Strapi.load (/layers/google.nodejs.yarn/yarn_modules/node_modules/@strapi/strapi/dist/Strapi.js:426:16)
以下是我在前端看到的错误:
https://10615.ew.r.appspot.com/
服务不可用
下面是我遵循的旧部署指南
以下是我的配置:
包.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'
后端/配置/env/生产/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"),
},
},
});
后端/.gcloudignore
.gcloudignore
.git
.gitignore
node_modules/
#!include:.gitignore
!.env
yarn.lock
我尝试授予某些服务权限:
角色=角色/cloudsql.client
cloudsql.editor
存储.objectAdmin
appengine.deployer
日志管理
错误:
Error: ENOENT: no such file or directory, mkdir '/workspace/.tmp'
意味着您的 Strapi 实例想要以默认配置(即 SQLite)启动
您有配置问题,看起来
env_variables
未正确传递。
当您使用
backend/config/env/production
时,您还必须使用:
NODE_ENV=production yarn build
NODE_ENV=production yarn start
当你像这样传递 env 时:
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'
在
/config
文件夹中拥有多个配置没有多大意义。
我最好删除 /config/env
并确保所有配置都在默认 /config/
文件夹中读取