diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 8e00f9d5..034514eb 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -18,7 +18,7 @@ services: build: . image: node:latest container_name: gancio - command: gancio start /gancio/config.json + command: gancio start --docker volumes: - ./db.sqlite:/gancio/db.sqlite - ./config.json:/gancio/config.json diff --git a/package.json b/package.json index 3e67aba6..0421abcb 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "less": "^3.9.0", "lodash": "^4.17.14", "mastodon-api": "lesion/mastodon-api", + "mkdirp": "^0.5.1", "morgan": "^1.9.1", "multer": "^1.4.2", "node-fetch": "^2.6.0", diff --git a/server/cli.js b/server/cli.js index 9a191d6d..a37cd213 100755 --- a/server/cli.js +++ b/server/cli.js @@ -8,6 +8,7 @@ const inquirer = require('inquirer') const package = require('../package.json') const firstrun = require('./firstrun') const path = require('path') +const mkdirp = require('mkdirp') const cwd = process.cwd() @@ -18,7 +19,7 @@ function notEmpty (value) { return value.length>0 } -async function setupQuestionnaire() { +async function setupQuestionnaire(is_docker) { const questions = [] questions.push({ @@ -38,7 +39,7 @@ async function setupQuestionnaire() { questions.push({ name: 'server.host', message: 'address to listen to', - default: 'localhost', + default: is_docker ? '0.0.0.0' : 'localhost', validate: notEmpty }) @@ -58,7 +59,7 @@ async function setupQuestionnaire() { questions.push({ name: 'db.storage', message: 'sqlite db path', - default: './db.sqlite', + default: is_docker ? '/opt/gancio/db.sqlite' : './db.sqlite', filter: p => path.resolve(cwd, p), when: answers => answers.db.dialect === 'sqlite', validate: db_path => db_path.length>0 && fs.existsSync(path.dirname(db_path)) @@ -67,7 +68,7 @@ async function setupQuestionnaire() { questions.push({ name: 'db.host', message: 'Postgres host', - default: 'localhost', + default: is_docker ? 'db' : 'localhost', when: answers => answers.db.dialect === 'postgres', validate: notEmpty }) @@ -111,12 +112,20 @@ async function setupQuestionnaire() { questions.push({ name: 'upload_path', message: 'Where gancio has to store media?', - default: './uploads', + default: '/opt/gancio/uploads', filter: p => path.resolve(cwd, p), - validate: p => { - const exists = fs.existsSync(p) - if (!exists) consola.warn(`"${p}" does not exists, please create it`) - return exists + validate: async p => { + let exists = fs.existsSync(p) + if (!exists) { + consola.warn(`"${p}" does not exists, trying to create it`) + try { + mkdirp.sync(p) + } catch(e) { + console.error(String(e)) + return false + } + } + return true } }) @@ -183,6 +192,10 @@ async function upgrade (options) { async function start (options) { // is first run? if (firstrun.check(options.config)) { + if (options.docker) { + consola.error('Something goes wrong, did you run "docker-compose run --rm gancio gancio setup"') + process.exit(-1) + } consola.error(`Configuration file "${options.config}" not found! Use "--config " to specify another path. If this is your first run use 'gancio setup --config ' `) process.exit(-1) @@ -192,8 +205,9 @@ If this is your first run use 'gancio setup --config ' `) } async function setup (options) { + consola.info('DOCKER ', options.docker) consola.info(`You're going to setup gancio on this machine.`) - const config = await setupQuestionnaire() + const config = await setupQuestionnaire(options.docker) await firstrun.setup(config, options.config) consola.info(`You can edit '${options.config}' to modify your configuration. `) consola.info(`Start the server with "gancio --config ${options.config}"`) @@ -204,7 +218,13 @@ consola.info(`${package.name} - v${package.version} - ${package.description}`) require('yargs') .usage('Usage $0 [options]') -.option('config', { +.option('docker', { + alias: 'd', + describe: 'Inside docker', + default: false, + type: 'boolean' +}) +.option('config', { alias: 'c', describe: 'Configuration file', default: '/opt/gancio/config.json',