From 5c5fda3ddf598f6c6e206e5e9067cfc888c5344b Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 7 Aug 2020 16:00:19 -0700 Subject: [PATCH] Add example compose --- Makefile | 20 ++++++++++++++------ README.md | 4 +++- docker-compose.yml | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 docker-compose.yml diff --git a/Makefile b/Makefile index ba4341d..e69f179 100644 --- a/Makefile +++ b/Makefile @@ -4,11 +4,13 @@ GIT_TAG_NAME := $(shell git tag -l --contains HEAD) GIT_SHA := $(shell git rev-parse HEAD) VERSION := $(if $(GIT_TAG_NAME),$(GIT_TAG_NAME),$(GIT_SHA)) +GOFILES = *.go go.mod go.sum + .PHONY: default default: build # Downloads dependencies into vendor directory -vendor: +vendor: $(GOFILES) go mod vendor # Runs the application, useful while developing @@ -34,7 +36,7 @@ check: pre-commit run --all-files # Output target -dockron: +dockron: $(GOFILES) @echo Version: $(VERSION) go build -ldflags '-X "main.version=${VERSION}"' -o dockron @@ -42,22 +44,22 @@ dockron: .PHONY: build build: dockron -dockron-darwin-amd64: +dockron-darwin-amd64: $(GOFILES) GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 \ go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \ -o dockron-darwin-amd64 -dockron-linux-amd64: +dockron-linux-amd64: $(GOFILES) GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \ go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \ -o dockron-linux-amd64 -dockron-linux-arm: +dockron-linux-arm: $(GOFILES) GOOS=linux GOARCH=arm CGO_ENABLED=0 \ go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \ -o dockron-linux-arm -dockron-linux-arm64: +dockron-linux-arm64: $(GOFILES) GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \ go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \ -o dockron-linux-arm64 @@ -124,3 +126,9 @@ docker-staged-build-arm64: docker build --build-arg VERSION=${VERSION} \ --build-arg REPO=arm64v8 --build-arg ARCH=arm64 -t ${DOCKER_TAG}-linux-arm64 \ -f Dockerfile.multi-stage . + +.PHONY: docker-example +docker-example: + # Uses multistage + docker-compose build + docker-compose up diff --git a/README.md b/README.md index 54bf9f3..07a7846 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ From either an `amd64`, `arm`, or `arm64` machine, you can run Dockron using: First, be sure your container is something that is not long running and will actually exit when complete. This is for batch runs and not keeping a service running. Docker should be able to do that on it's own with a restart policy. -Create your container and add a label in the form `dockron.schedule="* * * * *"`, where the value is a valid cron expression (See the section [Cron Expression Formatting](#cron-expression-formatting)). +Create your container and add a label in the form `'dockron.schedule=* * * * *'`, where the value is a valid cron expression (See the section [Cron Expression Formatting](#cron-expression-formatting)). Dockron will now start that container peridically on the schedule. @@ -53,3 +53,5 @@ Either use a separate tool in conjunction with Dockron, or use a more robust sch ## Building If you have go on your machine, you can simply use `make build` or `make run` to build and test Dockron. If you don't have go but you do have Docker, you can still build docker images using the provide multi-stage Dockerfile! You can kick that off with `make docker-staged-build` + +There is also an example `docker-compose.yml` that will use the multi-stage build to ensure an easy sample. This can be run with `make docker-example`. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c994c8c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +--- +version: '3' + +services: + dockron: + build: + context: . + dockerfile: ./Dockerfile.multi-stage + command: ["-watch", "10s", "-debug"] + volumes: + - /var/run/docker.sock:/var/run/docker.sock:ro + + echoer: + image: busybox:latest + command: ["date"] + labels: + # Execute every minute + - 'dockron.schedule=* * * * *'