cookiecutter-golang/{{cookiecutter.project_slug}}/Makefile

33 lines
878 B
Makefile

BINARY = {{cookiecutter.project_slug}}
BUILD_DIR = build
BUILD_ARCH = $(shell go env GOARCH)
BUILD_OS = $(shell go env GOOS)
DOCKER_BUILD_FLAGS =
DOCKER_BUILD_PLATFORM = linux/amd64,linux/arm64,linux/arm32v6,linux/arm32v7
DOCKER_BUILD_TAG = {{cookiecutter.docker_username}}/{{cookiecutter.project_slug}}
.PHONY: all
all: clean build
.PHONY:build
build: $(BUILD_DIR)/$(BINARY)
$(BUILD_DIR)/$(BINARY):
GOARCH=$(BUILD_ARCH) GOOS=$(BUILD_OS) go build -o $(BUILD_DIR)/$(BINARY) cmd/{{cookiecutter.project_slug}}.go
.PHONY:clean
clean:
rm -rf $(BUILD_DIR)
.PHONY: dev
dev:
go run cmd/{{cookiecutter.project_slug}}.go
.PHONY: docker-push
docker-push:
docker buildx build $(DOCKER_BUILD_FLAGS) --platform $(DOCKER_BUILD_PLATFORM) -t $(DOCKER_BUILD_TAG) . --push
.PHONY: docker-local
docker-local:
docker buildx build $(DOCKER_BUILD_FLAGS) -t $(DOCKER_BUILD_TAG) . --load