Refactor build and packaging scripts, add Helm Makefile, and configure actionlint matcher

Removes legacy type schema generation Makefile and updates pre-commit hook to use new Makefile command.

Introduces a comprehensive Makefile to manage Helm chart packaging, publishing, testing, linting, and Docker image workflows, streamlining Apolo project automation and aligning with upstream LightRAG packaging conventions.

Adds GitHub Action problem matcher configuration for actionlint to improve workflow diagnostics.

Enhances maintainability and developer experience by centralizing build and deployment processes.

Relates to MLO-469
This commit is contained in:
Taddeus 2025-11-03 14:58:11 +02:00
parent 64b1ec9b3d
commit aeefc06905
4 changed files with 112 additions and 62 deletions

View file

@ -1,14 +0,0 @@
.PHONY: all clean test gen-types-schemas
all: gen-types-schemas
gen-types-schemas:
@.apolo/scripts/gen_types_schemas.sh
clean:
@rm -f .apolo/src/apolo_apps_lightrag/schemas/LightRAGAppInputs.json
@rm -f .apolo/src/apolo_apps_lightrag/schemas/LightRAGAppOutputs.json
@rm -f .apolo/src/apolo_apps_lightrag/types.py
test:
@echo "No tests defined for schema generation."

27
.github/actionlint-matcher.json vendored Normal file
View file

@ -0,0 +1,27 @@
{
"problemMatcher": [
{
"owner": "actionlint",
"pattern": [
{
"regexp": "^::(?:(?:warning)|(?:error)) file=(.+),line=(\\d+),col=(\\d+)::(.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
]
},
{
"owner": "actionlint",
"pattern": [
{
"regexp": "^::(?:(?:warning)|(?:error)) file=(.+),line=(\\d+)::(.*)$",
"file": 1,
"line": 2,
"message": 3
}
]
}
]
}

View file

@ -44,5 +44,5 @@ repos:
hooks: hooks:
- id: generate-types-schemas - id: generate-types-schemas
name: Generate types schemas name: Generate types schemas
entry: make -f .apolo/scripts/gen_types_schemas.mk gen-types-schemas entry: make gen-types-schemas
language: system language: system

131
Makefile
View file

@ -1,61 +1,97 @@
# Makefile for LightRAG Helm packaging # Makefile for LightRAG Helm packaging
# Configuration # ------------------------------------------------------------------------------
# Core chart configuration (mirrors upstream LightRAG project)
# ------------------------------------------------------------------------------
CHART_NAME := lightrag-minimal CHART_NAME := lightrag-minimal
CHART_DIR := k8s-deploy/$(CHART_NAME) CHART_DIR := k8s-deploy/$(CHART_NAME)
CHART_PACKAGE_DIR := dist/charts CHART_PACKAGE_DIR := dist/charts
HELM_REGISTRY := ghcr.io/neuro-inc/helm-charts HELM_REGISTRY := ghcr.io/neuro-inc/helm-charts
RAW_VERSION := $(if $(VERSION),$(VERSION),$(shell git describe --tags --always --dirty 2>/dev/null)) RAW_VERSION := $(if $(VERSION),$(VERSION),$(shell git describe --tags --always --dirty 2>/dev/null))
SANITIZED_VERSION := $(shell python -c 'import re; raw = "$(RAW_VERSION)".strip(); raw = raw[1:] if raw.startswith("v") else raw; raw = raw or "0.0.0"; sanitized = re.sub(r"[^0-9A-Za-z.\-]", "-", raw); print(sanitized or "0.0.0")') SANITIZED_VERSION := $(shell python -c 'import re; raw = "$(RAW_VERSION)".strip(); raw = raw[1:] if raw.startswith("v") else raw; raw = raw or "0.0.0"; print(re.sub(r"[^0-9A-Za-z.\-]", "-", raw) or "0.0.0")')
CHART_VERSION := $(SANITIZED_VERSION) CHART_VERSION := $(SANITIZED_VERSION)
CHART_PACKAGE := $(CHART_PACKAGE_DIR)/$(CHART_NAME)-$(CHART_VERSION).tgz CHART_PACKAGE := $(CHART_PACKAGE_DIR)/$(CHART_NAME)-$(CHART_VERSION).tgz
GITHUB_USERNAME := $(shell echo "$$APOLO_GITHUB_TOKEN" | base64 -d 2>/dev/null | cut -d: -f1 2>/dev/null || echo "oauth2") GITHUB_USERNAME := $(shell echo "$$APOLO_GITHUB_TOKEN" | base64 -d 2>/dev/null | cut -d: -f1 2>/dev/null || echo "oauth2")
HOOKS_IMAGE_REPO ?= ghcr.io/neuro-inc/app-lightrag # ------------------------------------------------------------------------------
BUILD_IMAGE_TAG ?= $(CHART_VERSION) # Apolo tooling configuration
IMAGE_TAG ?= $(BUILD_IMAGE_TAG) # ------------------------------------------------------------------------------
HOOKS_BUILD_IMAGE := $(HOOKS_IMAGE_REPO):$(BUILD_IMAGE_TAG)
HOOKS_PUBLISH_IMAGE := $(HOOKS_IMAGE_REPO):$(IMAGE_TAG)
POETRY ?= poetry POETRY ?= poetry
POETRY_RUN := $(POETRY) run IMAGE_NAME ?= app-lightrag
PYTEST_TARGET ?= .apolo/tests IMAGE_TAG ?= latest
define HELP_MESSAGE APP_CHART_NAME := lightrag
APP_CHART_DIR := k8s-deploy/$(APP_CHART_NAME)
APP_CHART_PACKAGE := $(CHART_PACKAGE_DIR)/$(APP_CHART_NAME)-$(CHART_VERSION).tgz
define HELP_TEXT
Available targets: Available targets:
install - Install project dependencies (including dev extras) install - Install Poetry environment and pre-commit hooks
setup - Alias for install (compatibility) lint - Run pre-commit across the repository
lint - Run pre-commit checks across the repository test-unit - Execute unit tests for Apolo integrations
test-unit - Execute unit test suite with pytest gen-types-schemas - Regenerate LightRAG JSON schemas
helm-package - Package the LightRAG Helm chart (version: $(CHART_VERSION)) helm-package - Package the LightRAG Helm chart (version: $(CHART_VERSION))
helm-push - Package and push the chart to $(HELM_REGISTRY) helm-push - Package and push the minimal chart to $(HELM_REGISTRY)
helm-package-app - Package the full LightRAG app chart
helm-push-app - Package and push the full app chart
build-hook-image - Build the hooks helper image
push-hook-image - Push the hooks helper image
clean - Remove packaged charts from $(CHART_PACKAGE_DIR) clean - Remove packaged charts from $(CHART_PACKAGE_DIR)
hooks-build - Build the pre-commit hooks image $(HOOKS_BUILD_IMAGE)
hooks-publish - Build and push the hooks image to its registry
Set VERSION=1.2.3 to override the git-derived chart version. Set VERSION=1.2.3 to override the git-derived chart version.
endef endef
export HELP_MESSAGE export HELP_TEXT
.PHONY: all help install setup lint test-unit helm-package helm-push clean test hooks-build hooks-publish build-hook-image push-hook-image # ------------------------------------------------------------------------------
# Phony targets
# ------------------------------------------------------------------------------
.PHONY: all help test clean
.PHONY: install setup lint format test-unit gen-types-schemas
.PHONY: build-hook-image push-hook-image helm-package helm-push helm-package-app helm-push-app
# ------------------------------------------------------------------------------
# User-facing helpers
# ------------------------------------------------------------------------------
all: help all: help
help: help:
@printf "%s\n" "$$HELP_MESSAGE" @printf '%s\n' "$$HELP_TEXT"
install: install setup:
$(POETRY) config virtualenvs.in-project true
$(POETRY) install --with dev $(POETRY) install --with dev
$(POETRY) run pre-commit install
setup: install lint format:
ifdef CI
lint: $(POETRY) run pre-commit run --all-files --show-diff-on-failure
$(POETRY_RUN) pre-commit run --all-files --show-diff-on-failure else
$(POETRY) run pre-commit run --all-files || $(POETRY) run pre-commit run --all-files
endif
test-unit: test-unit:
$(POETRY_RUN) pytest $(PYTEST_TARGET) $(POETRY) run pytest -vvs --cov=.apolo --cov-report xml:.coverage.unit.xml .apolo/tests/unit
test: test-unit
gen-types-schemas:
@.apolo/scripts/gen_types_schemas.sh
build-hook-image:
docker build \
-t $(IMAGE_NAME):latest \
-f hooks.Dockerfile \
.
push-hook-image: build-hook-image
docker tag $(IMAGE_NAME):latest ghcr.io/neuro-inc/$(IMAGE_NAME):$(IMAGE_TAG)
docker push ghcr.io/neuro-inc/$(IMAGE_NAME):$(IMAGE_TAG)
# ------------------------------------------------------------------------------
# Upstream Helm packaging targets (kept minimal to ease syncing with source)
# ------------------------------------------------------------------------------
helm-package: helm-package:
@if [ -z "$(CHART_VERSION)" ]; then \ @if [ -z "$(CHART_VERSION)" ]; then \
echo "Error: unable to determine chart version."; \ echo "Error: unable to determine chart version."; \
@ -86,26 +122,27 @@ clean:
rm -rf $(CHART_PACKAGE_DIR) rm -rf $(CHART_PACKAGE_DIR)
@echo "✅ Cleaned" @echo "✅ Cleaned"
test: helm-package-app:
@echo "No automated tests for Helm packaging. Use 'helm test' as needed." @if [ -z "$(CHART_VERSION)" ]; then \
echo "Error: unable to determine chart version."; \
hooks-build: exit 1; \
@echo "Building hooks image $(HOOKS_BUILD_IMAGE)..."
docker build \
--file hooks.Dockerfile \
--tag $(HOOKS_BUILD_IMAGE) \
.
@echo "✅ Hooks image built: $(HOOKS_BUILD_IMAGE)"
hooks-publish: hooks-build
@echo "Tagging hooks image as $(HOOKS_PUBLISH_IMAGE)..."
@if [ "$(HOOKS_PUBLISH_IMAGE)" != "$(HOOKS_BUILD_IMAGE)" ]; then \
docker tag $(HOOKS_BUILD_IMAGE) $(HOOKS_PUBLISH_IMAGE); \
fi fi
@echo "Pushing hooks image $(HOOKS_PUBLISH_IMAGE)..." @echo "Packaging $(APP_CHART_NAME) chart version $(CHART_VERSION)..."
docker push $(HOOKS_PUBLISH_IMAGE) @mkdir -p $(CHART_PACKAGE_DIR)
@echo "✅ Hooks image pushed to $(HOOKS_PUBLISH_IMAGE)" helm dependency update $(APP_CHART_DIR) >/dev/null
helm package $(APP_CHART_DIR) \
--version $(CHART_VERSION) \
--app-version $(CHART_VERSION) \
-d $(CHART_PACKAGE_DIR)
@echo "✅ Chart packaged at $(APP_CHART_PACKAGE)"
build-hook-image: hooks-build helm-push-app: helm-package-app
@if [ -z "$(APOLO_GITHUB_TOKEN)" ]; then \
push-hook-image: hooks-publish echo "Error: APOLO_GITHUB_TOKEN not set. Please export a token with write:packages."; \
exit 1; \
fi
@echo "Logging into Helm registry ghcr.io as $(GITHUB_USERNAME)..."
echo "$(APOLO_GITHUB_TOKEN)" | helm registry login ghcr.io -u $(GITHUB_USERNAME) --password-stdin >/dev/null
@echo "Pushing chart $(APP_CHART_NAME):$(CHART_VERSION) to $(HELM_REGISTRY)..."
helm push $(APP_CHART_PACKAGE) oci://$(HELM_REGISTRY)
@echo "✅ Chart pushed to $(HELM_REGISTRY)"