Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/basic git and tar support #226

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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', './...']
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
4 changes: 2 additions & 2 deletions config/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/dnephin/configtf"
pth "github.com/dnephin/configtf/path"
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 @@ -239,7 +239,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
1 change: 1 addition & 0 deletions config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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 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
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="# "
6 changes: 3 additions & 3 deletions dockerfiles/Dockerfile.lint
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM golang:1.14-alpine
FROM golang:1.17-alpine

RUN apk add -U python3 py-pip python3-dev musl-dev gcc git bash
RUN apk add -U python3 py3-pip python3-dev musl-dev gcc git bash
RUN pip install --ignore-installed pre-commit

COPY --from=golangci/golangci-lint:v1.24.0 /usr/bin/golangci-lint /usr/bin/golangci-lint
COPY --from=golangci/golangci-lint:v1.42.1 /usr/bin/golangci-lint /usr/bin/golangci-lint

WORKDIR /go/src/github.com/dnephin/dobi
COPY .pre-commit-config.yaml ./
Expand Down
4 changes: 2 additions & 2 deletions dockerfiles/Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:3.8
FROM alpine:3.13

RUN apk --no-cache add bash curl
RUN export VERSION="v0.12.0"; \
RUN export VERSION="v0.14.0"; \
export URL="https://github.com/tcnksm/ghr/releases/download/"; \
curl -sL "${URL}/${VERSION}/ghr_${VERSION}_linux_amd64.tar.gz" | \
tar -xz && mv */ghr /usr/bin/ghr
Expand Down
8 changes: 1 addition & 7 deletions dockerfiles/Dockerfile.test-examples
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
FROM docker/compose:1.8.0
FROM docker/compose:alpine-1.29.2

RUN apk add -U bash git curl expect

RUN export VERSION=1.13.1; \
curl -Ls https://get.docker.com/builds/Linux/x86_64/docker-$VERSION.tgz | \
tar -xz docker/docker && \
mv docker/docker /usr/local/bin/ && \
rmdir docker
16 changes: 10 additions & 6 deletions execenv/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/dnephin/dobi/logging"
git "github.com/gogits/git-module"
git "github.com/gogs/git-module"
"github.com/metakeule/fmtdate"
"github.com/pkg/errors"
fasttmpl "github.com/valyala/fasttemplate"
Expand Down Expand Up @@ -140,26 +140,30 @@ func valueFromGit(out io.Writer, cwd string, tag, defValue string) (int, error)
return writeValue(defValue)
}

repo, err := git.OpenRepository(cwd)
repo, err := git.Open(cwd)
if err != nil {
return writeError(err)
}

switch tag {
case "branch":
branch, err := repo.GetHEADBranch()
branch, err := repo.SymbolicRef()
if err != nil {
return writeError(err)
}
return writeValue(branch.Name)
branchName := git.RefShortName(branch)
if branch == branchName {
return writeError(errors.New("HEAD is not referenced by a branch"))
}
return writeValue(branchName)
case "sha":
commit, err := repo.GetCommit("HEAD")
commit, err := repo.CatFileCommit("HEAD")
if err != nil {
return writeError(err)
}
return writeValue(commit.ID.String())
case "short-sha":
commit, err := repo.GetCommit("HEAD")
commit, err := repo.CatFileCommit("HEAD")
if err != nil {
return writeError(err)
}
Expand Down
1 change: 1 addition & 0 deletions execenv/user_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package execenv
Expand Down
72 changes: 46 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
module github.com/dnephin/dobi

go 1.13
go 1.17

require (
github.com/Unknwon/com v0.0.0-20170213072014-0db4a625e949 // indirect
github.com/dnephin/configtf v0.0.0-20161020003418-6b0d1fdf5e68
github.com/dnephin/go-os-user v0.0.0-20161029070903-44e2994deb1e
github.com/docker/cli v0.0.0-20200303215952-eb310fca4956
github.com/docker/docker v17.12.0-ce-rc1.0.20200309214505-aa6a9891b09c+incompatible
github.com/docker/cli v20.10.9+incompatible
github.com/docker/docker v20.10.9+incompatible
github.com/docker/go-connections v0.4.0
github.com/fsouza/go-dockerclient v1.6.4
github.com/gogits/git-module v0.0.0-20170608205522-1de103dca47a
github.com/golang/mock v1.1.1
github.com/google/go-cmp v0.4.0
github.com/kballard/go-shellquote v0.0.0-20170619183022-cd60e84ee657
github.com/mcuadros/go-version v0.0.0-20161105183618-257f7b9a7d87 // indirect
github.com/metakeule/fmtdate v1.1.2-0.20150502212323-427373e7d2f8
github.com/opencontainers/runc v1.0.0-rc3.0.20170716065720-825b5c020ace // indirect
github.com/pkg/errors v0.8.1
github.com/renstrom/dedent v1.0.1-0.20150819195903-020d11c3b9c0
github.com/sirupsen/logrus v1.4.1
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v0.0.0-20170224212429-dcecefd839c4
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
golang.org/x/time v0.0.0-20170927054726-6dc17368e09b // indirect
gopkg.in/yaml.v2 v2.2.2
gotest.tools/v3 v3.0.2
github.com/fsouza/go-dockerclient v1.7.4
github.com/gogs/git-module v1.1.5
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.6
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/lithammer/dedent v1.1.0
github.com/metakeule/fmtdate v1.1.2
github.com/moby/moby v20.10.9+incompatible
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/valyala/fasttemplate v1.2.1
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
gopkg.in/yaml.v2 v2.4.0
gotest.tools/v3 v3.0.3
)

replace github.com/spf13/cobra => github.com/dnephin/cobra v1.5.2-0.20170125185912-5d13e8c9d917

replace github.com/Nvveen/Gotty => github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd
require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/Microsoft/hcsshim v0.9.0 // indirect
github.com/containerd/cgroups v1.0.2 // indirect
github.com/containerd/containerd v1.5.7 // indirect
github.com/containerd/continuity v0.2.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2 // indirect
github.com/moby/buildkit v0.9.1 // indirect
github.com/moby/sys/mount v0.2.0 // indirect
github.com/moby/sys/mountinfo v0.4.1 // indirect
github.com/moby/sys/symlink v0.1.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runc v1.0.2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/sys v0.0.0-20211022215931-8e5104632af7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
Loading