我按照指令here使用Ghost作为NPM模块,并尝试设置Ghost进行 生产环境 .
我在本地运行Google Cloud sql代理 . 当我运行 NODE_ENV=production knex-migrator init --mgpath node_modules/ghost
时收到此错误消息:
NAME: RollbackError
CODE: ER_ACCESS_DENIED_ERROR
MESSAGE: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'cloudsqlproxy~[SOME_IP_ADDRESS]' (using password: NO)
运行 knex-migrator init --mgpath node_modules/ghost
工作正常,我可以在本地启动应用程序没有问题 . 这只是我尝试设置应用程序进行 生产环境 ,我遇到了问题 .
编辑:我可以通过MySQL Workbench连接到数据库,使用我在下面的配置中使用的相同凭据
这是我的 config.production.json
(删除了私人数据):
{
"production": {
"url": "https://MY_PROJECT_ID.appspot.com",
"fileStorage": false,
"mail": {},
"database": {
"client": "mysql",
"connection": {
"socketPath": "/cloudsql/MY_INSTANCE_CONNECTION_NAME",
"user": "USER",
"password": "PASSWORD",
"database": "DATABASE_NAME",
"charset": "utf8"
},
"debug": false
},
"server": {
"host": "0.0.0.0",
"port": "2368"
},
"paths": {
"contentPath": "content/"
}
}
}
并 app.yaml
:
runtime: nodejs
env: flex
manual_scaling:
instances: 1
env_variables:
MYSQL_USER: ******
MYSQL_PASSWORD: ******
MYSQL_DATABASE: ******
# e.g. my-awesome-project:us-central1:my-cloud-sql-instance-name
INSTANCE_CONNECTION_NAME: ******
beta_settings:
# The connection name of your instance on its Overview page in the Google
# Cloud Platform Console, or use `YOUR_PROJECT_ID:YOUR_REGION:YOUR_INSTANCE_NAME`
cloud_sql_instances: ******
# Setting to keep gcloud from uploading not required files for deployment
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
- ^(.*/)?.*\.ts$
- ^(.*/)?config\.development\.json$
2 回答
文件
ghost.prod.config.js
isn 't something Ghost recognises - I' m不确定文件名来自何处,但Ghost <1.0使用config.js
将所有环境都放在一个文件中,Ghost> = 1.0使用config.<env>.json
将每个环境放在自己的文件中 .您的
config.production.json
文件不包含您的MySQL连接信息,因此knex-migrator工具无法连接到您的数据库 .如果将
ghost.prod.config.js
的内容合并到config.producton.json
中,这应该可以正常工作 .你的config.production.json应该是这样的:
需要注意的是,新的JSON格式不能包含代码或逻辑,只能包含显式值,例如:不再允许
process.env.PORT || "2368"
.相反,您需要使用参数或环境变量来提供动态配置 . 有关如何使用环境变量的文档,请访问:https://docs.ghost.org/docs/config#section-running-ghost-with-config-env-variables
例如 .
NODE_ENV=production port=[your port] database__connection__user=[your user] ...etc... knex-migrator init --mgpath node_modules/ghost
您需要为配置中的每个动态变量添加一个环境变量 .
我解决了这个问题 .
我的配置文件不应该具有“ 生产环境 ”属性 . 我的配置应如下所示:
它现在覆盖默认配置 .
唯一的问题是您不能将knex-migrator与“socketPath”属性集一起使用,但这需要在 Cloud 中运行应用程序 .