Add pre-commit and clean up
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
607d364d29
commit
bda0ce4b1f
21
.pre-commit-config.yaml
Normal file
21
.pre-commit-config.yaml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v2.4.0
|
||||||
|
hooks:
|
||||||
|
- id: check-added-large-files
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-merge-conflict
|
||||||
|
- repo: git://github.com/dnephin/pre-commit-golang
|
||||||
|
rev: v0.3.5
|
||||||
|
hooks:
|
||||||
|
- id: go-fmt
|
||||||
|
- id: go-imports
|
||||||
|
# - id: gometalinter
|
||||||
|
# - id: golangci-lint
|
||||||
|
- repo: https://github.com/IamTheFij/docker-pre-commit
|
||||||
|
rev: v2.0.0
|
||||||
|
hooks:
|
||||||
|
- id: docker-compose-check
|
||||||
|
- id: hadolint
|
@ -1,8 +1,6 @@
|
|||||||
ARG REPO=library
|
FROM scratch
|
||||||
FROM ${REPO}/busybox:latest
|
|
||||||
WORKDIR /root/
|
|
||||||
|
|
||||||
ARG ARCH=amd64
|
ARG ARCH=amd64
|
||||||
COPY ./dockron-linux-${ARCH} ./dockron
|
COPY ./dockron-linux-${ARCH} /dockron
|
||||||
|
|
||||||
ENTRYPOINT [ "./dockron" ]
|
ENTRYPOINT [ "/dockron" ]
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
ARG REPO=library
|
ARG REPO=library
|
||||||
FROM golang:1.12-alpine AS builder
|
FROM golang:1.12-alpine AS builder
|
||||||
|
|
||||||
|
# hadolint ignore=DL3018
|
||||||
RUN apk add --no-cache git
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
RUN mkdir /app
|
RUN mkdir /app
|
||||||
@ -16,8 +17,7 @@ ARG VERSION=dev
|
|||||||
ENV CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH}
|
ENV CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH}
|
||||||
RUN go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o dockron .
|
RUN go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o dockron .
|
||||||
|
|
||||||
FROM ${REPO}/busybox:latest
|
FROM scratch
|
||||||
WORKDIR /root/
|
COPY --from=builder /app/dockron /
|
||||||
COPY --from=builder /app/dockron .
|
|
||||||
|
|
||||||
ENTRYPOINT [ "./dockron" ]
|
ENTRYPOINT [ "/dockron" ]
|
||||||
|
10
Makefile
10
Makefile
@ -22,6 +22,16 @@ test:
|
|||||||
# @go tool cover -func=coverage.out | awk -v target=80.0% \
|
# @go tool cover -func=coverage.out | awk -v target=80.0% \
|
||||||
'/^total:/ { print "Total coverage: " $$3 " Minimum coverage: " target; if ($$3+0.0 >= target+0.0) print "ok"; else { print "fail"; exit 1; } }'
|
'/^total:/ { print "Total coverage: " $$3 " Minimum coverage: " target; if ($$3+0.0 >= target+0.0) print "ok"; else { print "fail"; exit 1; } }'
|
||||||
|
|
||||||
|
# Installs pre-commit hooks
|
||||||
|
.PHONY: install-hooks
|
||||||
|
install-hooks:
|
||||||
|
pre-commit install --install-hooks
|
||||||
|
|
||||||
|
# Runs pre-commit checks on files
|
||||||
|
.PHONY: check
|
||||||
|
check:
|
||||||
|
pre-commit run --all-files
|
||||||
|
|
||||||
# Output target
|
# Output target
|
||||||
dockron:
|
dockron:
|
||||||
@echo Version: $(VERSION)
|
@echo Version: $(VERSION)
|
||||||
|
13
main.go
13
main.go
@ -3,14 +3,15 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
dockerTypes "github.com/docker/docker/api/types"
|
|
||||||
dockerClient "github.com/docker/docker/client"
|
|
||||||
"github.com/robfig/cron/v3"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
dockerTypes "github.com/docker/docker/api/types"
|
||||||
|
dockerClient "github.com/docker/docker/client"
|
||||||
|
"github.com/robfig/cron/v3"
|
||||||
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -86,7 +87,7 @@ func ScheduleJobs(c *cron.Cron, jobs []ContainerStartJob) {
|
|||||||
log.Printf("Scheduled %s (%s) with schedule '%s'\n", job.Name, job.ContainerID[:10], job.Schedule)
|
log.Printf("Scheduled %s (%s) with schedule '%s'\n", job.Name, job.ContainerID[:10], job.Schedule)
|
||||||
} else {
|
} else {
|
||||||
// TODO: Track something for a healthcheck here
|
// TODO: Track something for a healthcheck here
|
||||||
log.Printf("Error scheduling %s (%s) with schedule '%s'. %v", job.Name, job.ContainerID[:10], job.Schedule, err)
|
log.Printf("Error scheduling %s (%s) with schedule '%s'. %v\n", job.Name, job.ContainerID[:10], job.Schedule, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,9 +124,9 @@ func main() {
|
|||||||
c.Stop()
|
c.Stop()
|
||||||
c = cron.New()
|
c = cron.New()
|
||||||
|
|
||||||
// Schedule jobs again
|
|
||||||
jobs := QueryScheduledJobs(client)
|
jobs := QueryScheduledJobs(client)
|
||||||
ScheduleJobs(c, jobs)
|
ScheduleJobs(c, jobs)
|
||||||
|
|
||||||
c.Start()
|
c.Start()
|
||||||
|
|
||||||
// Sleep until the next query time
|
// Sleep until the next query time
|
||||||
|
@ -2,11 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"testing"
|
||||||
|
|
||||||
dockerTypes "github.com/docker/docker/api/types"
|
dockerTypes "github.com/docker/docker/api/types"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"log"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// FakeDockerClient is used to test without interracting with Docker
|
// FakeDockerClient is used to test without interracting with Docker
|
||||||
|
Loading…
Reference in New Issue
Block a user