class Fidoci::Main

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

Attributes

config[RW]

Public Class Methods

new(config_file = 'd.yml') click to toggle source

Initialize entry point config_file - yml file path with configuration

# 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

Public Instance Methods

build(tag, build_id, registry = '') click to toggle source

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

# 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
clean() click to toggle source

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

# File lib/fidoci/main.rb, line 50
def clean
    (config.keys - ['image']).each { |name|
        env = env(name, name)
        env.clean!
    }
end
cmd(*args) click to toggle source

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

# 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 = '') click to toggle source

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

# 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_name() click to toggle source

Configured docker repository name image key from YAML file

# File lib/fidoci/main.rb, line 36
def repository_name
    config['image']
end