Add pre-commit and clean up
continuous-integration/drone/push Build is passing Details

This commit is contained in:
IamTheFij 2020-08-07 15:00:30 -07:00
parent 607d364d29
commit bda0ce4b1f
7 changed files with 56 additions and 25 deletions

21
.pre-commit-config.yaml Normal file
View 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

View File

@ -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" ]

View File

@ -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" ]

16
LICENSE
View File

@ -1,5 +1,5 @@
Apache License Apache License
Version 2.0, January 2004 Version 2.0, January 2004
http://www.apache.org/licenses/ http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
@ -59,14 +59,14 @@ To apply the Apache License to your work, attach the following boilerplate notic
Copyright [yyyy] [name of copyright owner] Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.

View File

@ -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
View File

@ -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

View File

@ -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