最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

通过Dockerfile从部署到App Engine的Ghost连接到Google Cloud SQL

运维笔记admin12浏览0评论

通过Dockerfile从部署到App Engine的Ghost连接到Google Cloud SQL

通过Dockerfile从部署到App Engine的Ghost连接到Google Cloud SQL

我正在按照本教程将Ghost部署到Google App Engine

但是,不建议将Ghost安装为NPM模块的方法。

本教程介绍了一种通过Dockerfile安装Ghost的方法。 /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

如何在运行Ghost之前将我的Dockerfile配置为迁移数据库,以确保它可以连接到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 .js index.js

WORKDIR /var/lib/ghost

config.production.json

{
  "url": "",
  "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$

``
回答如下:

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

发布评论

评论列表(0)

  1. 暂无评论