fix clone state; example routine
This commit is contained in:
parent
361a307d8d
commit
afb35ebad8
@ -1,5 +1,7 @@
|
||||
const AbstractGitState = require('./AbstractGitState')
|
||||
|
||||
// TODO add 'bare' option
|
||||
// TODO add 'new_repo' option (rm -rf .git && git init)
|
||||
class CloneState extends AbstractGitState {
|
||||
|
||||
async apply() {
|
||||
|
@ -15,11 +15,12 @@ class hosts extends Service {
|
||||
|
||||
get(name) {
|
||||
const config = this.config[name]
|
||||
config.name = name
|
||||
if ( !config ) {
|
||||
throw new Error(`Could not get host ${name}: No such host configured.`)
|
||||
}
|
||||
|
||||
config.name = name
|
||||
|
||||
if ( config.type === 'localhost' ) {
|
||||
const host = this.app.di().make(LocalHost, config)
|
||||
this._running_hosts.push(host)
|
||||
|
@ -12,18 +12,21 @@ const Routine = require('../classes/routine/Routine')
|
||||
*/
|
||||
class RoutinesService extends Service {
|
||||
static get services() {
|
||||
return [...super.services, 'app', 'configs', 'hosts']
|
||||
return [...super.services, 'injector', 'configs', 'hosts']
|
||||
}
|
||||
|
||||
async get(name) {
|
||||
this.app.make(Routine)
|
||||
const config = this.configs.get(`routines:${name}`)
|
||||
if ( !config ) {
|
||||
throw new Error(`Unable to find a routine with the name: ${name}`)
|
||||
}
|
||||
|
||||
const hosts = {}
|
||||
for ( const host_name of config.hosts ) {
|
||||
hosts[host_name] = await this.hosts.get(host_name)
|
||||
}
|
||||
|
||||
return new Routine(hosts, config, config.type)
|
||||
return this.injector.make(Routine, hosts, config, config.type)
|
||||
}
|
||||
}
|
||||
|
||||
|
147
config/routines/example.config.js
Normal file
147
config/routines/example.config.js
Normal file
@ -0,0 +1,147 @@
|
||||
const example_routine = {
|
||||
type: 'checks',
|
||||
hosts: ['localhost', 'other_server'],
|
||||
steps: [
|
||||
{
|
||||
// State: the file exists on the host
|
||||
type: 'fs.file',
|
||||
host: 'localhost', // localhost | other_server
|
||||
path: '/tmp/some.file',
|
||||
},
|
||||
{
|
||||
// State: the directory exists on the host
|
||||
type: 'fs.directory',
|
||||
host: 'localhost',
|
||||
path: '/tmp/some.directory',
|
||||
},
|
||||
{
|
||||
// State: the archive is unpacked into the destination
|
||||
type: 'fs.unpack',
|
||||
host: 'localhost',
|
||||
path: '/tmp/some.zip', // or /tmp/some.tar.gz
|
||||
destination: '/tmp/destination.dir',
|
||||
format: 'zip', // Optional: tar | zip (by default, from file extension)
|
||||
},
|
||||
{
|
||||
// State: the path is packed into a destination archive
|
||||
type: 'fs.pack',
|
||||
host: 'localhost',
|
||||
path: '/tmp/some.directory/or.file',
|
||||
destination: '/tmp/packed.tar.gz',
|
||||
format: 'tar', // Optional: tar | zip (by default, from file extension)
|
||||
},
|
||||
{
|
||||
// State: the fs permissions are set to the specified level
|
||||
type: 'fs.permission',
|
||||
host: 'localhost',
|
||||
path: '/tmp/some.directory/or.file',
|
||||
level: '644', // Some chmod permission level
|
||||
recursive: true, // default: false,
|
||||
revert_to: '555', // Permissions to revert to on undo, optional
|
||||
},
|
||||
{
|
||||
// State: the fs owners are set to the specified user/group
|
||||
type: 'fs.ownership',
|
||||
host: 'localhost',
|
||||
owners: { // Specify one or both of the following:
|
||||
user: 'some_user',
|
||||
group: 'some_group',
|
||||
},
|
||||
path: '/tmp/some.file/or.dir',
|
||||
recursive: true, // default: false
|
||||
revert_to: {
|
||||
user: 'root',
|
||||
group: 'root',
|
||||
},
|
||||
},
|
||||
{
|
||||
// State: the source repo is cloned into the path
|
||||
type: 'git.clone',
|
||||
host: 'localhost',
|
||||
path: '/tmp/some.dir.on.host',
|
||||
source: 'https://git.host/some/repo',
|
||||
},
|
||||
{
|
||||
// State: the specified ref is checked out
|
||||
type: 'git.checkout',
|
||||
host: 'localhost',
|
||||
path: '/tmp/some.dir.on.host',
|
||||
target: 'develop', // ref to check out
|
||||
revert_to: 'master', // ref to revert to on undo
|
||||
},
|
||||
{
|
||||
// State: the specified tag exists
|
||||
type: 'git.tag',
|
||||
host: 'localhost',
|
||||
path: '/tmp/some.dir.on.host',
|
||||
tag: 'rc-1', // tag to be created
|
||||
},
|
||||
{
|
||||
// State: the command has been run
|
||||
type: 'os.cmd',
|
||||
host: 'localhost',
|
||||
cmd: 'useradd some_user', // Command to run on execute
|
||||
reverse: 'userdel some_user', // Command to run on undo
|
||||
},
|
||||
{
|
||||
// State: the host is alive and responding
|
||||
type: 'os.alive',
|
||||
host: 'localhost',
|
||||
},
|
||||
{
|
||||
// State: the package is installed on the host
|
||||
type: 'package.present',
|
||||
host: 'localhost',
|
||||
package: 'gcc',
|
||||
},
|
||||
{
|
||||
// State: the package is not installed on the host
|
||||
type: 'package.absent',
|
||||
host: 'localhost',
|
||||
package: 'gcc',
|
||||
},
|
||||
{
|
||||
// State: the packages are all up to date
|
||||
type: 'package.updates',
|
||||
host: 'localhost',
|
||||
},
|
||||
{
|
||||
// State: the package cache has been cleared
|
||||
type: 'package.cache.clear',
|
||||
host: 'localhost',
|
||||
},
|
||||
{
|
||||
// State: the specified service(s) is (are) running
|
||||
type: 'service.running',
|
||||
host: 'localhost',
|
||||
service: 'apache2', // or array of services: ['apache2', 'redis']
|
||||
},
|
||||
{
|
||||
// State: the specified service(s) is (are) stopped
|
||||
type: 'service.stopped',
|
||||
host: 'localhost',
|
||||
service: 'apache2', // or array of services: ['apache2', 'redis']
|
||||
},
|
||||
{
|
||||
// State: the specified service(s) has (have) been restarted
|
||||
type: 'service.restarted',
|
||||
host: 'localhost',
|
||||
service: 'apache2', // or array of services: ['apache2', 'redis']
|
||||
},
|
||||
{
|
||||
// State: the service daemon has been reloaded
|
||||
type: 'service.daemon.reloaded',
|
||||
host: 'localhost',
|
||||
},
|
||||
{
|
||||
// State: the source file has been downloaded to the destination path
|
||||
type: 'web.download',
|
||||
host: 'localhost',
|
||||
method: 'get', // HTTP verb
|
||||
source: 'https://static.garrettmills.dev/assets/flitter/flitter_f.png',
|
||||
path: '/tmp/flitter_f.png',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
module.exports = exports = example_routine
|
@ -1,20 +0,0 @@
|
||||
const login_config = {
|
||||
type: 'checks',
|
||||
hosts: ['core', 'localhost', 'edge'],
|
||||
steps: [
|
||||
{
|
||||
type: 'os.alive',
|
||||
host: 'core',
|
||||
},
|
||||
{
|
||||
type: 'os.alive',
|
||||
host: 'edge',
|
||||
},
|
||||
{
|
||||
type: 'os.alive',
|
||||
host: 'localhost',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
module.exports = exports = login_config
|
@ -1,18 +0,0 @@
|
||||
const tmpdir_config = {
|
||||
type: 'checks',
|
||||
hosts: ['core', 'localhost'],
|
||||
steps: [
|
||||
{
|
||||
type: 'fs.directory',
|
||||
host: 'core',
|
||||
path: '/tmp/glmdev',
|
||||
},
|
||||
{
|
||||
type: 'fs.directory',
|
||||
host: 'localhost',
|
||||
path: '/tmp/glmdev',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
module.exports = exports = tmpdir_config
|
@ -1,16 +0,0 @@
|
||||
const updates_config = {
|
||||
type: 'checks',
|
||||
hosts: ['core', 'localhost'],
|
||||
steps: [
|
||||
{
|
||||
type: 'package.updates',
|
||||
host: 'core',
|
||||
},
|
||||
{
|
||||
type: 'package.updates',
|
||||
host: 'localhost',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
module.exports = exports = updates_config
|
@ -21,7 +21,7 @@
|
||||
"flitter-cli": "^0.16.0",
|
||||
"flitter-di": "^0.5.0",
|
||||
"flitter-flap": "^0.5.2",
|
||||
"libflitter": "^0.53.1",
|
||||
"libflitter": "^0.54.0",
|
||||
"moment": "^2.24.0",
|
||||
"scp": "^0.0.3",
|
||||
"ssh2": "^0.8.7",
|
||||
|
@ -2211,10 +2211,10 @@ leven@^1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/leven/-/leven-1.0.2.tgz#9144b6eebca5f1d0680169f1a6770dcea60b75c3"
|
||||
integrity sha1-kUS27ryl8dBoAWnxpncNzqYLdcM=
|
||||
|
||||
libflitter@^0.53.1:
|
||||
version "0.53.1"
|
||||
resolved "https://registry.yarnpkg.com/libflitter/-/libflitter-0.53.1.tgz#30b1838763a228fba8b9c820d2cad501c3aa0117"
|
||||
integrity sha512-EK3okZyt0pmnpsZNx2lYOIcwgtmSOEPh4a5xE3pXM9RVc3dtXXscgJ5h9OvLTIN9WfRc7T5VTdpOjeAK6Xmysg==
|
||||
libflitter@^0.54.0:
|
||||
version "0.54.0"
|
||||
resolved "https://registry.yarnpkg.com/libflitter/-/libflitter-0.54.0.tgz#5758fd0069de0ed75a80385c66809078b8210c36"
|
||||
integrity sha512-/pRgUD5dXdpEPxR6B3Do5BZQTGLrTYj3u0ZxYr7GViB4NysLePkR8Vg3gBzuNYUkEznzWxDR8VcmtuIiEowhFw==
|
||||
dependencies:
|
||||
colors "^1.3.3"
|
||||
connect-mongodb-session "^2.2.0"
|
||||
|
Loading…
Reference in New Issue
Block a user