From 6fb723b16482ce08df331e546cdb630969737944 Mon Sep 17 00:00:00 2001 From: Darren Foo Date: Wed, 27 Apr 2016 22:54:17 -0700 Subject: [PATCH] allow -a option to register AMI from bake -p created snapshot --- lib/linecook/cli.rb | 1 + lib/linecook/provisioner/manager.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/linecook/cli.rb b/lib/linecook/cli.rb index 28c4d86..7349357 100644 --- a/lib/linecook/cli.rb +++ b/lib/linecook/cli.rb @@ -146,6 +146,7 @@ class Linecook::CLI < Thor method_option :clean, type: :boolean, default: false, desc: 'Clean up all build artifacts', aliases: '-c' method_option :build, type: :boolean, default: true, desc: 'Build the image', aliases: '-b' method_option :snapshot, type: :boolean, default: false, desc: 'Snapshot the resulting build to create an image', aliases: '-s' + method_option :ami, type: :boolean, default: false, desc: 'Create an ami', aliases: '-a' method_option :upload, type: :boolean, default: false, desc: 'Upload the resulting build. Implies --snapshot and --encrypt.', aliases: '-u' method_option :package, type: :boolean, default: false, desc: 'Package the resulting image. Implies --upload, --snapshot and --encrypt.', aliases: '-p' def bake diff --git a/lib/linecook/provisioner/manager.rb b/lib/linecook/provisioner/manager.rb index e38ecb4..abb40a0 100644 --- a/lib/linecook/provisioner/manager.rb +++ b/lib/linecook/provisioner/manager.rb @@ -9,13 +9,13 @@ module Linecook module Baker extend self - def bake(name: nil, tag: nil, id: nil, snapshot: nil, upload: nil, package: nil, build: nil, keep: nil, clean: nil) + def bake(name: nil, tag: nil, id: nil, snapshot: nil, upload: nil, package: nil, build: nil, keep: nil, clean: nil, ami: nil) build_agent = Linecook::Build.new(name, tag: tag, id: id, image: image(name)) resume = clean ? false : true provider(name).provision(build_agent, name) if build snapshot = build_agent.snapshot(save: true, resume: resume) if snapshot || upload || package Linecook::ImageManager.upload(snapshot, type: build_agent.type) if upload || package - Linecook::Packager.package(snapshot, type: build_agent.type) if package + Linecook::Packager.package(snapshot, type: build_agent.type, ami: ami) if package rescue => e puts e.message puts e.backtrace