From 48936efa96ae17295be4e0a71be3294f0ec6aef8 Mon Sep 17 00:00:00 2001 From: Mathieu Deous Date: Mon, 2 May 2022 20:18:23 +0200 Subject: Make application go-install-able and create a docker image --- Makefile | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 931f4e7..8cdf2fd 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,48 @@ -.PHONY: clean deps tests +.PHONY: clean rebuild update-deps tests help docker docker-tests docker-publish -all: php-malware-finder/phpmalwarefinder +NAME := php-malware-finder +TAG_COMMIT := $(shell git rev-list --abbrev-commit --all --max-count=1) +VERSION := $(shell git describe --abbrev=0 --tags --exact-match $(TAG_COMMIT) 2>/dev/null || true) +IMAGE_VERSION := $(VERSION) +DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d%H%M") +ifeq ($(VERSION),) + VERSION := $(DATE) + IMAGE_VERSION := latest +endif +LDFLAGS := "-X main.version=$(VERSION)" +GO_FLAGS := -o $(NAME) -ldflags $(LDFLAGS) +IMAGE_REGISTRY := ghcr.io +IMAGE_REGISTRY_USER := jvoisin +IMAGE_NAME := $(IMAGE_REGISTRY)/$(IMAGE_REGISTRY_USER)/$(NAME) -php-malware-finder/phpmalwarefinder: - go build -o php-malware-finder/phpmalwarefinder php-malware-finder/phpmalwarefinder.go +all: php-malware-finder -clean: - rm -f php-malware-finder/phpmalwarefinder +php-malware-finder: ## Build application + @go build $(GO_FLAGS) . -deps: - go mod tidy -v +clean: ## Delete build artifacts + @rm -f $(NAME) -tests: php-malware-finder/phpmalwarefinder - @cd ./php-malware-finder && bash ./tests.sh +rebuild: clean all ## Delete build artifacts and rebuild + +update-deps: ## Update dependencies + @go get -u . + @go mod tidy -v + +tests: php-malware-finder ## Run test suite + @bash ./tests.sh + +docker: ## Build docker image + docker pull $(IMAGE_NAME):latest || true + docker build --pull -t $(IMAGE_NAME):latest . + docker tag $(IMAGE_NAME):latest $(IMAGE_NAME):$(IMAGE_VERSION) + +docker-tests: ## Run docker image against the samples folder + @docker run --rm -v $(shell pwd)/data/samples:/data $(IMAGE_NAME):latest + +docker-publish: ## Push docker image to the container registry + @docker push $(IMAGE_NAME):latest + @(test "$(IMAGE_VERSION)" != "latest" && docker push $(IMAGE_NAME):$(IMAGE_VERSION)) || true + +help: ## Show this help + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' -- cgit v1.3