rbld 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9e9aca3061e0708713b02db9087e37dc422a6dd
4
+ data.tar.gz: 95f8378b8a2b3f024c432d3bea4a39843c1b8e7e
5
+ SHA512:
6
+ metadata.gz: c0302f820ffdb0bcd9d058c2ed29b587a8f790c27dfdd6f3977ff74c23105f5af44fbff3b565349d1b572b2885406957e72af3c955473a8141cd9bbc3499cc20
7
+ data.tar.gz: 6ac9cad20676849bda8176bb96dff285101a9e3a0a154fc2721e934a700bf52c85bc6d65895759691f2fdc6b75d558a5298f1dc93bf79be1ee8122dbb08e0dfe
data/cli/bin/rbld ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'require_all'
4
+
5
+ module Rebuild
6
+ require_relative '../lib/rbld_commands'
7
+ require_rel '../lib/commands'
8
+ end
9
+
10
+ begin
11
+
12
+ rbld_log.info( "ARGV: #{ARGV.join(' ')}" )
13
+
14
+ if !ARGV[0] || (ARGV[0] == "help" && !ARGV[1])
15
+ puts Rebuild::CLI::Main.usage
16
+ puts
17
+ exit 0
18
+ end
19
+
20
+ if ARGV[0] == "help"
21
+ Rebuild::CLI::Commands.usage( ARGV[1] )
22
+ exit 0
23
+ end
24
+
25
+ if ARGV[1] == "--help" || ARGV[1] == "-h"
26
+ Rebuild::CLI::Commands.usage( ARGV[0] )
27
+ exit 0
28
+ end
29
+
30
+ exit Rebuild::CLI::Commands.run( ARGV[0], ARGV.drop(1) ) || 0
31
+
32
+ rescue RuntimeError => msg
33
+ rbld_print.error(msg)
34
+ exit 1
35
+ end
@@ -0,0 +1,30 @@
1
+ #!/bin/sh
2
+
3
+ has_app()
4
+ {
5
+ hash $1 2>/dev/null
6
+ }
7
+
8
+ delete_group()
9
+ {
10
+ if has_app groupdel; then
11
+ groupdel $1
12
+ elif has_app delgroup; then
13
+ delgroup $1
14
+ else
15
+ echo Failed to delete a group, no supported group management utils found
16
+ exit 1
17
+ fi
18
+ }
19
+
20
+ delete_user()
21
+ {
22
+ if has_app userdel; then
23
+ userdel $1
24
+ elif has_app deluser; then
25
+ deluser $1
26
+ else
27
+ echo Failed to delete a user, no supported user management utils found
28
+ exit 1
29
+ fi
30
+ }
@@ -0,0 +1,75 @@
1
+ #!/bin/sh
2
+
3
+ . /rebuild/re-build-bootstrap-utils
4
+
5
+ DEBUG_OUTPUT=/dev/null
6
+
7
+ rebuild_banner()
8
+ {
9
+ BEST_ECHO=`which echo 2>/dev/null`
10
+ if test -z $BEST_ECHO; then
11
+ BEST_ECHO=echo
12
+ fi
13
+
14
+ $BEST_ECHO -e "\e[1;92m$1\e[0m"
15
+ }
16
+
17
+ setup_users()
18
+ {
19
+ delete_user $REBUILD_USER_NAME
20
+ delete_group $REBUILD_USER_NAME
21
+ delete_group $REBUILD_GROUP_NAME
22
+
23
+ if has_app useradd; then
24
+
25
+ groupadd -o -g $REBUILD_GROUP_ID $REBUILD_GROUP_NAME
26
+
27
+ useradd -o -M \
28
+ -g $REBUILD_GROUP_ID \
29
+ -u $REBUILD_USER_ID \
30
+ --home-dir $REBUILD_USER_HOME \
31
+ $REBUILD_USER_NAME
32
+
33
+ else
34
+
35
+ echo "$REBUILD_GROUP_NAME:x:$REBUILD_GROUP_ID:" >> /etc/group
36
+ echo "$REBUILD_USER_NAME:x:$REBUILD_USER_ID:$REBUILD_GROUP_ID:Linux User,,,:$REBUILD_USER_HOME:" >> /etc/passwd
37
+
38
+ fi
39
+ }
40
+
41
+ rebuild_shell()
42
+ {
43
+ if test -f /bin/bash; then
44
+ echo /bin/bash
45
+ else
46
+ echo /bin/sh
47
+ fi
48
+ }
49
+
50
+ sudo_params()
51
+ {
52
+ echo "-n -H -E -g $REBUILD_GROUP_NAME -u $REBUILD_USER_NAME"
53
+ }
54
+
55
+ setup_users 2>$DEBUG_OUTPUT
56
+
57
+ cd $REBUILD_PWD
58
+
59
+ . /rebuild/rebuild.rc
60
+
61
+ if test -n "$*"; then
62
+ rebuild_banner ">>> rebuild env $HOSTNAME"
63
+ rebuild_banner ">>> $*"
64
+ sudo `sudo_params` `rebuild_shell` -c "$*"
65
+ else
66
+ rebuild_banner ">>> rebuild env $HOSTNAME interactive"
67
+ rebuild_banner ">>> Press CTRL-D do leave"
68
+ sudo `sudo_params` `rebuild_shell`
69
+ fi
70
+
71
+ RC=$?
72
+
73
+ rebuild_banner "<<< rebuild env $HOSTNAME"
74
+
75
+ exit $RC
@@ -0,0 +1,52 @@
1
+ #!/bin/sh -e
2
+
3
+ . /rebuild/re-build-bootstrap-utils
4
+
5
+ dep_install()
6
+ {
7
+ if has_app dnf; then
8
+ dnf install -y $*
9
+ #cleaning to make image smaller
10
+ dnf clean all
11
+ elif has_app yum; then
12
+ yum install -y $*
13
+ #cleaning to make image smaller
14
+ yum clean all
15
+ elif has_app apt-get; then
16
+ apt-get update
17
+ apt-get install -y $*
18
+ #cleaning to make image smaller
19
+ apt-get clean
20
+ elif has_app apk; then
21
+ apk update
22
+ apk add $*
23
+ elif has_app zypper; then
24
+ zypper install -y $*
25
+ #cleaning to make image smaller
26
+ zypper clean
27
+ elif has_app urpmi; then
28
+ urpmi sudo
29
+ else
30
+ echo Failed to install "$*", no supported package manager found
31
+ exit 1
32
+ fi
33
+ }
34
+
35
+ configure_sudo()
36
+ {
37
+ echo "ALL ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers
38
+ }
39
+
40
+ try_install_sudo()
41
+ {
42
+ if ! has_app sudo; then
43
+ dep_install sudo
44
+ fi
45
+
46
+ return $(has_app sudo)
47
+ }
48
+
49
+ # Download may fail unpredictably so we try a few times
50
+ try_install_sudo || try_install_sudo || try_install_sudo
51
+
52
+ configure_sudo
@@ -0,0 +1,6 @@
1
+ # This is the rebuild environment definition file.
2
+ # Define required environment variables here.
3
+ #
4
+ # NOTE: Make sure to prefix definitions with
5
+ # 'export' directive, i.e.
6
+ #export MY_PATH=/path/to/some/location
@@ -0,0 +1,14 @@
1
+ module Rebuild::CLI
2
+ class RbldCheckoutCommand < Command
3
+ def initialize
4
+ @usage = "checkout [OPTIONS] [ENVIRONMENT[:TAG]]"
5
+ @description = "Discard environment modifications"
6
+ end
7
+
8
+ def run(parameters)
9
+ env = Environment.new( parameters[0] )
10
+ rbld_log.info("Going to checkout #{env}")
11
+ engine_api.checkout!( env )
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ require 'getoptlong'
2
+
3
+ module Rebuild::CLI
4
+ class RbldCommitCommand < Command
5
+ def initialize
6
+ @usage = "commit [OPTIONS] [ENVIRONMENT[:TAG]]"
7
+ @description = "Commit environment modifications"
8
+ @options = [["-t TAG,--tag TAG", "New tag to be created"]]
9
+ end
10
+
11
+ def parse_opts(parameters)
12
+ replace_argv( parameters ) do
13
+ opts = GetoptLong.new([ '--tag', '-t', GetoptLong::REQUIRED_ARGUMENT ])
14
+ tag = nil
15
+ opts.each do |opt, arg|
16
+ case opt
17
+ when '--tag'
18
+ tag = arg
19
+ end
20
+ end
21
+
22
+ raise "New tag not specified" unless tag
23
+ Environment.validate_component( 'new tag', tag )
24
+ return tag, ARGV
25
+ end
26
+ end
27
+
28
+ def run(parameters)
29
+ new_tag, parameters = parse_opts( parameters )
30
+
31
+ env = Environment.new( parameters[0] )
32
+ rbld_log.info("Going to commit #{env}")
33
+ engine_api.commit!(env, new_tag)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,50 @@
1
+ require 'getoptlong'
2
+
3
+ module Rebuild::CLI
4
+ class RbldCreateCommand < Command
5
+ def initialize
6
+ @usage = "create [OPTIONS] [ENVIRONMENT]"
7
+ @description = "Create a new environment"
8
+ @options = [
9
+ ["-b NAME, --base NAME", "Base image from Docker Hub"],
10
+ ["-f NAME, --basefile NAME", "Base file"]
11
+ ]
12
+ end
13
+
14
+ def parse_opts(parameters)
15
+ replace_argv( parameters ) do
16
+ opts = GetoptLong.new([ '--base', '-b', GetoptLong::REQUIRED_ARGUMENT ],
17
+ [ '--basefile', '-f', GetoptLong::REQUIRED_ARGUMENT ])
18
+ base = basefile = nil
19
+ opts.each do |opt, arg|
20
+ case opt
21
+ when '--base'
22
+ base = arg
23
+ when '--basefile'
24
+ basefile = arg
25
+ end
26
+ end
27
+
28
+ raise "Exactly one environment base must be specified" \
29
+ if base && basefile
30
+
31
+ raise "Environment base not specified" \
32
+ unless base || basefile
33
+
34
+ raise "Base file #{basefile} does not exist" \
35
+ if basefile && !File.file?(basefile)
36
+
37
+ return base, basefile, ARGV
38
+ end
39
+ end
40
+
41
+ def run(parameters)
42
+ base, basefile, parameters = parse_opts( parameters )
43
+
44
+ env = Environment.new( parameters[0], force_no_tag: true )
45
+ rbld_log.info("Going to create #{env} from #{base || basefile}")
46
+ engine_api.create!( base, basefile, env )
47
+ rbld_print.progress "Successfully created #{env.full}"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,16 @@
1
+ module Rebuild::CLI
2
+ class RbldDeployCommand < Command
3
+ def initialize
4
+ @usage = "deploy [OPTIONS] [ENVIRONMENT[:TAG]]"
5
+ @description = "Deploy environment from remote registry"
6
+ end
7
+
8
+ def run(parameters)
9
+ env = Environment.new( parameters[0] )
10
+ cmd = get_cmdline_tail( parameters )
11
+ rbld_log.info("Going to deploy \"#{env}\"")
12
+ engine_api.deploy!( env )
13
+ rbld_print.progress "Successfully deployed #{env}\n"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Rebuild::CLI
2
+ class RbldListCommand < Command
3
+ def initialize
4
+ @usage = "list [OPTIONS]"
5
+ @description = "List local environments"
6
+ end
7
+
8
+ def run(parameters)
9
+ print_names( engine_api.environments )
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ module Rebuild::CLI
2
+ class RbldLoadCommand < Command
3
+ private
4
+
5
+ def default_file(name, tag)
6
+ "#{name}-#{tag}.rbld"
7
+ end
8
+
9
+ public
10
+
11
+ def initialize
12
+ @usage = "load [OPTIONS] [FILE]"
13
+ @description = "Load environment from file"
14
+ end
15
+
16
+ def run(parameters)
17
+ file = parameters[0]
18
+ raise "File name must be specified" if !file
19
+ raise "File #{file} does not exist" if !File::exist?(file)
20
+ rbld_log.info("Going to load environment from #{file}")
21
+ engine_api.load!( file )
22
+ rbld_print.progress "Successfully loaded environment from #{file}\n"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ module Rebuild::CLI
2
+ class RbldModifyCommand < Command
3
+ def initialize
4
+ @usage = [
5
+ { :syntax => "modify [OPTIONS] [ENVIRONMENT[:TAG]]",
6
+ :description => "Interactive mode: opens shell in the " \
7
+ "specified enviroment" },
8
+ { :syntax => "modify [OPTIONS] [ENVIRONMENT[:TAG]] -- COMMANDS",
9
+ :description => "Scripting mode: runs COMMANDS in the " \
10
+ "specified environment" }
11
+ ]
12
+ @description = "Modify a local environment"
13
+ end
14
+
15
+ def run(parameters)
16
+ env = Environment.new( parameters.shift )
17
+ cmd = get_cmdline_tail( parameters )
18
+ rbld_log.info("Going to modify \"#{env}\" with \"#{cmd}\"")
19
+ @errno = engine_api.modify!( env, cmd )
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Rebuild::CLI
2
+ class RbldPublishCommand < Command
3
+ def initialize
4
+ @usage = "publish [OPTIONS] [ENVIRONMENT[:TAG]]"
5
+ @description = "Publish environment on remote registry"
6
+ end
7
+
8
+ def run(parameters)
9
+ env = Environment.new( parameters[0] )
10
+ rbld_log.info("Going to publish \"#{env}\"")
11
+ engine_api.publish( env )
12
+ rbld_print.progress "Successfully published #{env}\n"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Rebuild::CLI
2
+ class RbldRmCommand < Command
3
+ def initialize
4
+ @usage = "rm [OPTIONS] [ENVIRONMENT[:TAG]]"
5
+ @description = "Remove local environment"
6
+ end
7
+
8
+ def run(parameters)
9
+ env = Environment.new( parameters[0] )
10
+ rbld_log.info("Going to remove #{env}")
11
+ engine_api.remove!( env )
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ module Rebuild::CLI
2
+ class RbldRunCommand < Command
3
+ def initialize
4
+ @usage = [
5
+ { :syntax => "run [OPTIONS] [ENVIRONMENT[:TAG]]",
6
+ :description => "Interactive mode: opens shell in the " \
7
+ "specified enviroment" },
8
+ { :syntax => "run [OPTIONS] [ENVIRONMENT[:TAG]] -- COMMANDS",
9
+ :description => "Scripting mode: runs COMMANDS in the " \
10
+ "specified environment" }
11
+ ]
12
+ @description = "Run command in a local environment"
13
+ end
14
+
15
+ def run(parameters)
16
+ env = Environment.new( parameters.shift )
17
+ cmd = get_cmdline_tail( parameters )
18
+ rbld_log.info("Going to run \"#{cmd}\" in \"#{env}\"")
19
+
20
+ warn_if_modified( env, 'running' )
21
+ @errno = engine_api.run( env, cmd )
22
+ end
23
+ end
24
+ end