* Copyright 2016-2017 Gary Kramlich <grim@reaperworld.com> * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. "github.com/aphistic/gomol" "bitbucket.org/rw_grim/convey/docker" "bitbucket.org/rw_grim/convey/environment" "bitbucket.org/rw_grim/convey/logging" "bitbucket.org/rw_grim/convey/stages" "bitbucket.org/rw_grim/convey/state" "bitbucket.org/rw_grim/convey/tasks" "bitbucket.org/rw_grim/convey/yaml" Environment yaml.StringOrSlice `yaml:"environment"` Stages []stages.Stage `yaml:"stages"` Merge bool `yaml:"merge"` func (p *Plan) setup(logger *gomol.LogAdapter, st *state.State) error { logger.Info("creating network...") network, err := docker.NewNetwork(st) logger.Fatal("failed to create network") logger.Infof("created network %s", st.Network.Name()) logger.Info("creating workspace...") ws, err := docker.NewWorkspace(st) logger.Fatal("failed to create workspace") logger.Infof("created workspace %s", st.Workspace.Name()) func (p *Plan) teardown(logger *gomol.LogAdapter, st *state.State) { // run through the DetachedContainers and stop them for _, cid := range st.GetDetached() { logger.Infof("removing detached container %s", cid) docker.StopContainer(cid, logger, st) // remove the workspace (if requested) logger.Infof("not removing workspace %s as requested", st.Workspace.Name()) logger.Infof("removing workspace %s", st.Workspace.Name()) if err := st.Workspace.Destroy(); err != nil { logger.Fatalf("failed to remove workspace %s", st.Workspace.Name()) logger.Infof("removed workspace %s", st.Workspace.Name()) logger.Infof("removing network %s", st.Network.Name()) if err := st.Network.Destroy(); err != nil { logger.Fatalf("failed to remove network %s", st.Network.Name()) logger.Infof("removed network %s", st.Network.Name()) func (p *Plan) Execute(path string, tasks map[string]tasks.Task, env []string, st *state.State) error { logger := logging.NewAdapter(path) planEnv := environment.Merge(env, p.Environment) defer p.teardown(logger, st) if err := p.setup(logger, st); err != nil { // set a flag on whether or not we've failed for _, stage := range p.Stages { absStageName := fmt.Sprintf("%s/%s", path, stage.Name) stageLogger := logging.NewAdapter(absStageName) if stage.ShouldRun(planErr) { stageLogger.Info("stage starting") err := stage.Execute(absStageName, stageLogger, tasks, planEnv, st) stageLogger.Fatal("stage failed") stageLogger.Info("stage finished")