From a2d6550eddc9c4e619b3653a35c8b9c2263bc0d1 Mon Sep 17 00:00:00 2001 From: Ruslan Popov Date: Sat, 7 Feb 2026 12:57:30 +0300 Subject: [PATCH] Fix Makefile tasks --- Makefile | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index c6716b6..6ca5d3c 100644 --- a/Makefile +++ b/Makefile @@ -3,45 +3,71 @@ PACKAGE := backend SHELL := /bin/bash REGISTRY := registry.halfakop.ru REPOSITORY := $(NAMESPACE)/$(PACKAGE) +PLATFORM ?= --platform=linux/amd64 SOURCE_VERSION ?= $(shell cat VERSION) SOURCE_COMMIT ?= $(shell git rev-parse --short=8 HEAD) GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed s,feature/,,g) IMAGE_NAME_TAGGED = $(REPOSITORY):$(SOURCE_VERSION) -EXEC=$(PACKAGE).run +EXEC=service +TEST_PACKAGES := $(shell go list ./...) all: help help: - @echo "app - build the application" - @echo "tests - run tests" - @echo "run - run application locally" - @echo "clean - clean build environment" + @printf "\nMain make targets:\n" + @printf " make app - Download deps, fix, build app (binary: %s)\n" "$(EXEC)" + @printf " make test - Run unit tests\n" + @printf " make test-integration - Run tests with integration tag\n" + @printf " make run - Build then run locally\n" + @printf " make clean - Clean build artifacts\n" + @printf " make release - Clean, build image, login, push\n" + @printf "\nVariables:\n" + @printf " NAMESPACE=%s\n" "$(NAMESPACE)" + @printf " PACKAGE=%s\n" "$(PACKAGE)" + @printf " IMAGE_NAME_TAGGED=%s\n" "$(IMAGE_NAME_TAGGED)" + @printf " EXEC=%s\n\n" "$(EXEC)" + +download: + @echo "Download dependencies" + @go mod download fix: + @echo "Fix code" @go fix ./... -app: fix +app: download fix + @echo "Build application" @go build -o ./${EXEC} ./src -tests: build - @go test ./... +tests: app + @echo "Run unit tests" + @go test -count=1 $(TEST_PACKAGES) -run: +test-integration: + @echo "Run integration tests (tag: integration)" + @go test -tags=integration -count=1 $(TEST_PACKAGES) + +run: app + @echo "Run application" @./${EXEC} clean: - @rm -rf ./${EXEC}% + @echo "Clean build environment" + @rm -rf ./${EXEC} release: title clean build login push build: - docker build --compress \ + DOCKER_BUILDKIT=0 \ + docker build $(PLATFORM) --progress=plain --compress \ -t $(IMAGE_NAME_TAGGED) \ -t $(REGISTRY)/$(IMAGE_NAME_TAGGED) \ --build-arg SOURCE_VERSION=$(SOURCE_VERSION) \ --build-arg SOURCE_COMMIT=$(SOURCE_COMMIT) \ + --build-arg GOPROXY=$(GOPROXY) \ + --build-arg GONOSUMDB=$(GONOSUMDB) \ ${DOCKER_OPTS} \ -f Dockerfile . @@ -54,4 +80,4 @@ login: push: docker push $(REGISTRY)/$(IMAGE_NAME_TAGGED) -.PHONY: tests release build login push \ No newline at end of file +.PHONY: tests test test-integration release build login push