ghost-gcp-storage-adapter
v1.2.0
Published
Ghost adapter to store images into Google Cloud Storage
Maintainers
Readme
ghost-gcp-storage-adapter
Ghost adapter to store images, media files, and other files into Google Cloud Storage.
:arrow_down: Installation
Google Cloud Storage Configuration
- Create a project from Google Cloud Console
- Be sure that
Google Cloud Storage APIis enable inAPIs & Services > Library - Create a new Service Account in
IAM & Admin > Service Accounts - Create new credentials for your service account in
IAM & Admin > Service Accounts > <Your Service Account> > Actions > Manage Keys > Add Key - Download your credentials as a JSON file and renamed it to
credentials.json - Create a bucket to store your files (use Fine-grained access control)
Server Configuration for production
- Go to your Ghost instalation folder (the folder where you have the files
config.production.jsonorconfig.development.json):
cd /your/ghost/instalation/folder- Create the
adapters/storagefolder inside thecontentfolder:
mkdir -p content/adapters/storage- Install this package via NPM:
npm i ghost-gcp-storage-adapter- Copy the installed package into
content/adapters/storage:
cp -r node_modules/ghost-gcp-storage-adapter content/adapters/storage/ghost-gcp-storage-adapterCopy your
credentials.jsonfile intocontent/adapters/storage/ghost-gcp-storage-adapterAdd the following configuration to your
config.production.jsonfile:
"storage": {
"active": "ghost-gcp-storage-adapter", // For images
"media": "ghost-gcp-storage-adapter", // For video and audio files
"files": "ghost-gcp-storage-adapter", // For other file types
"ghost-gcp-storage-adapter": {
"projectId": "<your_google_cloud_project_id>",
"keyFilename": "<your_ghost_instalation_folder>/content/adapters/storage/ghost-gcp-storage-adapter/credentials.json",
"bucketName": "<your_bucket_name>"
}
}Storage Configuration Options:
active: Controls the storage adapter for imagesmedia: Controls the storage adapter for video and audio filesfiles: Controls the storage adapter for other file types
- Restart Ghost
Docker Deployment
If you're running Ghost in Docker, follow these steps:
- Clone and prepare the adapter:
# Clone this repository
git clone https://github.com/vcgtz/ghost-gcp-storage-adapter.git
cd ghost-gcp-storage-adapter
# Install dependencies
npm install- Update your
docker-compose.ymlto mount the necessary volumes:
version: '3'
services:
ghost:
image: ghost:5-alpine
volumes:
# Mount config.production.json
- ./config.production.json:/var/lib/ghost/config.production.json
# Mount the storage adapter
- ./ghost-gcp-storage-adapter:/var/lib/ghost/content/adapters/storage/ghost-gcp-storage-adapter
# Mount credentials.json (ensure it's in your project directory)
- ./credentials.json:/var/lib/ghost/content/adapters/storage/ghost-gcp-storage-adapter/credentials.json
// ... other configurations ...- Ensure your
config.production.jsonincludes the storage configuration:
{
// ... other configurations ...
"storage": {
"active": "ghost-gcp-storage-adapter", // For images
"media": "ghost-gcp-storage-adapter", // For video and audio files
"files": "ghost-gcp-storage-adapter", // For other file types
"ghost-gcp-storage-adapter": {
"projectId": "<your_google_cloud_project_id>",
"keyFilename": "/var/lib/ghost/content/adapters/storage/ghost-gcp-storage-adapter/credentials.json",
"bucketName": "<your_bucket_name>"
}
}
}- Start your Docker containers:
docker-compose up -dNote: Make sure the file permissions are correct and the credentials.json file is accessible within the container.
Configuration for development
If you want to contribute or test this adapter, you can use it locally by following the next instructions:
- Follow the same steps to configure Google Cloud Storage
- Fork this repo
- Clone your fork in your computer
- Install Ghost locally (Instructions)
- In the folder where you installed Ghost, install the adapter locally
cd ghost_folder/
npm install /path/to/your/forked/repo- Create the
adapters/storagefolder inside thecontentfolder:
mkdir -p content/adapters/storage- Copy the installed package into
content/adapters/storage:
cp -r node_modules/ghost-gcp-storage-adapter content/adapters/storage/ghost-gcp-storage-adapter- Copy your
credentials.jsonfile intocontent/adapters/storage/ghost-gcp-storage-adapter - Stop Ghost and running it in
developmentmode by using:
NODE_ENV=development ghost runWith this you'be able to see the logs in real time and test and debug this package.
