################################# # # Orchestration of containers # ################################# bundle common my { vars: "parent_address" string => "172.17.42.1"; "name" string => "$(sys.uqhost)"; "jobs" slist => { "container_1", "container_2", "container_3" }; classes: "containers" or => { @(jobs) }; } ################################################################################# bundle agent main { methods: parent:: "prepare continuous delivery source" comment => "The files where people make changes"; "collect build products" comment => "Reap the harvest"; "package for delivery" comment => "Tie it with a bow"; containers:: "fetch from the parent" comment => "pick up files and build something"; services: parent:: "children" comment => "Spawn some fledgings"; } ################################################################################### # Methods ################################################################################### bundle agent method_prepare_continuous_delivery_source { files: # Make one task for each bud "/tmp/feeds/$(my.jobs)_feed.txt" create => "true", edit_line => append_if_no_line("This is for $(my.jobs) from $(sys.uqhost)"); } ################################################################################### bundle agent method_collect_build_products { files: "/tmp/results/." create => "true"; "/tmp/results/reply_from_$(my.jobs)" comment => "Pick up the latest on the pipeline", copy_from => secure_cp("/tmp/result_for_pickup.txt","$(sys.docker_guest_ip[$(my.jobs)])"); } ################################################################################### bundle agent method_package_for_delivery { vars: "all_files" slist => { "/tmp/results/reply_from_container_1", "/tmp/results/reply_from_container_2" }; commands: "/bin/tar zcf /tmp/package.tgz /tmp/results" if => makerule("/tmp/package.tgz", "@(all_files)"); } ################################################################################### bundle agent service_children(name,state) { guest_environments: parent.!cleanup:: "$(my.jobs)" guest_details => stem_cell, guest_state => "create"; cleanup:: "$(my.jobs)" guest_details => stem_cell, guest_state => "delete"; reports: !cleanup:: "CONTAINERS running"; cleanup:: "CONTAINERS stopped"; } #################################################################################### body guest_details stem_cell { guest_type => "docker"; guest_image_name => "cf-stem-cell"; } ################################################################################### # Containers ################################################################################### bundle agent method_fetch_from_the_parent { services: "ssh" comment => "So we can log in and inspect the containers"; "cfengine" comment => "Need the server running"; files: "/tmp/job_description.txt" comment => "Pick up the latest on the pipeline", copy_from => secure_cp("/tmp/feeds/$(my.name)_feed.txt","$(my.parent_address)"); "/tmp/result_for_pickup.txt" create => "true", comment => "Do my part and deliver the result for pickup", edit_line => signature("/tmp/job_description.txt", "A postcard from sunny $(sys.ipv4) - Thanks, with love $(my.name)"); } #################################################################################### # Misc - try to keep this all in one file #################################################################################### body common control { bundlesequence => {"my", "main"}; } ## bundle server access_control { access: "/tmp" admit => { "172.17.0.0/16" }; } ## body server control { allowconnects => { "172.17.0.0/16" }; allowallconnects => { "172.17.0.0/16" }; trustkeysfrom => { "172.17.0.0/16" }; } ## bundle agent service_ssh(a,b) { processes: "/usr/sbin/sshd" restart_class => "restart_ssh"; commands: "/usr/sbin/sshd" ifvarclass => "restart_ssh"; } ## bundle agent service_cfengine(a,b) { processes: "cf-serverd" restart_class => "restart_cfengine"; commands: "/var/cfengine/bin/cf-serverd" ifvarclass => "restart_cfengine"; } ## body copy_from secure_cp(from,server) { source => "$(from)"; servers => { "$(server)" }; compare => "digest"; encrypt => "true"; verify => "true"; trustkey => "true"; } ## bundle edit_line append_if_no_line(str) { insert_lines: "$(str)" comment => "Append a line to the file if it doesn't already exist"; } ## bundle edit_line signature(file,str) { insert_lines: "$(file)" insert_type => "file"; "$(str)"; } ## body contain in_dir(s) { chdir => "$(s)"; }