Class: Fidoci::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/fidoci/main.rb

Overview

Main entry point for D command reads configuration and provide high-level commands

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file = 'd.yml') ⇒ Main

Initialize entry point config_file - yml file path with configuration



14
15
16
17
18
19
20
21
22
# File 'lib/fidoci/main.rb', line 14

def initialize(config_file = 'd.yml')
    @config = YAML.load_file(config_file)

    Docker.options = {
        read_timeout: 3600
    }

    $stdout.sync = true
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



10
11
12
# File 'lib/fidoci/main.rb', line 10

def config
  @config
end

Instance Method Details

#build(tag, build_id, registry = '') ⇒ Object

Build image and run test in it tag - tag name to tag image after successful build and test build_id - unique build_id to be used to identify docker images and containers



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fidoci/main.rb', line 60

def build(tag, build_id, registry = '')
    build_id = SecureRandom.hex(10) unless build_id

    test_env = env(:build, build_id, registry)
    test_env.clean!

    success = test_env.commands

    if success
        test_env.tag_image(tag)
        test_env.push(tag)
    end

    success
ensure
    test_env.clean! if test_env
end

#cleanObject

Clean system removes all service and running containers and their images and removes all images build by d



50
51
52
53
54
55
# File 'lib/fidoci/main.rb', line 50

def clean
    (config.keys - ['image']).each { |name|
        env = env(name, name)
        env.clean!
    }
end

#cmd(*args) ⇒ Object

Run command in default “exec” environment ie in container build and started with exec configuration args - command and arguments to pass to docker run command



27
28
29
30
31
32
# File 'lib/fidoci/main.rb', line 27

def cmd(*args)
    exec_env = env(:dev, 'dev')
    exec_env.cmd(*args)
ensure
    exec_env.stop!
end

#env(name, id, registry = '') ⇒ Object

Create environment instance with given name name - key that will be used to configure this env id - unique identifier of env that will be used to tag containers and images



43
44
45
# File 'lib/fidoci/main.rb', line 43

def env(name, id, registry = '')
    Env.new(registry + repository_name, id.to_s, config[name.to_s])
end

#repository_nameObject

Configured docker repository name image key from YAML file



36
37
38
# File 'lib/fidoci/main.rb', line 36

def repository_name
    config['image']
end