npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ghost-s3-file-storage

v2.0.1

Published

Compatible with Ghost ^1.18.2

Downloads

2

Readme

Ghost S3 File Storage Plug-in

Compatible with Ghost ^1.18.2

Build Status

Once installed allows a ghost user to upload files directly to AWS S3 from the Ghost editor without any changes to ghost source. This is especially useful when deploying Ghost in AWS directly on EC2 instances or Docker Containers where storing files to local disk isn't desirable.

This S3 storage adapter doesn't perform reading or serving the files and requires the specified S3 bucket configured with public read-only policy. S3 is fit for this purpose of serving SPAs and/or assets via public url endpoint.

Installation Example

I like to deploy Ghost in a Docker container using the official Ghost image.

I created an npm project with a Dockerfile and installed ghost-s3-file-storage as a dependency. This way when the container is built we can include the index.js and it's node_modules.

npm init

npm install --save ghost-s3-file-storage

Example Dockerfile

FROM ghost:1.18.2

ADD node_modules /var/lib/ghost/content/adapters/storage/ghost-s3-file-storage/node_modules
ADD node_modules/ghost-s3-file-storage/index.js /var/lib/ghost/content/adapters/storage/ghost-s3-file-storage/index.js

Now we can build our Docker image.

docker build --rm -t ghost-blog:latest .

Now we can test it out and run our Ghost container with our new s3 storage adapter configured.

docker run --rm -p 2368:2368 -e NODE_ENV=development -e database__client=sqlite3
    -e database__connection__filename=/var/lib/ghost/content/data/ghost-test.db -e storage__active=ghost-s3-file-storage
    -e storage__ghost-s3-file-storage__region=us-west-2 -e storage__ghost-s3-file-storage__bucket=ghost-blog
    -e storage__ghost-s3-file-storage__folder=files -e AWS_ACCESS_KEY_ID=<access-key>
    -e AWS_SECRET_ACCESS_KEY=<secret> ghost-blog:latest

Note: Never store AWS credentials in source or configuration files or transmit them from your development machine in any way. Best practice is to never set the AWS credentials in code via the aws-sdk client. Instead utilize the default behavior of AWS sdk clients, credential provider chain which searches for credentials using chain of responsibility pattern searching for environment variables or IAM role (running within AWS data center) and so on. See http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CredentialProviderChain.html

Bob's your uncle! You should be able to create a new post from Ghost post editor and upload a new image straight to an S3 bucket/folder.

Configuration

storage: {
    active: 'ghost-s3-file-storage',
    'ghost-s3-file-storage': {
        region: 'us-west-2',
        bucket: '<bucket>',
        folder: '<root-folder>',
        distributionUrl: 'https://abc.cloudfront.net'
    }
}
active

Refers to the /var/lib/ghost/content/adapters/storage directory where Ghost can find this file storage plug-in.

region

(Optional) The AWS availability zone the S3 bucket was created in

bucket

The S3 bucket name

folder

The root folder to upload files into in the specified bucket

distributionUrl

(Optional) The base url to construct when returning url to Ghost if standing up a CloudFront CDN in front of the S3 bucket. Eg. <distribution-url>/<folder>/<YYYY>/<MM>/<DD>/<guid>.<ext> See here for details on how to set up CloudFront to cache files out on the edges.

If distributionUrl is not specified then defaults to S3 http url in which case region must be specified. Eg. https://s3-<region>.amazonaws.com/<bucket>/<folder>/<YYYY>/<MM>/<DD>/<guid>.<ext> If both region and distributionUrl are specified distributionUrl takes precedence.

Feedback

Feedback and contributions welcome