Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvam committed May 20, 2019
2 parents 329dc9c + 2e1c7f6 commit 8f23fac
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 117 deletions.
17 changes: 10 additions & 7 deletions .dunner.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
build:
- image: node:10.15.0
command: ["node", "--version"]
- image: node:10.15.0
command: ["npm", "--version"]
commands:
- ["node", "--version"]
- ["npm", "--version"]
- image: alpine
dir: pkg
command: ["pwd"]
- image: alpine
command: ["apk", "update"]
commands:
- ["apk", "update"]
- image: alpine
command: ["printenv"]
commands:
- ["printenv"]
envs:
- PERM=775
- ID=dunner
- DIR=`$HOME`
- name: '@show'
- follow: 'show'
args:
- '/root'
show:
- image: alpine
command: ["ls", "$1"]
commands:
- ["ls", "$1"]
mounts:
- '~/Downloads:/root/down'
- ~/Pictures:/root/pics:wr
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@

# Environment file
.env

# Coverage files
coverage*

# IDE files
.idea/*
39 changes: 29 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all install test build clean
ALL_PACKAGES=$(shell go list ./... | grep -v "vendor")

SHA=$(shell git rev-list HEAD --max-count=1 --abbrev-commit)
TAG?=$(shell git tag -l --contains HEAD)
Expand All @@ -8,23 +8,42 @@ ifeq ($(VERSION),)
VERSION := latest
endif


#Go parameters
GOCMD=go
GOINSTALL=$(GOCMD) install
GOTEST=$(GOCMD) test
DEP=dep
.PHONY : all install vet fmt test lint build

all: build
all: build test fmt lint vet

install:
@$(DEP) ensure
setup: install
@go get -u golang.org/x/lint/golint

test: install
@$(GOTEST) -v ./...
install:
@$(DEP) ensure

build: install
build: install
@$(GOINSTALL) -ldflags "-X main.version=$(VERSION)-$(SHA) -s"

clean:
rm -rf *
test: build
@go test -v $(ALL_PACKAGES)

vet:
@go vet $(ALL_PACKAGES)

fmt:
@go fmt $(ALL_PACKAGES)

lint:
@golint -set_exit_status $(ALL_PACKAGES)

precommit: build test fmt lint vet

test-coverage:
@echo "mode: count" > coverage-all.out

$(foreach pkg, $(ALL_PACKAGES),\
go test -coverprofile=coverage.out -covermode=count $(pkg);\
tail -n +2 coverage.out >> coverage-all.out;)
@go tool cover -html=coverage-all.out -o coverage.html
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
# Dunner

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b2275e331d2745dc9527d45efbbf2da2)](https://app.codacy.com/app/Leopardslab/dunner?utm_source=github.com&utm_medium=referral&utm_content=leopardslab/dunner&utm_campaign=Badge_Grade_Dashboard)
[![Build Status](https://travis-ci.org/leopardslab/Dunner.svg?branch=master)](https://travis-ci.org/leopardslab/Dunner)

Dunner is a task runner tool like Grunt but uses Docker images like CircleCI do. You can define tasks and steps of the tasks in your `.dunner.yaml` file and then run these steps with `Dunner do taskname`
Dunner is a task runner tool like Grunt but uses Docker images like CircleCI do. You can define tasks and steps of the tasks in your `.dunner.yaml` file and then run these steps with `dunner do taskname`


Example `.dunner.yaml`

```yaml
deploy:
- image: 'emeraldsquad/sonar-scanner'
command: ['sonar', 'scan']
commands:
- ['sonar', 'scan']
- image: 'golang'
command: ['go', 'install']
commands:
- ['go', 'install']
- image: 'mesosphere/aws-cli'
command: ['aws', 'elasticbeanstalk update-application --application-name myapp']
commands:
- ['aws', 'elasticbeanstalk update-application --application-name myapp']
envs:
- AWS_ACCESS_KEY_ID=`$AWS_KEY`
- AWS_SECRET_ACCESS_KEY=`$AWS_SECRET`
- AWS_DEFAULT_REGION=us-east1
- name: '@status' #This refers to another task and can pass args too
- follow: 'status' #This refers to another task and can pass args too
args: 'prod'
status:
- image: 'mesosphere/aws-cli'
command: ['aws', 'elasticbeanstalk describe-events --environment-name $1']
commands:
- ['aws', 'elasticbeanstalk describe-events --environment-name $1']
# This uses args passed to the task, `$1` means first arg
envs:
- AWS_ACCESS_KEY_ID=`$AWS_KEY`
Expand All @@ -32,8 +37,8 @@ status:
```
Now you can use as,
1. `Dunner do deploy`
2. `Dunner do status prod`
1. `dunner do deploy`
2. `dunner do status prod`


## NOTE
Expand All @@ -51,15 +56,15 @@ This work is still in progress. See the development plan.
- [x] Ability to mount other dirs to the task containers
- [x] Ability to use a task as a step for another task
- [x] Ability to get ENV, param, etc values from host environment variables or `.env` file
- [ ] Ability to install as a Snap package
- [ ] Ability to install as a Deb package
- [ ] Ability to install as a RPM package
- [ ] Ability to install as a Brew package
- [x] Ability to install as a Snap package

### [`v2.0`](https://github.com/leopardslab/dunner/milestone/3)
- [ ] Ability to Dry Run
- [ ] Ability to verfiy the `.dunner.yaml` file
- [ ] Ability to define multiple commands for the same step
- [ ] Ability to install as a Deb package
- [ ] Ability to install as a RPM package
- [ ] Ability to install as a Brew package

# Guides

Expand Down
8 changes: 7 additions & 1 deletion cmd/do.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ func init() {
rootCmd.AddCommand(doCmd)

// Async Mode
doCmd.Flags().BoolP("async", "A", false, "Async mode")
doCmd.Flags().BoolP("async", "A", false, "Asynchronous mode")
if err := viper.BindPFlag("Async", doCmd.Flags().Lookup("async")); err != nil {
log.Fatal(err)
}

// Dry-run mode
doCmd.Flags().Bool("dry-run", false, "Dry-run of the command")
if err := viper.BindPFlag("Dry-run", doCmd.Flags().Lookup("dry-run")); err != nil {
log.Fatal(err)
}

}

var doCmd = &cobra.Command{
Expand Down
7 changes: 3 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"fmt"
"os"

Expand All @@ -18,13 +19,11 @@ var rootCmd = &cobra.Command{
Long: `You can define a set of commands and on what Docker images these commands should run as steps. A task has many steps. Then you can run these tasks with 'dunner do nameoftask'`,
Run: func(cmd *cobra.Command, args []string) {

_, err := client.NewClientWithOpts(
client.FromEnv,
client.WithVersion(viper.GetString("DockerAPIVersion")),
)
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
log.Fatal(err)
}
cli.NegotiateAPIVersion(context.Background())

fmt.Println("Dunner running!")
},
Expand Down
1 change: 1 addition & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

G "github.com/leopardslab/dunner/pkg/global"
"github.com/spf13/cobra"
)
Expand Down
6 changes: 5 additions & 1 deletion internal/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import (
"github.com/spf13/viper"
)

func init() {
// Init function initializes the default settings for dunner
// These settings can tweaked using appropriate environment variables, or
// defining the configuration in conf present in the appropriate config files
func Init() {
// Settings file
viper.SetConfigName("settings")
viper.SetConfigType("yaml")
Expand All @@ -26,6 +29,7 @@ func init() {
// Modes
viper.SetDefault("Async", false)
viper.SetDefault("Verbose", false)
viper.SetDefault("Dry-run", false)

// Constants
viper.SetDefault("DockerAPIVersion", "1.39")
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package main

import (
"github.com/leopardslab/dunner/cmd"
"github.com/leopardslab/dunner/internal/settings"
G "github.com/leopardslab/dunner/pkg/global"
)

var version string

func main() {
settings.Init()
G.VERSION = version
cmd.Execute()
}
23 changes: 12 additions & 11 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ var (
validDirPermissionModes = []string{defaultPermissionMode, "wr", "rw", "w"}
)

type contextKey string
var configsKey = contextKey("dunnerConfigs")

type customValidation struct {
tag string
translation string
Expand All @@ -56,24 +59,22 @@ type DirMount struct {

// Task describes a single task to be run in a docker container
type Task struct {
Name string `yaml:"name"`
Image string `yaml:"image" validate:"required"`
SubDir string `yaml:"dir"`
Command []string `yaml:"command" validate:"omitempty,dive,required"`
Envs []string `yaml:"envs"`
Mounts []string `yaml:"mounts" validate:"omitempty,dive,min=1,mountdir"`
Args []string `yaml:"args"`
Name string `yaml:"name"`
Image string `yaml:"image" validate:"required"`
SubDir string `yaml:"dir"`
Command []string `yaml:"command" validate:"omitempty,dive,required"`
Commands [][]string `yaml:"commands"`
Envs []string `yaml:"envs"`
Mounts []string `yaml:"mounts" validate:"omitempty,dive,min=1,mountdir"`
Follow string `yaml:"follow"`
Args []string `yaml:"args"`
}

// Configs describes the parsed information from the dunner file
type Configs struct {
Tasks map[string][]Task `validate:"required,min=1,dive,keys,required,endkeys,required,min=1,required"`
}

type contextKey string

var configsKey = contextKey("dunnerConfigs")

// Validate validates config and returns errors.
func (configs *Configs) Validate() []error {
err := initValidator(customValidations)
Expand Down
12 changes: 7 additions & 5 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ func TestGetConfigs(t *testing.T) {
var content = []byte(`
test:
- image: node
command: ["node", "--version"]
commands:
- ["node", "--version"]
- ["npm", "--version"]
envs:
- MYVAR=MYVAL`)

Expand All @@ -39,10 +41,10 @@ test:
}

var task = Task{
Name: "",
Image: "node",
Command: []string{"node", "--version"},
Envs: []string{"MYVAR=MYVAL"},
Name: "",
Image: "node",
Commands: [][]string{{"node", "--version"}, {"npm", "--version"}},
Envs: []string{"MYVAR=MYVAL"},
}
var tasks = make(map[string][]Task)
tasks["test"] = []Task{task}
Expand Down
Loading

0 comments on commit 8f23fac

Please sign in to comment.