From f9faa1f1e24752e1bb392819540c9eb7a4d26803 Mon Sep 17 00:00:00 2001 From: Vito Castellano Date: Sat, 11 Oct 2025 01:57:41 +0200 Subject: [PATCH] refactor: migrate to Podman and enhance Makefile Replace Docker with Podman and upgrade Makefile with help system and new developer-friendly targets. --- .env | 8 +--- Makefile | 115 ++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 91 insertions(+), 32 deletions(-) diff --git a/.env b/.env index 41a28d3..c1956e0 100644 --- a/.env +++ b/.env @@ -1,10 +1,6 @@ APP_NAME=bbrew APP_VERSION=0.0.1-local - -### Docker -DOCKER_IMAGE_NAME=bbrew - -### Build -BUILD_GOVERSION=1.20 +CONTAINER_IMAGE_NAME=bbrew +BUILD_GOVERSION=1.25 BUILD_GOOS=darwin BUILD_GOARCH=arm64 \ No newline at end of file diff --git a/Makefile b/Makefile index d3d5941..321a932 100644 --- a/Makefile +++ b/Makefile @@ -1,63 +1,126 @@ ############################## # VARIABLES ############################## -ifneq (,$(wildcard ./.env)) - include .env - export -endif -%:@ +# Load .env if exists (loaded first so defaults can override if not set) +-include .env + +# Default values (can be overridden by .env or command line) +APP_NAME ?= bbrew +APP_VERSION ?= 0.0.1-local +CONTAINER_IMAGE_NAME ?= bbrew +BUILD_GOVERSION ?= 1.25 +BUILD_GOOS ?= $(shell go env GOOS) +BUILD_GOARCH ?= $(shell go env GOARCH) + +# Container runtime command +CONTAINER_RUN = podman run --rm -v $(PWD):/app $(CONTAINER_IMAGE_NAME) + +############################## +# HELP +############################## +.PHONY: help +help: ## Show this help message + @echo "Usage: make [target]" + @echo "" + @echo "Available targets:" + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort + +.DEFAULT_GOAL := help ############################## # CONTAINER ############################## .PHONY: container-build-image -container-build-image: - @podman build -f Containerfile -t $(DOCKER_IMAGE_NAME) . +container-build-image: ## Build container image + @podman build -f Containerfile -t $(CONTAINER_IMAGE_NAME) . -.PHONY: container-build-force-recreate -container-build-force-recreate: - @podman build --no-cache -f Containerfile -t $(DOCKER_IMAGE_NAME) . +.PHONY: container-build-force +container-build-force: ## Force rebuild container image (no cache) + @podman build --no-cache -f Containerfile -t $(CONTAINER_IMAGE_NAME) . + +.PHONY: container-clean +container-clean: ## Remove container image + @podman rmi $(CONTAINER_IMAGE_NAME) 2>/dev/null || true ############################## # RELEASE ############################## .PHONY: release-snapshot -release-snapshot: container-build-image # Builds the project in snapshot mode and releases it [This is used for testing releases] - @podman run --rm -v $(PWD):/app $(DOCKER_IMAGE_NAME) goreleaser release --snapshot --clean +release-snapshot: container-build-image ## Build and release snapshot (testing) + @$(CONTAINER_RUN) goreleaser release --snapshot --clean -.PHONY: build-snapshot # Builds the project in snapshot mode [This is used for testing releases] -build-snapshot: container-build-image - @podman run --rm -v $(PWD):/app $(DOCKER_IMAGE_NAME) goreleaser build --snapshot --clean +.PHONY: build-snapshot +build-snapshot: container-build-image ## Build snapshot without release + @$(CONTAINER_RUN) goreleaser build --snapshot --clean ############################## # BUILD ############################## .PHONY: build -build: container-build-image - @podman run --rm -v $(PWD):/app $(DOCKER_IMAGE_NAME) \ - env GOOS=$(BUILD_GOOS) GOARCH=$(BUILD_GOARCH) go build -o $(APP_NAME) ./cmd/$(APP_NAME) +build: container-build-image ## Build the application binary + @$(CONTAINER_RUN) env GOOS=$(BUILD_GOOS) GOARCH=$(BUILD_GOARCH) \ + go build -o $(APP_NAME) ./cmd/$(APP_NAME) + +.PHONY: build-local +build-local: ## Build locally without container (requires Go installed) + @go build -o $(APP_NAME) ./cmd/$(APP_NAME) .PHONY: run -run: build - ./$(APP_NAME) +run: build ## Build and run the application + @./$(APP_NAME) + +.PHONY: clean +clean: ## Clean build artifacts + @rm -f $(APP_NAME) + @rm -rf dist/ ############################## -# HELPER +# QUALITY ############################## .PHONY: quality -quality: container-build-image - @podman run --rm -v $(PWD):/app $(DOCKER_IMAGE_NAME) golangci-lint run +quality: container-build-image ## Run linter checks + @$(CONTAINER_RUN) golangci-lint run + +.PHONY: quality-local +quality-local: ## Run linter locally (requires golangci-lint installed) + @golangci-lint run + +.PHONY: test +test: ## Run tests + @go test -v ./... + +.PHONY: test-coverage +test-coverage: ## Run tests with coverage + @go test -v -coverprofile=coverage.out ./... + @go tool cover -html=coverage.out -o coverage.html ############################## # WEBSITE ############################## .PHONY: build-site -build-site: +build-site: ## Build the static website @node build.js .PHONY: serve-site -serve-site: +serve-site: ## Serve the website locally @npx http-server docs -p 3000 .PHONY: dev-site -dev-site: build-site serve-site \ No newline at end of file +dev-site: build-site serve-site ## Build and serve the website + +############################## +# UTILITY +############################## +.PHONY: install +install: build-local ## Install binary to $GOPATH/bin + @go install ./cmd/$(APP_NAME) + +.PHONY: deps +deps: ## Download and tidy dependencies + @go mod download + @go mod tidy + +.PHONY: deps-update +deps-update: ## Update all dependencies + @go get -u ./... + @go mod tidy