mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-26 13:35:16 +03:00
af0f26c75f
no issue - Dev Containers let you work on Ghost in a consistent, isolated environment with all the necessary development dependencies pre-installed. VSCode (or Cursor) can effectively run _inside_ the container, providing a local quality development environment while working in a well-defined, isolated environment. - For now the default setup only works with "Clone repository in Container Volume" or "Clone PR in Container Volume" — this allows for a super quick and simple setup. We can also introduce another configuration to allow opening an existing local checkout in a Dev Container, but that's not quite ready yet. - This PR also added the `yarn clean:hard` command which: deletes all node_modules, cleans the yarn cache, and cleans the NX cache. This will be necessary for opening a local checkout in a Dev Container. - To learn more about Dev Containers, read this guide from VSCode: https://code.visualstudio.com/docs/devcontainers/containers#_personalizing-with-dotfile-repositories --------- Co-authored-by: Joe Grigg <joe@ghost.org> Co-authored-by: Steve Larson <9larsons@gmail.com>
92 lines
3.0 KiB
JavaScript
92 lines
3.0 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
const assert = require('node:assert/strict');
|
|
|
|
// Reads the config.local.json file and updates it with environments variables for devcontainer setup
|
|
const configBasePath = path.join(__dirname, '..', 'ghost', 'core');
|
|
const configFile = path.join(configBasePath, 'config.local.json');
|
|
let originalConfig = {};
|
|
if (fs.existsSync(configFile)) {
|
|
try {
|
|
// Backup the user's config.local.json file just in case
|
|
// This won't be used by Ghost but can be useful to switch back to local development
|
|
const backupFile = path.join(configBasePath, 'config.local-backup.json');
|
|
fs.copyFileSync(configFile, backupFile);
|
|
|
|
// Read the current config.local.json file into memory
|
|
const fileContent = fs.readFileSync(configFile, 'utf8');
|
|
originalConfig = JSON.parse(fileContent);
|
|
} catch (error) {
|
|
console.error('Error reading or parsing config file:', error);
|
|
process.exit(1);
|
|
}
|
|
} else {
|
|
console.log('Config file does not exist. Creating a new one.');
|
|
}
|
|
|
|
let newConfig = {};
|
|
// Change the url if we're in a codespace
|
|
if (process.env.CODESPACES === 'true') {
|
|
assert.ok(process.env.CODESPACE_NAME, 'CODESPACE_NAME is not defined');
|
|
assert.ok(process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN, 'GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN is not defined');
|
|
const url = `https://${process.env.CODESPACE_NAME}-2368.${process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}`;
|
|
newConfig.url = url;
|
|
}
|
|
|
|
newConfig.database = {
|
|
client: 'mysql2',
|
|
connection: {
|
|
host: 'mysql',
|
|
user: 'root',
|
|
password: 'root',
|
|
database: 'ghost'
|
|
}
|
|
}
|
|
newConfig.adapters = {
|
|
Redis: {
|
|
host: 'redis',
|
|
port: 6379
|
|
}
|
|
}
|
|
|
|
|
|
// Only update the mail settings if they aren't already set
|
|
if (!originalConfig.mail && process.env.MAILGUN_SMTP_PASS && process.env.MAILGUN_SMTP_USER) {
|
|
newConfig.mail = {
|
|
transport: 'SMTP',
|
|
options: {
|
|
service: 'Mailgun',
|
|
host: 'smtp.mailgun.org',
|
|
secure: true,
|
|
port: 465,
|
|
auth: {
|
|
user: process.env.MAILGUN_SMTP_USER,
|
|
pass: process.env.MAILGUN_SMTP_PASS
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Only update the bulk email settings if they aren't already set
|
|
if (!originalConfig.bulkEmail && process.env.MAILGUN_API_KEY && process.env.MAILGUN_DOMAIN) {
|
|
newConfig.bulkEmail = {
|
|
mailgun: {
|
|
baseUrl: 'https://api.mailgun.net/v3',
|
|
apiKey: process.env.MAILGUN_API_KEY,
|
|
domain: process.env.MAILGUN_DOMAIN,
|
|
tag: 'bulk-email'
|
|
}
|
|
}
|
|
}
|
|
|
|
// Merge the original config with the new config
|
|
const config = {...originalConfig, ...newConfig};
|
|
|
|
// Write the updated config.local.json file
|
|
try {
|
|
fs.writeFileSync(configFile, JSON.stringify(config, null, 2));
|
|
console.log('Config file updated successfully.');
|
|
} catch (error) {
|
|
console.error('Error writing config file:', error);
|
|
process.exit(1);
|
|
} |