You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
docker-gancio/patches/0001-adds-deploy-command-to...

104 lines
3.3 KiB

From b2722e244c8249d6cdc3464610fb257e8c80d849 Mon Sep 17 00:00:00 2001
From: matus <matus@enmotoneta.com>
Date: Fri, 4 Jun 2021 16:29:07 +0000
Subject: [PATCH] adds deploy command to gancio
---
server/cli.js | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/server/cli.js b/server/cli.js
index 41005ca2..7148f3e0 100755
--- a/server/cli.js
+++ b/server/cli.js
@@ -305,6 +305,67 @@ async function setup (options) {
process.exit(0)
}
+async function deploy (options) {
+ consola.info('You\'re going to deploy gancio on this machine.')
+
+ // check for mandatory config.json
+ if (firstrun.check(options.config)) {
+ consola.error(` ⚠ MISSING CINFIGURATION: Configuration file "${options.config}" not found!
+ Use "--config <CONFIG_FILE.json>" to specify another path, or generate one running 'gancio setup'`)
+ process.exit(-1)
+ }
+ const config = require(options.config)
+
+ // run migrations on ddbb
+ await run_migrations(config.db)
+
+ const db = require('./api/models')
+ const User = require('./api/models/user')
+ await db.authenticate()
+
+ // if new instance, initialize
+ const users = await User.findAll()
+ if (users.length === 0) {
+ // check for necesary data
+ if (!(config.admin_email && config.admin_pass)) {
+ consola.error(`⚠ MISSING CONFIGURATION: Cannot create Admin account on new deployment
+ Please, specify both 'admin_email' and 'admin_pass' on the config file`)
+ process.exit(-1)
+ }
+
+ // generate a random salt
+ consola.info(`Generate random salt`)
+ config.secret = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
+
+ // create admin user
+ const admin = { email: config.admin_email, password: config.admin_pass }
+
+ consola.info(`Create admin with email: ${admin.email}`)
+ await User.create({
+ email: admin.email,
+ password: admin.password,
+ is_admin: true,
+ is_active: true
+ })
+
+ // remove admin password and store salt/secret on config.json
+ delete config.admin_pass
+
+ consola.info(`Save configuration to ${options.config}`)
+ try {
+ fs.writeFileSync(options.config, JSON.stringify(config, null, 2))
+ } catch (e) {
+ consola.warn(` ⚠ ${e}. You can specify configuration path using '--config'`)
+ }
+
+ }
+
+ if ( options.autostart ) {
+ // start gancio using default method
+ start(options)
+ }
+}
+
consola.info(`📅 ${pkg.name} - v${pkg.version} - ${pkg.description}`)
require('yargs')
@@ -323,6 +384,11 @@ require('yargs')
describe: 'Configuration file',
default: '/opt/gancio/config.json'
})
+ .option('autostart', {
+ describe: 'Start gancio service after deploying',
+ default: false,
+ type: 'boolean'
+ })
.coerce('config', config_path => {
const absolute_config_path = path.resolve(cwd, config_path)
process.env.config_path = absolute_config_path
@@ -330,6 +396,7 @@ require('yargs')
})
.command(['start', 'run', '$0'], 'Start gancio', {}, start)
.command('setup', 'Setup a new instance', {}, setup)
+ .command('deploy', 'Deploy a instance from config files', {}, deploy)
.help('h')
.alias('h', 'help')
.epilog('Made with ❤ by underscore hacklab - https://gancio.org')
--
2.31.1