grim/convey

Add new task aws/ecr-login for logging into AWS ECR. Fixed #161
// Convey
// Copyright 2016-2018 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/>.
package docker
import (
"time"
"github.com/aphistic/gomol"
"bitbucket.org/rw_grim/convey/logging"
"bitbucket.org/rw_grim/convey/state"
"bitbucket.org/rw_grim/convey/util"
)
// Network represents a docker network.
type Network struct {
name string
logger *gomol.LogAdapter
state *state.State
}
// NewNetwork creates a new docker network.
func NewNetwork(st *state.State) (*Network, error) {
network := &Network{
name: util.ID(),
logger: logging.NewAdapter("network"),
state: st,
}
cmdv := []string{"network", "create", network.name}
_, _, err := DockerOutput("create network", cmdv, st)
if err != nil {
return nil, err
}
network.logger.Debugf("created network: %#v", network.name)
return network, nil
}
// Name returns the name of the network.
func (network *Network) Name() string {
return network.name
}
// Destroy tears down the docker network.
func (network *Network) Destroy() error {
for _, name := range network.state.GetRunning() {
cmdv := []string{
"network",
"disconnect",
"--force",
network.name,
name,
}
network.logger.Infof("disconnecting container %s from network %s", name, network.Name())
err := Docker("disconnect container", cmdv, network.state)
if err != nil {
network.logger.Warningf("failed to disconnect container %s from network %s", name, network.Name())
continue
}
network.logger.Infof("disconnected container %s from network %s", name, network.Name())
}
// monkey with the timeout so our cleanup always runs
oldTimeout := network.state.PlanTimeout
defer func() {
network.state.PlanTimeout = oldTimeout
}()
network.state.PlanTimeout = 15 * time.Minute
cmdv := []string{"network", "rm", network.name}
return Docker("remove network", cmdv, network.state)
}