Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defaults:
- image: dnephin/circleci-alpine-step@sha256:75f925e006ea379870ea7d2ce6539072e584f62a74063d73a9b1c2fd75ec233f
steps:
- setup_remote_docker: &setup_docker
version: 17.07.0-ce
version: 20.10.6
filters: &default_filters
branches: {ignore: [gh-pages]}
tags: {only: '/v[0-9]+(\.[0-9]+)*/'}
Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:

lint:
docker:
- image: "golangci/golangci-lint:v1.24.0"
- image: "golangci/golangci-lint:v1.42.1"
steps:
- checkout
- attach_workspace: {at: /work}
Expand Down
9 changes: 1 addition & 8 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- revive
- gosimple
- ineffassign
- interfacer
- errcheck
- lll
- megacheck
Expand All @@ -30,9 +29,3 @@ linters:
- unused
- varcheck
- vet

issues:
exclude-rules:
- path: tasks/image/tag_test\.go
linters:
- interfacer
40 changes: 20 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
- repo: git://github.com/pre-commit/pre-commit-hooks
sha: v0.7.1
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
files: '(\.(go|md|sh|yml|yaml|json|ini|rst)|Dockerfile.*)$'
exclude: '^vendor/'
- id: trailing-whitespace
files: '(\.(go|md|sh|yml|yaml|json|ini|rst)|Dockerfile.*)$'
args: ['--no-markdown-linebreak-ext']
exclude: '^vendor/'
- id: check-yaml
exclude: '^vendor/'
- id: check-json
exclude: '^vendor/'
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
files: '(\.(go|md|sh|yml|yaml|json|ini|rst)|Dockerfile.*)$'
exclude: '^vendor/'
- id: trailing-whitespace
files: '(\.(go|md|sh|yml|yaml|json|ini|rst)|Dockerfile.*)$'
exclude: '^vendor/'
- id: check-yaml
exclude: '^vendor/'
- id: check-json
exclude: '^vendor/'

- repo: git://github.com/dnephin/pre-commit-golang
sha: v0.3.5
hooks:
- id: golangci-lint
args: ['-v', './...']
- repo: git://github.com/dnephin/pre-commit-golang
rev: v0.4.0
hooks:
- id: golangci-lint
args: ['-v', './...']
8 changes: 5 additions & 3 deletions cmd/autoclean.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/dnephin/dobi/config"
"github.com/dnephin/dobi/tasks"
"github.com/dnephin/dobi/tasks/task"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -39,10 +40,11 @@ func runClean(opts *dobiOptions) error {
}

func removeTasks(conf *config.Config) []string {
resources := conf.Sorted()
tasks := []string{}
for i := len(resources) - 1; i >= 0; i-- {
tasks = append(tasks, resources[i]+":rm")
for name, res := range conf.Resources {
if _, alias := res.(*config.AliasConfig); !alias {
tasks = append(tasks, name+":"+task.Remove.String())
}
}
return tasks
}
2 changes: 1 addition & 1 deletion cmd/dobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

const (
// DefaultDockerAPIVersion is the default version of the docker API to use
DefaultDockerAPIVersion = "1.25"
DefaultDockerAPIVersion = "1.41"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions config/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/dnephin/configtf"
pth "github.com/dnephin/configtf/path"
"github.com/dnephin/dobi/tasks/task"
)

// AliasConfig An **alias** resource is a list of other tasks which will be run
Expand All @@ -26,8 +27,8 @@ type AliasConfig struct {
}

// Dependencies returns the list of tasks
func (c *AliasConfig) Dependencies() []string {
return c.Tasks
func (c *AliasConfig) Dependencies() ([]task.Name, error) {
return task.ParseNames(c.Tasks)
}

// Validate the resource
Expand Down
10 changes: 7 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ func validate(config *Config) error {
if err := configtf.ValidateFields(path, resource); err != nil {
return err
}
if err := validateResourcesExist(path, config, resource.Dependencies()); err != nil {
deps, err := resource.Dependencies()
if err != nil {
return err
}
if err := validateResourcesExist(path, config, deps); err != nil {
return err
}
if err := resource.Validate(path, config); err != nil {
Expand All @@ -110,10 +114,10 @@ func validate(config *Config) error {

// validateResourcesExist checks that the list of resources is defined in the
// config and returns an error if a resources is not defined.
func validateResourcesExist(path pth.Path, c *Config, names []string) error {
func validateResourcesExist(path pth.Path, c *Config, names []task.Name) error {
missing := []string{}
for _, name := range names {
resource := task.ParseName(name).Resource()
resource := name.Resource()
if _, ok := c.Resources[resource]; !ok {
missing = append(missing, resource)
}
Expand Down
7 changes: 4 additions & 3 deletions config/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/dnephin/configtf"
pth "github.com/dnephin/configtf/path"
"github.com/dnephin/dobi/tasks/task"
)

// EnvConfig An **env** resource provides environment variables to **job** and
Expand All @@ -30,9 +31,9 @@ type EnvConfig struct {
Annotations
}

// Dependencies returns the list of job dependencies
func (c *EnvConfig) Dependencies() []string {
return []string{}
// Dependencies returns the list of env dependencies
func (c *EnvConfig) Dependencies() ([]task.Name, error) {
return []task.Name{}, nil
}

// Validate runs config validation
Expand Down
4 changes: 3 additions & 1 deletion config/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ func TestImageConfigValidateMissingDependencies(t *testing.T) {
image := sampleImageConfig()
image.Depends = []string{"one", "two"}
conf := NewConfig()
err := validateResourcesExist(pth.NewPath(""), conf, image.Dependencies())
deps, err := image.Dependencies()
assert.Assert(t, is.Nil(err))
err = validateResourcesExist(pth.NewPath(""), conf, deps)
assert.Assert(t, is.ErrorContains(err, "missing dependencies: one, two"))
}

Expand Down
21 changes: 17 additions & 4 deletions config/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (

"github.com/dnephin/configtf"
pth "github.com/dnephin/configtf/path"
"github.com/dnephin/dobi/tasks/task"
shlex "github.com/kballard/go-shellquote"
"golang.org/x/crypto/ssh/terminal"
"golang.org/x/term"
)

// JobConfig A **job** resource uses an `image`_ to run a job in a container.
Expand Down Expand Up @@ -109,8 +110,20 @@ type Device struct {
}

// Dependencies returns the list of implicit and explicit dependencies
func (c *JobConfig) Dependencies() []string {
return append([]string{c.Use}, append(c.Depends, c.Mounts...)...)
func (c *JobConfig) Dependencies() ([]task.Name, error) {
deps, err := task.ParseNames(c.Depends)
if err != nil {
return []task.Name{}, err
}
mnts, err := task.ParseNames(c.Mounts)
if err != nil {
return []task.Name{}, err
}
use, err := task.ParseName(c.Use)
if err != nil {
return []task.Name{}, err
}
return append(mnts, append(deps, use)...), nil
}

// Validate checks that all fields have acceptable values
Expand Down Expand Up @@ -239,7 +252,7 @@ func (s *ShlexSlice) TransformConfig(raw reflect.Value) error {
}

func jobFromConfig(name string, values map[string]interface{}) (Resource, error) {
isTerminal := terminal.IsTerminal(int(os.Stdin.Fd()))
isTerminal := term.IsTerminal(int(os.Stdin.Fd()))
cmd := &JobConfig{}
if isTerminal {
if _, ok := values["interactive"]; !ok {
Expand Down
5 changes: 3 additions & 2 deletions config/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/dnephin/configtf"
pth "github.com/dnephin/configtf/path"
"github.com/dnephin/dobi/tasks/task"
"github.com/dnephin/dobi/utils/fs"
)

Expand Down Expand Up @@ -44,8 +45,8 @@ type MountConfig struct {
}

// Dependencies returns an empty list, Mount resources have no dependencies
func (c *MountConfig) Dependencies() []string {
return []string{}
func (c *MountConfig) Dependencies() ([]task.Name, error) {
return []task.Name{}, nil
}

// Validate checks that all fields have acceptable values
Expand Down
8 changes: 5 additions & 3 deletions config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package config
import (
pth "github.com/dnephin/configtf/path"
"github.com/dnephin/dobi/logging"
"github.com/dnephin/dobi/tasks/task"
"github.com/pkg/errors"
)

// Resource is an interface for each configurable type
type Resource interface {
Dependencies() []string
Dependencies() ([]task.Name, error)
Validate(pth.Path, *Config) *pth.Error
Resolve(Resolver) (Resource, error)
Describe() string
Expand Down Expand Up @@ -59,6 +60,7 @@ type AnnotationFields struct {
// Tags Tags can be used to group resources. There can be configured
// multiple tags per resource. Adding a tag to a resource outputs a
// grouped list from ``dobi list -g``.
// type:list of strings
Tags []string
}

Expand All @@ -70,8 +72,8 @@ type Dependent struct {
}

// Dependencies returns the list of tasks
func (d *Dependent) Dependencies() []string {
return d.Depends
func (d *Dependent) Dependencies() ([]task.Name, error) {
return task.ParseNames(d.Depends)
}

// Resolver is an interface for a type that returns values for variables
Expand Down
2 changes: 1 addition & 1 deletion config/unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/renstrom/dedent"
"github.com/lithammer/dedent"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand Down
10 changes: 5 additions & 5 deletions dobi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ image=circleci-alpine:
dockerfile: Dockerfile.circleci
context: dockerfiles/ci

image=refactorer:
image: dnephin/go-refactor
tags: [latest]
pull: 72h

#
# Jobs
#
Expand Down Expand Up @@ -218,11 +223,6 @@ job=build-rtf:
annotations:
tags: [test]

image=refactorer:
image: dnephin/go-refactor
tags: [latest]
pull: 72h

job=refactor-shell:
use: refactorer
mounts: [source]
Expand Down
28 changes: 12 additions & 16 deletions dockerfiles/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
FROM golang:1.13-alpine
FROM golang:1.17-alpine
RUN apk add -U git bash curl tree

ARG FILEWATCHER_SHA=v0.3.2
RUN go get -d github.com/dnephin/filewatcher && \
cd /go/src/github.com/dnephin/filewatcher && \
git checkout -q "$FILEWATCHER_SHA" && \
go build -v -o /usr/bin/filewatcher . && \
ARG FILEWATCHER_VER=v0.3.2
RUN go install github.com/dnephin/filewatcher@${FILEWATCHER_VER} && \
cp /go/bin/filewatcher /usr/bin && \
rm -rf /go/src/* /go/pkg/* /go/bin/*

ARG GOTESTSUM=v0.4.0
RUN go get -d gotest.tools/gotestsum && \
cd /go/src/gotest.tools/gotestsum && \
git checkout -q "$GOTESTSUM" && \
go build -v -o /usr/bin/gotestsum . && \
ARG GOTESTSUM_VER=v1.7.0
RUN go install gotest.tools/gotestsum@${GOTESTSUM_VER} && \
cp /go/bin/gotestsum /usr/bin && \
rm -rf /go/src/* /go/pkg/* /go/bin/*

RUN go get github.com/mitchellh/gox && \
ARG GOX_VER=v1.0.1
RUN go install github.com/mitchellh/gox@${GOX_VER} && \
cp /go/bin/gox /usr/bin && \
rm -rf /go/src/* /go/pkg/* /go/bin/*

RUN go get -d github.com/golang/mock/mockgen && \
cd /go/src/github.com/golang/mock && \
git checkout -q "v1.0.0" && \
go build -v -o /usr/local/bin/mockgen ./mockgen && \
ARG MOCKGEN_VER=v1.6.0
RUN go install github.com/golang/mock/mockgen@${MOCKGEN_VER} && \
cp /go/bin/mockgen /usr/bin && \
rm -rf /go/src/* /go/pkg/* /go/bin/*

WORKDIR /go/src/github.com/dnephin/dobi
Expand Down
11 changes: 6 additions & 5 deletions dockerfiles/Dockerfile.docs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM alpine:3.10
FROM alpine:3.14

RUN apk -U add \
python \
py-pip \
python3 \
py3-pip \
go \
bash \
git \
Expand All @@ -11,11 +11,12 @@ RUN apk -U add \

ENV GOPATH=/go
RUN git config --global http.https://gopkg.in.followRedirects true
RUN go get github.com/dnephin/filewatcher && \
ARG FILEWATCHER_VER=v0.3.2
RUN go install github.com/dnephin/filewatcher@${FILEWATCHER_VER} && \
cp /go/bin/filewatcher /usr/bin/ && \
rm -rf /go/src/* /go/pkg/* /go/bin/*

RUN pip install sphinx==1.4.5
RUN pip install wheel sphinx==4.2.0

WORKDIR /go/src/github.com/dnephin/dobi
ENV PS1="# "
Loading