dockron/Makefile

142 lines
3.9 KiB
Makefile
Raw Normal View History

OUTPUT ?= dockron
DOCKER_TAG ?= $(OUTPUT)-dev-$(USER)
2019-06-28 17:24:41 +00:00
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))
2018-08-03 18:35:49 +00:00
2020-08-07 23:00:19 +00:00
GOFILES = *.go go.mod go.sum
2018-08-03 01:11:07 +00:00
.PHONY: default
default: build
2020-08-19 20:04:37 +00:00
.PHONY: all
all: check test itest
2018-08-03 01:11:07 +00:00
# Downloads dependencies into vendor directory
2020-08-07 23:00:19 +00:00
vendor: $(GOFILES)
2019-06-08 00:08:15 +00:00
go mod vendor
2018-08-03 01:11:07 +00:00
# Runs the application, useful while developing
.PHONY: run
2019-06-08 00:08:15 +00:00
run:
go run . -watch 10s -debug
2018-08-03 01:11:07 +00:00
2020-08-07 21:17:30 +00:00
.PHONY: test
test:
go test -coverprofile=coverage.out
go tool cover -func=coverage.out
@go tool cover -func=coverage.out | awk -v target=75.0% \
2020-08-07 21:17:30 +00:00
'/^total:/ { print "Total coverage: " $$3 " Minimum coverage: " target; if ($$3+0.0 >= target+0.0) print "ok"; else { print "fail"; exit 1; } }'
2020-08-19 20:04:37 +00:00
.PHONY: itest
itest:
./itest/itest.sh
2020-08-07 22:00:30 +00:00
# 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
2018-08-03 01:11:07 +00:00
# Output target
$(OUTPUT): $(GOFILES)
2019-06-28 17:24:41 +00:00
@echo Version: $(VERSION)
go build -ldflags '-X "main.version=$(VERSION)"' -o $(OUTPUT)
2018-08-03 01:11:07 +00:00
# Alias for building
.PHONY: build
build: $(OUTPUT)
2018-08-03 01:11:07 +00:00
$(OUTPUT)-darwin-amd64: $(GOFILES)
2019-06-28 17:24:41 +00:00
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 \
go build -ldflags '-X "main.version=$(VERSION)"' -a -installsuffix nocgo \
-o $(OUTPUT)-darwin-amd64
2019-06-28 17:24:41 +00:00
$(OUTPUT)-linux-amd64: $(GOFILES)
2019-06-28 17:24:41 +00:00
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
go build -ldflags '-X "main.version=$(VERSION)"' -a -installsuffix nocgo \
-o $(OUTPUT)-linux-amd64
2019-06-07 22:40:04 +00:00
$(OUTPUT)-linux-arm: $(GOFILES)
2019-06-28 17:24:41 +00:00
GOOS=linux GOARCH=arm CGO_ENABLED=0 \
go build -ldflags '-X "main.version=$(VERSION)"' -a -installsuffix nocgo \
-o $(OUTPUT)-linux-arm
2019-06-07 22:40:04 +00:00
$(OUTPUT)-linux-arm64: $(GOFILES)
2019-06-28 17:24:41 +00:00
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
go build -ldflags '-X "main.version=$(VERSION)"' -a -installsuffix nocgo \
-o $(OUTPUT)-linux-arm64
2019-06-28 17:24:41 +00:00
.PHONY: build-linux-static
build-linux-static: $(OUTPUT)-linux-amd64 $(OUTPUT)-linux-arm $(OUTPUT)-linux-arm64
2019-06-07 22:40:04 +00:00
.PHONY: build-all-static
build-all-static: $(OUTPUT)-darwin-amd64 build-linux-static
2019-06-07 22:40:04 +00:00
2018-08-03 01:11:07 +00:00
# Cleans all build artifacts
.PHONY: clean
clean:
rm -f $(OUTPUT)
rm -f $(OUTPUT)-linux-*
2018-08-03 01:11:07 +00:00
# Cleans vendor directory
.PHONY: clean-vendor
clean-vendor:
rm -fr ./vendor
2018-08-03 18:35:49 +00:00
.PHONY: docker-build
docker-build: $(OUTPUT)-linux-amd64
docker build . -t $(DOCKER_TAG)-linux-amd64
2019-06-07 22:40:04 +00:00
# Cross build for arm architechtures
.PHONY: docker-build-arm
docker-build-arm: $(OUTPUT)-linux-arm
docker build --build-arg REPO=arm32v7 --build-arg ARCH=arm . -t $(DOCKER_TAG)-linux-arm
2019-06-07 22:40:04 +00:00
.PHONY: docker-build-arm
docker-build-arm64: $(OUTPUT)-linux-arm64
docker build --build-arg REPO=arm64v8 --build-arg ARCH=arm64 . -t $(DOCKER_TAG)-linux-arm64
2018-08-03 18:35:49 +00:00
.PHONY: docker-run
2019-06-07 22:40:04 +00:00
docker-run: docker-build
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG)-linux-amd64
# Cross run on host architechture
.PHONY: docker-run-arm
docker-run-arm: docker-build-arm
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG)-linux-arm
2019-06-07 22:40:04 +00:00
.PHONY: docker-run-arm64
docker-run-arm64: docker-build-arm64
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG)-linux-arm64
# Multi stage builds
.PHONY: docker-staged-build
docker-staged-build:
docker build --build-arg VERSION=$(VERSION) \
-t $(DOCKER_TAG)-linux-amd64 \
-f Dockerfile.multi-stage .
# Cross build for arm architechtures
.PHONY: docker-staged-build-arm
docker-staged-build-arm:
docker build --build-arg VERSION=$(VERSION) \
--build-arg REPO=arm32v7 --build-arg ARCH=arm -t $(DOCKER_TAG)-linux-arm \
-f Dockerfile.multi-stage .
.PHONY: docker-staged-build-arm
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 .
2020-08-07 23:00:19 +00:00
.PHONY: docker-example
docker-example:
# Uses multistage
docker-compose build
docker-compose up