Skip to content

Instantly share code, notes, and snippets.

@paulcarroty
Created September 15, 2023 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulcarroty/c131be84696acf51aaf017b7472c2db4 to your computer and use it in GitHub Desktop.
Save paulcarroty/c131be84696acf51aaf017b7472c2db4 to your computer and use it in GitHub Desktop.
ghost npm installer for render.com
mkdir -p ./content/adapters/storage
cp -r ./node_modules/ghost-storage-adapter-s3 ./content/adapters/storage/s3
mkdir -p ./content/adapters/storage
cp -r ./node_modules/ghost-storage-cloudinary ./content/adapters/storage/cloudinary
#!/usr/bin/env node
// Ghost Configuration for Heroku
var fs = require("fs");
var path = require("path");
var url = require("url");
var envValues = require("./common/env-values");
var appRoot = path.join(__dirname, "..");
function createConfig() {
var fileStorage, storage;
if (!!process.env.S3_ACCESS_KEY_ID) {
fileStorage = true;
storage = {
active: "s3",
s3: {
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_ACCESS_SECRET_KEY,
bucket: process.env.S3_BUCKET_NAME,
region: process.env.S3_BUCKET_REGION,
assetHost: process.env.S3_ASSET_HOST_URL,
},
};
} else if (!!process.env.CLOUDINARY_URL) {
fileStorage = true;
storage = {
active: "cloudinary",
cloudinary: {
useDatedFolder: false,
upload: {
use_filename: true,
unique_filename: false,
overwrite: false,
folder: "ghost-blog-images",
tags: ["blog"],
},
fetch: {
quality: "auto",
secure: true,
cdn_subdomain: true,
},
},
};
} else {
fileStorage = false;
storage = {};
}
config = {
url: process.env.APP_PUBLIC_URL,
logging: {
level: "info",
transports: ["stdout"],
},
mail: {
transport: "SMTP",
options: {
service: "Mailgun",
auth: {
user: process.env.MAILGUN_SMTP_LOGIN,
pass: process.env.MAILGUN_SMTP_PASSWORD,
},
},
},
fileStorage: fileStorage,
storage: storage,
database: {
client: "mysql",
connection: getMysqlConfig(envValues.mysqlDatabaseUrl),
pool: { min: 0, max: 5 },
debug: false,
},
server: {
host: "0.0.0.0",
port: process.env.PORT || 10000,
},
paths: {
contentPath: path.join(appRoot, "/content/"),
},
};
return config;
}
function getMysqlConfig(connectionUrl) {
if (connectionUrl == null) {
return {};
}
var dbConfig = url.parse(connectionUrl);
if (dbConfig == null) {
return {};
}
var dbAuth = dbConfig.auth ? dbConfig.auth.split(":") : [];
var dbUser = dbAuth[0];
var dbPassword = dbAuth[1];
if (dbConfig.pathname == null) {
var dbName = "ghost";
} else {
var dbName = dbConfig.pathname.split("/")[1];
}
var dbConnection = {
host: "containers-us-west-180.railway.app" || dbConfig.hostname,
port: dbConfig.port || "3306",
user: dbUser,
password: dbPassword,
database: dbName,
};
return dbConnection;
}
var configContents = JSON.stringify(createConfig(), null, 2);
fs.writeFileSync(path.join(appRoot, "config.production.json"), configContents);
var ghost = require("ghost");
#!/usr/bin/env bash
echo "Initializing the deployment…"
echo "pwd →"
pwd
echo "config.production.json →"
cat config.production.json
bin/wait-for-db
#ls -l node_modules
echo CONTENT
#ls -l content/
echo THEMES
#ls -lah content/themes
# knex-migrator init --mgpath ./
{
"name": "ghost",
"version": "5.31.0",
"description": "Deploy latest Ghost v5 on Render",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://...git"
},
"keywords": [
"render, blog, ghost"
],
"author": "blog",
"license": "MIT",
"bugs": {
"url": "https://.../issues"
},
"homepage": "https://.../#readme",
"engines": {
"node": "16.X"
},
"dependencies": {
"ghost-cli": "^1.24.0",
"casper": "github:TryGhost/Casper#main",
"headline": "github:TryGhost/Headline#main",
"edition": "github:TryGhost/Edition#main",
"alto": "github:TryGhost/Alto#main",
"ruby": "github:TryGhost/Ruby#main",
"lyra": "github:TryGhost/lyra#main",
"ghost-storage-adapter-s3": "^2.8.0",
"ghost-storage-cloudinary": "^2.2.5",
"knex-migrator": "^5.1.1",
"mysql": "^2.18.1"
},
"scripts": {
"postinstall": "export NPM_CONFIG_PRODUCTION=false; ghost install --allow-root --no-check-empty --no-prompt --no-stack --no-setup --no-setup-linux-user --db sqlite3 && rm -rvf content && cp -Rf package*.json node_modules versions/*/; rm -rf node_modules; echo 'INSTALL TO versions/*/ DONE' && cp -Rf versions/*/* .; echo 'INSTALL TO PWD DONE' && rm -rf versions current && bash -x bin/cloudinary.sh && chmod +x ./bin/create-config ./bin/wait-for-db && ./bin/create-config && bash -x bin/aws-s3.sh && bash -x bin/themes.sh && bash -x bin/init-deployment",
"start": "node index.js"
}
}
themes=(
casper
lyra
headline
edition
alto
ruby
)
for theme in "${themes[@]}"
do
cp -Rf "node_modules/$theme" content/themes
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment