Add Makefile and remove obsolete build.sh/test.sh scripts
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
107
Makefile
Normal file
107
Makefile
Normal file
@ -0,0 +1,107 @@
|
||||
.PHONY: build build-docker test test-docker lint clean help docker-build-dev docker-build-runtime package package-rpm
|
||||
|
||||
# Docker parameters
|
||||
DOCKER=docker
|
||||
DOCKER_BUILD=$(DOCKER) build
|
||||
DOCKER_RUN=$(DOCKER) run
|
||||
|
||||
# Image names
|
||||
DEV_IMAGE=logcorrelator-dev:latest
|
||||
RUNTIME_IMAGE=logcorrelator:latest
|
||||
PACKAGER_IMAGE=logcorrelator-packager:latest
|
||||
|
||||
# Binary name
|
||||
BINARY_NAME=logcorrelator
|
||||
DIST_DIR=dist
|
||||
|
||||
# Package version
|
||||
PKG_VERSION ?= 1.0.3
|
||||
|
||||
## build: Build the logcorrelator binary locally
|
||||
build:
|
||||
mkdir -p $(DIST_DIR)
|
||||
go build -ldflags="-w -s" -o $(DIST_DIR)/$(BINARY_NAME) ./cmd/$(BINARY_NAME)
|
||||
|
||||
## docker-build-dev: Build the development Docker image
|
||||
docker-build-dev:
|
||||
$(DOCKER_BUILD) --target builder -t $(DEV_IMAGE) -f Dockerfile .
|
||||
|
||||
## docker-build-runtime: Build the runtime Docker image
|
||||
docker-build-runtime:
|
||||
$(DOCKER_BUILD) --target runtime -t $(RUNTIME_IMAGE) -f Dockerfile .
|
||||
|
||||
## test: Run unit tests locally
|
||||
test:
|
||||
go test -race -coverprofile=coverage.out ./...
|
||||
|
||||
## test-docker: Run unit tests inside Docker container
|
||||
test-docker: docker-build-dev
|
||||
@echo "Tests already run in builder stage"
|
||||
|
||||
## lint: Run linters
|
||||
lint:
|
||||
go vet ./...
|
||||
gofmt -l .
|
||||
|
||||
## fmt: Format all Go files
|
||||
fmt:
|
||||
gofmt -w .
|
||||
|
||||
## package: Build RPM packages for all target distributions
|
||||
package: package-rpm
|
||||
|
||||
## package-rpm: Build RPM packages for Rocky Linux 8/9, AlmaLinux 10 (requires Docker)
|
||||
package-rpm:
|
||||
mkdir -p $(DIST_DIR)/rpm/rocky8 $(DIST_DIR)/rpm/rocky9 $(DIST_DIR)/rpm/almalinux10
|
||||
$(DOCKER_BUILD) --target output -t $(PACKAGER_IMAGE) \
|
||||
--build-arg VERSION=$(PKG_VERSION) \
|
||||
-f Dockerfile.package .
|
||||
@echo "Extracting RPM packages from Docker image..."
|
||||
$(DOCKER_RUN) --rm -v $(PWD)/$(DIST_DIR):/output $(PACKAGER_IMAGE) sh -c \
|
||||
"cp -r /packages/rpm/rocky8 /output/rpm/ && \
|
||||
cp -r /packages/rpm/rocky9 /output/rpm/ && \
|
||||
cp -r /packages/rpm/almalinux10 /output/rpm/"
|
||||
@echo "RPM packages created:"
|
||||
@echo " Rocky Linux 8:"
|
||||
ls -la $(DIST_DIR)/rpm/rocky8/ 2>/dev/null || echo " (no packages)"
|
||||
@echo " Rocky Linux 9:"
|
||||
ls -la $(DIST_DIR)/rpm/rocky9/ 2>/dev/null || echo " (no packages)"
|
||||
@echo " AlmaLinux 10:"
|
||||
ls -la $(DIST_DIR)/rpm/almalinux10/ 2>/dev/null || echo " (no packages)"
|
||||
|
||||
## test-package-rpm: Test RPM package installation in Docker
|
||||
test-package-rpm: package-rpm
|
||||
./packaging/test/test-rpm.sh
|
||||
|
||||
## test-package: Test RPM package installation
|
||||
test-package: test-package-rpm
|
||||
|
||||
## ci: Full CI pipeline (tests, build, packages, package tests)
|
||||
ci: ci-test ci-build ci-package ci-package-test
|
||||
|
||||
## ci-test: Run all tests for CI
|
||||
ci-test: test lint
|
||||
|
||||
## ci-build: Build for CI (production binary)
|
||||
ci-build: build
|
||||
|
||||
## ci-package: Build all packages for CI
|
||||
ci-package: package
|
||||
|
||||
## ci-package-test: Test all packages for CI
|
||||
ci-package-test: test-package
|
||||
|
||||
## clean: Clean build artifacts and Docker images
|
||||
clean:
|
||||
rm -rf $(DIST_DIR)/
|
||||
rm -f coverage.out
|
||||
$(DOCKER) rmi $(DEV_IMAGE) 2>/dev/null || true
|
||||
$(DOCKER) rmi $(RUNTIME_IMAGE) 2>/dev/null || true
|
||||
$(DOCKER) rmi $(PACKAGER_IMAGE) 2>/dev/null || true
|
||||
|
||||
## help: Show this help message
|
||||
help:
|
||||
@echo "Usage: make [target]"
|
||||
@echo ""
|
||||
@echo "Targets:"
|
||||
@sed -n 's/^##//p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /'
|
||||
Reference in New Issue
Block a user