1
0
Fork 0

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

Dieser Commit ist enthalten in:
IamTheFij 2020-08-07 15:00:30 -07:00
Ursprung 607d364d29
Commit bda0ce4b1f
7 geänderte Dateien mit 56 neuen und 25 gelöschten Zeilen

21
.pre-commit-config.yaml Normale Datei
Datei anzeigen

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

Datei anzeigen

@ -1,8 +1,6 @@
ARG REPO=library
FROM ${REPO}/busybox:latest
WORKDIR /root/
FROM scratch
ARG ARCH=amd64
COPY ./dockron-linux-${ARCH} ./dockron
COPY ./dockron-linux-${ARCH} /dockron
ENTRYPOINT [ "./dockron" ]
ENTRYPOINT [ "/dockron" ]

Datei anzeigen

@ -1,6 +1,7 @@
ARG REPO=library
FROM golang:1.12-alpine AS builder
# hadolint ignore=DL3018
RUN apk add --no-cache git
RUN mkdir /app
@ -16,8 +17,7 @@ ARG VERSION=dev
ENV CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH}
RUN go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o dockron .
FROM ${REPO}/busybox:latest
WORKDIR /root/
COPY --from=builder /app/dockron .
FROM scratch
COPY --from=builder /app/dockron /
ENTRYPOINT [ "./dockron" ]
ENTRYPOINT [ "/dockron" ]

16
LICENSE
Datei anzeigen

@ -1,5 +1,5 @@
Apache License
Version 2.0, January 2004
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
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]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with 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 obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Datei anzeigen

@ -22,6 +22,16 @@ test:
# @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; } }'
# 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
dockron:
@echo Version: $(VERSION)

13
main.go
Datei anzeigen

@ -3,14 +3,15 @@ package main
import (
"flag"
"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"
"os"
"strings"
"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 (
@ -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)
} else {
// 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 = cron.New()
// Schedule jobs again
jobs := QueryScheduledJobs(client)
ScheduleJobs(c, jobs)
c.Start()
// Sleep until the next query time

Datei anzeigen

@ -2,11 +2,12 @@ package main
import (
"fmt"
"log"
"testing"
dockerTypes "github.com/docker/docker/api/types"
"github.com/robfig/cron/v3"
"golang.org/x/net/context"
"log"
"testing"
)
// FakeDockerClient is used to test without interracting with Docker