【问题标题】:Connecting to Google Cloud SQL from Ghost deployed to App Engine with Dockerfile使用 Dockerfile 从部署到 App Engine 的 Ghost 连接到 Google Cloud SQL
【发布时间】:2020-02-02 05:57:42
【问题描述】:

我正在按照本教程将 Ghost 部署到 Google App Engine https://cloud.google.com/community/tutorials/ghost-on-app-engine-part-1-deploying

但是,将 Ghost 作为 NPM 模块安装的方法已被弃用。

本教程介绍了一种使用 Dockerfile 安装 Ghost 的方法。 https://vanlatum.dev/ghost-appengine/

我正在尝试利用此 Dockerfile 将 Ghost 部署到 Google App Engine,并连接到我的 Google Cloud SQL 数据库。

但是我遇到了问题:

ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2019-10-03 21:10:46] ERROR connect ENOENT /cloudsql/ghost

connect ENOENT /cloudsql/ghost

"Unknown database error"

Error ID:
    500

Error Code:
    ENOENT

----------------------------------------

DatabaseError: connect ENOENT /cloudsql/ghost
    at DatabaseError.KnexMigrateError (/var/lib/ghost/versions/2.31.1/node_modules/knex-migrator/lib/errors.js:7:26)

在第一个教程中,它提到需要在启动 ghost 之前运行迁移以防止出现此问题。所以我尝试在我的 Dockerfile 中添加这一行

RUN npm install knex-migrator --no-save
RUN NODE_ENV=production node_modules/knex-migrator init --mgpath node_modules/ghost

然后我收到以下错误:

/bin/sh: 1: node_modules/knex-migrator: Permission denied
The command '/bin/sh -c NODE_ENV=production node_modules/knex-migrator init --mgpath node_modules/ghost' returned a non-zero code: 126

如何配置我的 Dockerfile 以在运行 Ghost 之前迁移数据库以确保它可以连接到 Cloud SQL 数据库?

文件:

Dockerfile

FROM ghost

COPY config.production.json /var/lib/ghost/config.production.json
WORKDIR /var/lib/ghost
COPY credentials.json /var/lib/ghost/credentials.json
RUN npm install ghost-gcs --no-save
WORKDIR /var/lib/ghost/content/adapters/storage/ghost-gcs/
ADD https://raw.githubusercontent.com/thomas-vl/ghost-gcs/master/export.js index.js

WORKDIR /var/lib/ghost

config.production.json

{
  "url": "https://redactedurl.appspot.com",
  "fileStorage": false,
  "mail": {},
  "database": {
    "client": "mysql",
    "connection": {
      "socketPath": "/cloudsql/ghost",
      "user": "redacted",
      "password": "redacted",
      "database": "ghost",
      "charset": "utf8"
    },
    "debug": false
  },
  "server": {
    "host": "0.0.0.0",
    "port": "2368"
  },
  "paths": {
    "contentPath": "content/"
  },
  "logging": {
    "level": "info",
    "rotation": {
      "enabled": true
    },
    "transports": ["file", "stdout"]
  },
  "storage": {
    "active": "ghost-gcs",
    "ghost-gcs": {
      "key": "credentials.json",
      "bucket": "redactedurl"
    }
  }
}

app.yaml

runtime: custom
service: blog
env: flex
manual_scaling:
  instances: 1
env_variables:
  MYSQL_USER: redacted
  MYSQL_PASSWORD: redacted
  MYSQL_DATABASE: ghost
  INSTANCE_CONNECTION_NAME: redacted:us-central1:ghost
beta_settings:
  cloud_sql_instances: redacted:us-central1:ghost
skip_files:
  - ^(.*/)?#.*#$
  - ^(.*/)?.*~$
  - ^(.*/)?.*\.py[co]$
  - ^(.*/)?.*/RCS/.*$
  - ^(.*/)?\..*$
  - ^(.*/)?.*\.ts$
  - ^(.*/)?config\.development\.json$

``

【问题讨论】:

    标签: node.js docker google-app-engine google-cloud-sql ghost-blog


    【解决方案1】:

    根据Connecting from App Engine页面,您需要将路径更新为/cloudsql/INSTANCE_CONNECTION_NAME(所以/cloudsql/redacted:us-central1:ghost)。

    【讨论】:

    • 感谢您的回答,不幸的是,这仍然给了我 ENOENT 错误。
    • @Dayton - 您可以尝试该页面上的其他一些步骤。 1. 确保启用 Cloud SQL Admin API。 2. 确保运行代码的服务帐户具有正确的 IAM 权限(Cloud SQL Client 或更高)。 3. 如果是 flex,请确保您的 app.yaml 中有配置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    • 2017-06-17
    • 1970-01-01
    • 2020-02-19
    • 1970-01-01
    • 2015-09-15
    相关资源
    最近更新 更多