Simple scheduling for short-running Docker containers https://blog.iamthefij.com/2018/11/19/introducing-dockron-scheduling/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. DOCKER_TAG ?= dockron-dev-${USER}
  2. GIT_TAG_NAME := $(shell git tag -l --contains HEAD)
  3. GIT_SHA := $(shell git rev-parse HEAD)
  4. VERSION := $(if $(GIT_TAG_NAME),$(GIT_TAG_NAME),$(GIT_SHA))
  5. .PHONY: default
  6. default: build
  7. # Downloads dependencies into vendor directory
  8. vendor:
  9. go mod vendor
  10. # Runs the application, useful while developing
  11. .PHONY: run
  12. run:
  13. go run *.go
  14. # Output target
  15. dockron:
  16. @echo Version: $(VERSION)
  17. go build -ldflags '-X "main.version=${VERSION}"' -o dockron
  18. # Alias for building
  19. .PHONY: build
  20. build: dockron
  21. dockron-darwin-amd64:
  22. GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 \
  23. go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
  24. -o dockron-darwin-amd64
  25. dockron-linux-amd64:
  26. GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
  27. go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
  28. -o dockron-linux-amd64
  29. dockron-linux-arm:
  30. GOOS=linux GOARCH=arm CGO_ENABLED=0 \
  31. go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
  32. -o dockron-linux-arm
  33. dockron-linux-arm64:
  34. GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
  35. go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
  36. -o dockron-linux-arm64
  37. .PHONY: build-linux-static
  38. build-linux-static: dockron-linux-amd64 dockron-linux-arm dockron-linux-arm64
  39. .PHONY: build-all-static
  40. build-all-static: dockron-darwin-amd64 build-linux-static
  41. # Cleans all build artifacts
  42. .PHONY: clean
  43. clean:
  44. rm -f dockron
  45. rm -f dockron-linux-*
  46. # Cleans vendor directory
  47. .PHONY: clean-vendor
  48. clean-vendor:
  49. rm -fr ./vendor
  50. .PHONY: docker-build
  51. docker-build: dockron-linux-amd64
  52. docker build . -t ${DOCKER_TAG}-linux-amd64
  53. # Cross build for arm architechtures
  54. .PHONY: docker-build-arm
  55. docker-build-arm: dockron-linux-arm
  56. docker build --build-arg REPO=arm32v7 --build-arg ARCH=arm . -t ${DOCKER_TAG}-linux-arm
  57. .PHONY: docker-build-arm
  58. docker-build-arm64: dockron-linux-arm64
  59. docker build --build-arg REPO=arm64v8 --build-arg ARCH=arm64 . -t ${DOCKER_TAG}-linux-arm64
  60. .PHONY: docker-run
  61. docker-run: docker-build
  62. docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG)-linux-amd64
  63. # Cross run on host architechture
  64. .PHONY: docker-run-arm
  65. docker-run-arm: docker-build-arm
  66. docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run ${DOCKER_TAG}-linux-arm
  67. .PHONY: docker-run-arm64
  68. docker-run-arm64: docker-build-arm64
  69. docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run ${DOCKER_TAG}-linux-arm64
  70. # Multi stage builds
  71. .PHONY: docker-staged-build
  72. docker-staged-build:
  73. docker build --build-arg VERSION=${VERSION} \
  74. -t ${DOCKER_TAG}-linux-amd64 \
  75. -f Dockerfile.multi-stage .
  76. # Cross build for arm architechtures
  77. .PHONY: docker-staged-build-arm
  78. docker-staged-build-arm:
  79. docker build --build-arg VERSION=${VERSION} \
  80. --build-arg REPO=arm32v7 --build-arg ARCH=arm -t ${DOCKER_TAG}-linux-arm \
  81. -f Dockerfile.multi-stage .
  82. .PHONY: docker-staged-build-arm
  83. docker-staged-build-arm64:
  84. docker build --build-arg VERSION=${VERSION} \
  85. --build-arg REPO=arm64v8 --build-arg ARCH=arm64 -t ${DOCKER_TAG}-linux-arm64 \
  86. -f Dockerfile.multi-stage .