Further parameterize Makefile to make it easier for me to reuse
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a60ff562c7
commit
2a03ef21ad
69
Makefile
69
Makefile
@ -1,4 +1,5 @@
|
|||||||
DOCKER_TAG ?= dockron-dev-${USER}
|
OUTPUT ?= dockron
|
||||||
|
DOCKER_TAG ?= $(OUTPUT)-dev-$(USER)
|
||||||
GIT_TAG_NAME := $(shell git tag -l --contains HEAD)
|
GIT_TAG_NAME := $(shell git tag -l --contains HEAD)
|
||||||
GIT_SHA := $(shell git rev-parse HEAD)
|
GIT_SHA := $(shell git rev-parse HEAD)
|
||||||
VERSION := $(if $(GIT_TAG_NAME),$(GIT_TAG_NAME),$(GIT_SHA))
|
VERSION := $(if $(GIT_TAG_NAME),$(GIT_TAG_NAME),$(GIT_SHA))
|
||||||
@ -42,45 +43,45 @@ check:
|
|||||||
pre-commit run --all-files
|
pre-commit run --all-files
|
||||||
|
|
||||||
# Output target
|
# Output target
|
||||||
dockron: $(GOFILES)
|
$(OUTPUT): $(GOFILES)
|
||||||
@echo Version: $(VERSION)
|
@echo Version: $(VERSION)
|
||||||
go build -ldflags '-X "main.version=${VERSION}"' -o dockron
|
go build -ldflags '-X "main.version=$(VERSION)"' -o $(OUTPUT)
|
||||||
|
|
||||||
# Alias for building
|
# Alias for building
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build: dockron
|
build: $(OUTPUT)
|
||||||
|
|
||||||
dockron-darwin-amd64: $(GOFILES)
|
$(OUTPUT)-darwin-amd64: $(GOFILES)
|
||||||
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 \
|
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 \
|
||||||
go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
|
go build -ldflags '-X "main.version=$(VERSION)"' -a -installsuffix nocgo \
|
||||||
-o dockron-darwin-amd64
|
-o $(OUTPUT)-darwin-amd64
|
||||||
|
|
||||||
dockron-linux-amd64: $(GOFILES)
|
$(OUTPUT)-linux-amd64: $(GOFILES)
|
||||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
|
||||||
go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
|
go build -ldflags '-X "main.version=$(VERSION)"' -a -installsuffix nocgo \
|
||||||
-o dockron-linux-amd64
|
-o $(OUTPUT)-linux-amd64
|
||||||
|
|
||||||
dockron-linux-arm: $(GOFILES)
|
$(OUTPUT)-linux-arm: $(GOFILES)
|
||||||
GOOS=linux GOARCH=arm CGO_ENABLED=0 \
|
GOOS=linux GOARCH=arm CGO_ENABLED=0 \
|
||||||
go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
|
go build -ldflags '-X "main.version=$(VERSION)"' -a -installsuffix nocgo \
|
||||||
-o dockron-linux-arm
|
-o $(OUTPUT)-linux-arm
|
||||||
|
|
||||||
dockron-linux-arm64: $(GOFILES)
|
$(OUTPUT)-linux-arm64: $(GOFILES)
|
||||||
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
|
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
|
||||||
go build -ldflags '-X "main.version=${VERSION}"' -a -installsuffix nocgo \
|
go build -ldflags '-X "main.version=$(VERSION)"' -a -installsuffix nocgo \
|
||||||
-o dockron-linux-arm64
|
-o $(OUTPUT)-linux-arm64
|
||||||
|
|
||||||
.PHONY: build-linux-static
|
.PHONY: build-linux-static
|
||||||
build-linux-static: dockron-linux-amd64 dockron-linux-arm dockron-linux-arm64
|
build-linux-static: $(OUTPUT)-linux-amd64 $(OUTPUT)-linux-arm $(OUTPUT)-linux-arm64
|
||||||
|
|
||||||
.PHONY: build-all-static
|
.PHONY: build-all-static
|
||||||
build-all-static: dockron-darwin-amd64 build-linux-static
|
build-all-static: $(OUTPUT)-darwin-amd64 build-linux-static
|
||||||
|
|
||||||
# Cleans all build artifacts
|
# Cleans all build artifacts
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f dockron
|
rm -f $(OUTPUT)
|
||||||
rm -f dockron-linux-*
|
rm -f $(OUTPUT)-linux-*
|
||||||
|
|
||||||
# Cleans vendor directory
|
# Cleans vendor directory
|
||||||
.PHONY: clean-vendor
|
.PHONY: clean-vendor
|
||||||
@ -88,17 +89,17 @@ clean-vendor:
|
|||||||
rm -fr ./vendor
|
rm -fr ./vendor
|
||||||
|
|
||||||
.PHONY: docker-build
|
.PHONY: docker-build
|
||||||
docker-build: dockron-linux-amd64
|
docker-build: $(OUTPUT)-linux-amd64
|
||||||
docker build . -t ${DOCKER_TAG}-linux-amd64
|
docker build . -t $(DOCKER_TAG)-linux-amd64
|
||||||
|
|
||||||
# Cross build for arm architechtures
|
# Cross build for arm architechtures
|
||||||
.PHONY: docker-build-arm
|
.PHONY: docker-build-arm
|
||||||
docker-build-arm: dockron-linux-arm
|
docker-build-arm: $(OUTPUT)-linux-arm
|
||||||
docker build --build-arg REPO=arm32v7 --build-arg ARCH=arm . -t ${DOCKER_TAG}-linux-arm
|
docker build --build-arg REPO=arm32v7 --build-arg ARCH=arm . -t $(DOCKER_TAG)-linux-arm
|
||||||
|
|
||||||
.PHONY: docker-build-arm
|
.PHONY: docker-build-arm
|
||||||
docker-build-arm64: dockron-linux-arm64
|
docker-build-arm64: $(OUTPUT)-linux-arm64
|
||||||
docker build --build-arg REPO=arm64v8 --build-arg ARCH=arm64 . -t ${DOCKER_TAG}-linux-arm64
|
docker build --build-arg REPO=arm64v8 --build-arg ARCH=arm64 . -t $(DOCKER_TAG)-linux-arm64
|
||||||
|
|
||||||
.PHONY: docker-run
|
.PHONY: docker-run
|
||||||
docker-run: docker-build
|
docker-run: docker-build
|
||||||
@ -107,30 +108,30 @@ docker-run: docker-build
|
|||||||
# Cross run on host architechture
|
# Cross run on host architechture
|
||||||
.PHONY: docker-run-arm
|
.PHONY: docker-run-arm
|
||||||
docker-run-arm: docker-build-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
|
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG)-linux-arm
|
||||||
|
|
||||||
.PHONY: docker-run-arm64
|
.PHONY: docker-run-arm64
|
||||||
docker-run-arm64: docker-build-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
|
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock --name $(DOCKER_TAG)-run $(DOCKER_TAG)-linux-arm64
|
||||||
|
|
||||||
# Multi stage builds
|
# Multi stage builds
|
||||||
.PHONY: docker-staged-build
|
.PHONY: docker-staged-build
|
||||||
docker-staged-build:
|
docker-staged-build:
|
||||||
docker build --build-arg VERSION=${VERSION} \
|
docker build --build-arg VERSION=$(VERSION) \
|
||||||
-t ${DOCKER_TAG}-linux-amd64 \
|
-t $(DOCKER_TAG)-linux-amd64 \
|
||||||
-f Dockerfile.multi-stage .
|
-f Dockerfile.multi-stage .
|
||||||
|
|
||||||
# Cross build for arm architechtures
|
# Cross build for arm architechtures
|
||||||
.PHONY: docker-staged-build-arm
|
.PHONY: docker-staged-build-arm
|
||||||
docker-staged-build-arm:
|
docker-staged-build-arm:
|
||||||
docker build --build-arg VERSION=${VERSION} \
|
docker build --build-arg VERSION=$(VERSION) \
|
||||||
--build-arg REPO=arm32v7 --build-arg ARCH=arm -t ${DOCKER_TAG}-linux-arm \
|
--build-arg REPO=arm32v7 --build-arg ARCH=arm -t $(DOCKER_TAG)-linux-arm \
|
||||||
-f Dockerfile.multi-stage .
|
-f Dockerfile.multi-stage .
|
||||||
|
|
||||||
.PHONY: docker-staged-build-arm
|
.PHONY: docker-staged-build-arm
|
||||||
docker-staged-build-arm64:
|
docker-staged-build-arm64:
|
||||||
docker build --build-arg VERSION=${VERSION} \
|
docker build --build-arg VERSION=$(VERSION) \
|
||||||
--build-arg REPO=arm64v8 --build-arg ARCH=arm64 -t ${DOCKER_TAG}-linux-arm64 \
|
--build-arg REPO=arm64v8 --build-arg ARCH=arm64 -t $(DOCKER_TAG)-linux-arm64 \
|
||||||
-f Dockerfile.multi-stage .
|
-f Dockerfile.multi-stage .
|
||||||
|
|
||||||
.PHONY: docker-example
|
.PHONY: docker-example
|
||||||
|
Loading…
Reference in New Issue
Block a user