Giter VIP home page Giter VIP logo

ghost-google-cloud-storage's Introduction

Looking for mantainer

This plugin is not updated for working on last ghost version.

Ghost Google Cloud Storage Plugin

A simple plugin to add Google Cloud Storage support for a Ghost Blog.

Installation

cd /var/www/ghost # or wherever you ran ghost-cli, this is your ghost base directory
npm install --save ghost-google-cloud-storage

Note that if you do not have a package.json file in your ghost base directory, this will warn. You do not need to add one, the node_modules directory will be created and populated either way. You can create one by running npm init.

Create storage module

# This assumes that you are operating on your production environemnt, change the following variable if necessary.
export GHOST_ENVIRONMENT=production
# Your content path will be determined by your config file: https://docs.ghost.org/v1.0/docs/config#section-paths
# You can run the jq command to get it for you
export CONTENT_PATH=$(jq -r '.paths.contentPath // "."' config.${GHOST_ENVIRONMENT}.json)
mkdir -p ${CONTENT_PATH}/adapters/storage/gcloud
cat > ${CONTENT_PATH}/adapters/storage/gcloud/index.js << EOL
'use strict';
module.exports = require('ghost-google-cloud-storage');
EOL

Configuration

Create a bucket in your google cloud project. In the storage settings you will find your project id as x-goog-project-id, after that you need to go to your API Credentials settings and create a Service account key, choosing JSON as the key type.

Add this key on your root ghost folder or any folder you want.

Add a storage block to your config.${GHOST_ENVIRONMENT}.json as below:

"storage": {
    "active": "gcloud",
    "gcloud": {
        "projectId": "Your_project_id",
        "key": "Your_key_path",
        "bucket": "Your_bucket_name",
        "assetDomain": "domain-for-bucket.example.com",
        "insecure": true,
        "maxAge": "2678400"
    }
}

Notes:

  • For the key path, if it is in the ghost root directory, just use the name of the file. Otherwise use an absolute path.
  • The assetDomain is an optional config entry, and is only required if you want to use a custom domain for your cloud storage bucket. Note that these instructions only allow for http, not https, as the storage servers do not present a custom certificate for your domain. Here is a list of workarounds. Pair with the "insecure": true option to use bare http URLs.
  • The insecure config is also optional, and defaults to false. Set to true if you are using a custom asset domain, and do not have https configured.
  • The maxAge is an optional config entry, and is only required if you want to set the cache-control's max age property. It defaults to 31 days (in seconds). This is desirable if you will not be deleting and re-uploading the same file multiple times, and will reduce your bandwidth usage when paired with a CDN. It can be overridden to set the max age to something else, smaller if you would like cache entries to be revalidated quicker, larger if you would like the cache entries to last for longer than 1 month.

Verify Ghost config

ghost stop
ghost run

You will see some logs or an error if the install was not successful. Fix any errors and then run ghost run again until you see the Ghost boot log entry.

Restart ghost

ghost start

Here is a transcript of the above, with errors

user@ghost:/var/www/ghost$ ghost stop
ghost run
Running sudo command: systemctl stop ghost_example-com
✔ Stopping Ghost
user@ghost:/var/www/ghost$ ghost run
The `ghost run` command is used by the configured Ghost process manager and for debugging. If you're not running this to debug something, you should run `ghost start` instead.
Running sudo command: node current/index.js
[2017-10-02 16:18:26] ERROR

NAME: IncorrectUsageError
CODE: MODULE_NOT_FOUND
MESSAGE: We have detected an error in your custom storage adapter.

level:critical

IncorrectUsageError: We have detected an error in your custom storage adapter.
    at new IncorrectUsageError (/var/www/ghost/versions/1.10.0/node_modules/ghost-ignition/lib/errors/index.js:79:23)
    at Object.getStorage (/var/www/ghost/versions/1.10.0/core/server/adapters/storage/index.js:43:19)
    ...

# fix the issue and retry

user@ghost:/var/www/ghost$ ghost run
The `ghost run` command is used by the configured Ghost process manager and for debugging. If you're not running this to debug something, you should run `ghost start` instead.
Running sudo command: node current/index.js
[2017-10-02 18:31:58] INFO Ghost is running in production... 
[2017-10-02 18:31:58] INFO Your blog is now available on http://example.com/ 
[2017-10-02 18:31:58] INFO Ctrl+C to shut down 
[2017-10-02 18:31:58] INFO Ghost boot 11.834s 
^C[2017-10-02 18:32:02] WARN Ghost has shut down 
[2017-10-02 18:32:02] WARN Your blog is now offline 
user@ghost:/var/www/ghost$ ghost start
✔ Validating config
Running sudo command: systemctl start ghost_example-com
✔ Starting Ghost
You can access your blog at http://example.com

Contributors

  • thombuchi
  • prenaudin
  • gcochard
  • zackify
  • nkirchhoffer

ghost-google-cloud-storage's People

Contributors

gcochard avatar mitchellst avatar nkirchhoffer avatar prenaudin avatar richtera avatar thombuchi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ghost-google-cloud-storage's Issues

Uploads Succeed but a wrong url is generate for Upload

Ghost Version : 3.32.1

Expected Image URL

/{bucketname}/2020/09/Screen-Shot-2020-09-10-at-5.31.48-PM.png

Actual Generated URL

/{bucketname}/2020/092020/09/Screen-Shot-2020-09-10-at-5.31.48-PM.png

getUniqueFileName returns a path with date in it. The second append is not required.

I've fixed this one. I'll be creating a new pull request for the fix.

InternalServerError: Cannot read property 'maxAge' of undefined

When I try to upload an image in a post in development mode, I receive this error in console and my page keep stuck in uploading message:

ERROR [2017-11-21 18:04:31] "POST /ghost/api/v0.1/uploads/" 500 645ms

NAME: InternalServerError
MESSAGE: Cannot read property 'maxAge' of undefined

level:normal

InternalServerError: Cannot read property 'maxAge' of undefined
    at new GhostError (/home/ubuntu/workspace/ghost-alest/ghost/core/server/errors.js:9:26)
    at prepareError (/home/ubuntu/workspace/ghost-alest/ghost/core/server/middleware/error-handler.js:40:19)
    at Layer.handle_error (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/layer.js:71:5)
    at trim_prefix (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:315:13)
    at /home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:335:12)
    at next (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:275:10)
    at Layer.handle_error (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/layer.js:67:12)
    at trim_prefix (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:315:13)
    at /home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:335:12)
    at next (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:275:10)
    at /home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:635:15
    at next (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/index.js:260:14)
    at next (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/express/lib/router/route.js:127:14)
    at onAPIError (/home/ubuntu/workspace/ghost-alest/ghost/core/server/api/index.js:286:13)
    at tryCatcher (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/promise.js:689:18)
    at Async._drainQueue (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/async.js:133:16)

TypeError: Cannot read property 'maxAge' of undefined
    at /home/ubuntu/workspace/ghost-alest/ghost/node_modules/ghost-google-cloud-storage/index.js:41:62
    at tryCatcher (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/home/ubuntu/workspace/ghost-alest/ghost/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

It happens with or without ageMaxparam in config file. My workaround was force ageMax value in node_modules/ghost-google-cloud-storage/index.js:41:62

Not working in ghost v1?

I added this module, added the config, and for some reason it seems files are not going to google storage, and no errors are outputted. Any ideas?

Cannot find module '../../core/server/errors'

Received an error after adding this package on ghost 0.11.3...

Unhandled rejection Error
at Error.IncorrectUsage (/app/node_modules/ghost/core/server/errors/incorrect-usage.js:3:18)
at Object.getStorage (/app/node_modules/ghost/core/server/storage/index.js:36:19)
at setupMiddleware (/app/node_modules/ghost/core/server/middleware/index.js:126:44)
at /app/node_modules/ghost/core/server/index.js:188:9

which was masking...

Unhandled rejection Error: Cannot find module '../../core/server/errors'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/app/node_modules/ghost-google-cloud-storage/index.js:8:19)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/app/content/storage/gcloud/index.js:2:18)

errors      = require('../../core/server/errors'),
utils       = require('../../core/server/utils'),
baseStore   = require('../../core/server/storage/base'),

after I changed these lines to:

errors      = require('../ghost/core/server/errors'),
utils       = require('../ghost/core/server/utils'),
baseStore   = require('../ghost/core/server/storage/base'),

everything started working fine... I have my installation installed as part of a manifest for "ghost-on-heroku" which is probably why the dynamic pathing fails...

Uploads does not return a valid url

When the ghost google cloud storage module is enabled and you upload an image it fails to return a valid url the url that is displayed looks like
https://example.com/2018/02undefined

Storage module config

  "storage": {
    "active": "gcloud",
    "gcloud": {
        "projectId": "my-project-id",
        "key": "./location/to/key.json",
        "bucket": "example.com",
        "assetDomain": "example.com",
        "insecure": false,
        "maxAge": "2678400"
    }
  },

If you have any pointers as to where to start looking or if you need additional details please let me know.

Issues with Ghost 1.x

I am trying to use this with Ghost 1.x on Google App Engine, but for some reason, when I launch the app with the added storage tag, the entire app crashes. Not really sure why.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.