dev

package module
v0.1.4-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2019 License: MIT Imports: 8 Imported by: 0

README

dev Build Status Go Report Card

dev is a command line tool that wraps Docker Compose to enable shared resources for an ideal development environment.

Background

Requirements

  • Support sharing of docker-compose configuration across projects
  • Support sharing of networks across projects (i.e., manage creation of 'external' networks directly)
  • Support authentication with private container repositories
  • Support dependencies between projects, networks and registries

Table of Contents

Installing

Binaries available for linux and and osx here.

Contributing

You will need a current version of golang that supports modules to build this project.

Configuration

Dev will search the current directory and its parent directory until it locates a configuration file. The name of the configuration is .dev.yaml but can be overridden with the --config flag. If a per-project configuration file cannot be found, dev will look in your home directory and finally in $XDG_CONFIG_HOME/dev for one.

If a configuration file is not found, dev will look in the current working directory for a docker-compose.yml file. If one is found, it will create a dev project with the base name of current directory. For example, if you are located in $HOME/Projects/my-app and there is a docker-compose.yml in that directory, dev will create a command named 'my-app' and a number of subcommands. These subcommands can be listed by running dev my-app --help.

If you require more than one docker-compose.yml for your project, you can specify these in the .dev.yaml file. For example, for the my-app project which has a layout like this:

  $HOME/Projects/my-app:
    .dev.yaml
    docker-compose.yml

  $HOME/Projects/my-app/docker
    docker-compose.shared.yml

The $HOME/Projects/my-app/dev.yml might contain something like this:

projects:
 my-app:
   docker_compose_files:
     - "docker/docker-compose.shared.yml"
     - "docker-compose.yml"
   depends_on: ["my-external-network"]

networks:
 my-external-network:
   driver: bridge
   ipam:
     driver: default
     config:
       - subnet: 173.16.242.0/16

Running 'dev my-app build' will provide both docker-compose.yml configuration files to docker-compose with the -f flag.

When 'dev my-app up' is run, "my-external-network" will be created if it does not exist.

Run 'dev my-app sh' to get a shell in the container or 'dev my-app sh ls -al' to run 'ls -al' in the project container. The "project" container is the container in the docker-compose.yml with the same name as the project in the .dev.yaml file.

Overview

Run dev to see a list of Projects

Project Commands

The following commands are sub-commands added to each project added to .dev.yaml. If no .dev.yaml could not be located, dev will look in the current directory for a docker-compose.yml file and add a project with the same name as the current directory.

build

Run docker-compose build for the specified project. The build will specify all the docker-compose files in the project's docker_compose_files array.

ps

View details about the services running for the specified project. This is the output of docker-compose ps for your project.

up

Start the containers for the specified project. This will build or fetch the images as required.

sh

Run without arguments this command runs an interactive shell on the project container. If run with arguments, the arguments are passed to the container shell with the -c flag.

If this command is run from a subdirectory of the project directory this command will first change directories such that relative commands from your directory on the host can be run. If run from outside of your project directory the starting directory defaults to the WORKDIR specified in the project's Dockerfile.

Documentation

Index

Constants

View Source
const (

	// LogLevelDefault is the log level used when one has not been
	// specified in an environment variable or in configuration file.
	LogLevelDefault = "info"
	// NoProjectWarning is the message provided to the user when no project
	// could be found
	NoProjectWarning = `` /* 239-byte string literal not displayed */

)

Variables

View Source
var ConfigFileDefaults = []string{".dev.yml", ".dev.yaml", "dev.yml", "dev.yaml"}

ConfigFileDefaults are the default filenames for the configuration file for this program.

Functions

func ExpandConfig

func ExpandConfig(filename string, config *Config)

ExpandConfig makes modifications to the configuration structure provided by the user before it is used by dev.

func MergeConfig

func MergeConfig(target *Config, source *Config) error

MergeConfig adds the configuration from source to the configuration from target. An error is returned if there is an object with the same name in target and source or if the configs cannot be merged for whatever reason.

func SliceContainsString

func SliceContainsString(slice []string, a string) bool

SliceContainsString checks the provided slice for the specified string and returns true if it was found, otherwise returns false.

func SliceInsertString

func SliceInsertString(s []string, str string, index int) []string

SliceInsertString inserts string at the specified index of the provided slice. From Slice Tricks.

Types

type Config

type Config struct {
	Log        LogConfig            `mapstructure:"log"`
	Projects   map[string]*Project  `mapstructure:"projects"`
	Registries map[string]*Registry `mapstructure:"registries"`
	// Filename is the full path of the configuration file containing
	// this configuration. This is used internally and is ignored
	// if specified by the user.
	Filename string
	// Dir is either the location of the config file or the current
	// working directory if there is no config file. This is used
	// intenrally and is ignored if specified by the user.
	Dir string
	// Networks are a list of the networks managed by dev. A network
	// will be created automatically as required by dev if it is listed
	// as a dependency of your project. These are networks that are used
	// as 'external networks' in your docker-compose configuration.
	Networks map[string]*types.NetworkCreate `mapstructure:"networks"`
	// ImagePrefix is the prefix to add to images built with this
	// tool through compose. Compose forces the use of a prefix so we
	// allow the configuration of that prefix here.  Dev must know the
	// prefix in order to perform some image specific operations.  If not
	// set, this defaults to the directory where the this tool's config
	// file is located or the directory or the docker-compose.yml if one is
	// found. Note that compose only adds the prefix to local image
	// builds.
	ImagePrefix string `mapstructure:"image_prefix"`
}

Config is the datastructure into which we unmarshal the dev configuration file.

func NewConfig

func NewConfig() *Config

NewConfig structs the default configuration structure for dev driven projects.

func (*Config) RunnableProjects

func (c *Config) RunnableProjects() []*Project

RunnableProjects returns the Project configuration of each Project that has a docker-compose.yml file and is not hidden by configuration.

type LogConfig

type LogConfig struct {
	Level string `mapstructure:"level"`
}

LogConfig holds the logging related configuration.

type Project

type Project struct {
	// The paths of the docker compose files for this project. Can be
	// relative or absolute paths.
	DockerComposeFilenames []string `mapstructure:"docker_compose_files"`
	// The path of the root of the project (or its basename). Do we need this?
	Directory string `mapstructure:"directory"`
	// Ignored if set by user.
	Name string `mapstructure:"name"`
	// Alternate names for this project.
	Aliases []string `mapstructure:"aliases"`
	// Whether project should be included for use by this project, default false
	Hidden bool `mapstructure:"hidden"`
	// Shell used to enter the project container with 'sh' command,
	// default is /bin/bash
	Shell string `mapstructure:"shell"`
}

Project configuration structure. This must be used when using more than one docker-compose.yml file for a project.

type Registry

type Registry struct {
	// User readable name, not used by the docker client
	Name string `mapstructure:"name"`
	URL  string `mapstructure:"url"`
	// TODO: other forms of auth exist and should be supported, but this is
	// what I need..
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`

	// Sometimes these can be firewalled, so a default timeout of 2 seconds
	// is provided, though can be tweaked here
	TimeoutSeconds int64 `mapstructure:"timeout_seconds"`

	// if login or connection fails, should dev continue with command or
	// fail hard.  Default is True
	ContinueOnFailure bool `mapstructure:"continue_on_failure"`
}

Registry repesents the configuration required to model a container registry. Users can configure their project to be dependent on a registry. When this occurs, we will login to the container registry using the configuration provided here. This will allow users to host their images in private image repos.

Directories

Path Synopsis
cmd
dev command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL