diff --git a/.config/make/build-docker-buildx-dev.mak b/.config/make/build-docker-buildx-dev.mak new file mode 100644 index 00000000..24bc271b --- /dev/null +++ b/.config/make/build-docker-buildx-dev.mak @@ -0,0 +1,64 @@ +## โ€”โ€” Development/Source builds using direct buildx commands --------------------------------------- + +.PHONY: docker-dev +docker-dev: ## Build dev multi-arch image (cannot load locally) + @echo "๐Ÿ—๏ธ Building multi-architecture development Docker images with buildx..." + @echo "๐Ÿ’ก This builds from source code and is intended for local development and testing" + @echo "โš ๏ธ Multi-arch images cannot be loaded locally, use docker-dev-push to push to registry" + $(DOCKER_CLI) buildx build \ + --platform linux/amd64,linux/arm64 \ + --file $(DOCKERFILE_SOURCE) \ + --tag rustfs:source-latest \ + --tag rustfs:dev-latest \ + . + +.PHONY: docker-dev-local +docker-dev-local: ## Build dev single-arch image (local load) + @echo "๐Ÿ—๏ธ Building single-architecture development Docker image for local use..." + @echo "๐Ÿ’ก This builds from source code for the current platform and loads locally" + $(DOCKER_CLI) buildx build \ + --file $(DOCKERFILE_SOURCE) \ + --tag rustfs:source-latest \ + --tag rustfs:dev-latest \ + --load \ + . + +.PHONY: docker-dev-push +docker-dev-push: ## Build and push multi-arch development image # e.g (make docker-dev-push REGISTRY=xxx) + @if [ -z "$(REGISTRY)" ]; then \ + echo "โŒ Error: Please specify registry, example: make docker-dev-push REGISTRY=ghcr.io/username"; \ + exit 1; \ + fi + @echo "๐Ÿš€ Building and pushing multi-architecture development Docker images..." + @echo "๐Ÿ’ก Pushing to registry: $(REGISTRY)" + $(DOCKER_CLI) buildx build \ + --platform linux/amd64,linux/arm64 \ + --file $(DOCKERFILE_SOURCE) \ + --tag $(REGISTRY)/rustfs:source-latest \ + --tag $(REGISTRY)/rustfs:dev-latest \ + --push \ + . + +.PHONY: dev-env-start +dev-env-start: ## Start development container environment + @echo "๐Ÿš€ Starting development environment..." + $(DOCKER_CLI) buildx build \ + --file $(DOCKERFILE_SOURCE) \ + --tag rustfs:dev \ + --load \ + . + $(DOCKER_CLI) stop $(CONTAINER_NAME) 2>/dev/null || true + $(DOCKER_CLI) rm $(CONTAINER_NAME) 2>/dev/null || true + $(DOCKER_CLI) run -d --name $(CONTAINER_NAME) \ + -p 9010:9010 -p 9000:9000 \ + -v $(shell pwd):/workspace \ + -it rustfs:dev + +.PHONY: dev-env-stop +dev-env-stop: ## Stop development container environment + @echo "๐Ÿ›‘ Stopping development environment..." + $(DOCKER_CLI) stop $(CONTAINER_NAME) 2>/dev/null || true + $(DOCKER_CLI) rm $(CONTAINER_NAME) 2>/dev/null || true + +.PHONY: dev-env-restart +dev-env-restart: dev-env-stop dev-env-start ## Restart development container environment diff --git a/.config/make/build-docker-buildx-production.mak b/.config/make/build-docker-buildx-production.mak new file mode 100644 index 00000000..693f2bec --- /dev/null +++ b/.config/make/build-docker-buildx-production.mak @@ -0,0 +1,41 @@ +## โ€”โ€” Production builds using docker buildx (for CI/CD and production) ----------------------------- + +.PHONY: docker-buildx +docker-buildx: ## Build production multi-arch image (no push) + @echo "๐Ÿ—๏ธ Building multi-architecture production Docker images with buildx..." + ./docker-buildx.sh + +.PHONY: docker-buildx-push +docker-buildx-push: ## Build and push production multi-arch image + @echo "๐Ÿš€ Building and pushing multi-architecture production Docker images with buildx..." + ./docker-buildx.sh --push + +.PHONY: docker-buildx-version +docker-buildx-version: ## Build and version production multi-arch image # e.g (make docker-buildx-version VERSION=v1.0.0) + @if [ -z "$(VERSION)" ]; then \ + echo "โŒ Error: Please specify version, example: make docker-buildx-version VERSION=v1.0.0"; \ + exit 1; \ + fi + @echo "๐Ÿ—๏ธ Building multi-architecture production Docker images (version: $(VERSION))..." + ./docker-buildx.sh --release $(VERSION) + +.PHONY: docker-buildx-push-version +docker-buildx-push-version: ## Build and version and push production multi-arch image # e.g (make docker-buildx-push-version VERSION=v1.0.0) + @if [ -z "$(VERSION)" ]; then \ + echo "โŒ Error: Please specify version, example: make docker-buildx-push-version VERSION=v1.0.0"; \ + exit 1; \ + fi + @echo "๐Ÿš€ Building and pushing multi-architecture production Docker images (version: $(VERSION))..." + ./docker-buildx.sh --release $(VERSION) --push + +.PHONY: docker-buildx-production-local +docker-buildx-production-local: ## Build production single-arch image locally + @echo "๐Ÿ—๏ธ Building single-architecture production Docker image locally..." + @echo "๐Ÿ’ก Alternative to docker-buildx.sh for local testing" + $(DOCKER_CLI) buildx build \ + --file $(DOCKERFILE_PRODUCTION) \ + --tag rustfs:production-latest \ + --tag rustfs:latest \ + --load \ + --build-arg RELEASE=latest \ + . diff --git a/.config/make/build-docker-production.mak b/.config/make/build-docker-production.mak new file mode 100644 index 00000000..d9c249c8 --- /dev/null +++ b/.config/make/build-docker-production.mak @@ -0,0 +1,16 @@ +## โ€”โ€” Single Architecture Docker Builds (Traditional) ---------------------------------------------- + +.PHONY: docker-build-production +docker-build-production: ## Build single-arch production image + @echo "๐Ÿ—๏ธ Building single-architecture production Docker image..." + @echo "๐Ÿ’ก Consider using 'make docker-buildx-production-local' for multi-arch support" + $(DOCKER_CLI) build -f $(DOCKERFILE_PRODUCTION) -t rustfs:latest . + +.PHONY: docker-build-source +docker-build-source: ## Build single-arch source image + @echo "๐Ÿ—๏ธ Building single-architecture source Docker image..." + @echo "๐Ÿ’ก Consider using 'make docker-dev-local' for multi-arch support" + DOCKER_BUILDKIT=1 $(DOCKER_CLI) build \ + --build-arg BUILDKIT_INLINE_CACHE=1 \ + -f $(DOCKERFILE_SOURCE) -t rustfs:source . + diff --git a/.config/make/build-docker.mak b/.config/make/build-docker.mak new file mode 100644 index 00000000..36dd2bef --- /dev/null +++ b/.config/make/build-docker.mak @@ -0,0 +1,22 @@ +## โ€”โ€” Docker-based build (alternative approach) ---------------------------------------------------- + +# Usage: make BUILD_OS=ubuntu22.04 build-docker +# Output: target/ubuntu22.04/release/rustfs + +.PHONY: build-docker +build-docker: SOURCE_BUILD_IMAGE_NAME = rustfs-$(BUILD_OS):v1 +build-docker: SOURCE_BUILD_CONTAINER_NAME = rustfs-$(BUILD_OS)-build +build-docker: BUILD_CMD = /root/.cargo/bin/cargo build --release --bin rustfs --target-dir /root/s3-rustfs/target/$(BUILD_OS) +build-docker: ## Build using Docker container # e.g (make build-docker BUILD_OS=ubuntu22.04) + @echo "๐Ÿณ Building RustFS using Docker ($(BUILD_OS))..." + $(DOCKER_CLI) buildx build -t $(SOURCE_BUILD_IMAGE_NAME) -f $(DOCKERFILE_SOURCE) . + $(DOCKER_CLI) run --rm --name $(SOURCE_BUILD_CONTAINER_NAME) -v $(shell pwd):/root/s3-rustfs -it $(SOURCE_BUILD_IMAGE_NAME) $(BUILD_CMD) + +.PHONY: docker-inspect-multiarch +docker-inspect-multiarch: ## Check image architecture support + @if [ -z "$(IMAGE)" ]; then \ + echo "โŒ Error: Please specify image, example: make docker-inspect-multiarch IMAGE=rustfs/rustfs:latest"; \ + exit 1; \ + fi + @echo "๐Ÿ” Inspecting multi-architecture image: $(IMAGE)" + docker buildx imagetools inspect $(IMAGE) \ No newline at end of file diff --git a/.config/make/build.mak b/.config/make/build.mak new file mode 100644 index 00000000..a3801614 --- /dev/null +++ b/.config/make/build.mak @@ -0,0 +1,55 @@ +## โ€”โ€” Local Native Build using build-rustfs.sh script (Recommended) -------------------------------- + +.PHONY: build +build: ## Build RustFS binary (includes console by default) + @echo "๐Ÿ”จ Building RustFS using build-rustfs.sh script..." + ./build-rustfs.sh + +.PHONY: build-dev +build-dev: ## Build RustFS in Development mode + @echo "๐Ÿ”จ Building RustFS in development mode..." + ./build-rustfs.sh --dev + +.PHONY: build-musl +build-musl: ## Build x86_64 musl version + @echo "๐Ÿ”จ Building rustfs for x86_64-unknown-linux-musl..." + @echo "๐Ÿ’ก On macOS/Windows, use 'make build-docker' or 'make docker-dev' instead" + ./build-rustfs.sh --platform x86_64-unknown-linux-musl + +.PHONY: build-gnu +build-gnu: ## Build x86_64 GNU version + @echo "๐Ÿ”จ Building rustfs for x86_64-unknown-linux-gnu..." + @echo "๐Ÿ’ก On macOS/Windows, use 'make build-docker' or 'make docker-dev' instead" + ./build-rustfs.sh --platform x86_64-unknown-linux-gnu + +.PHONY: build-musl-arm64 +build-musl-arm64: ## Build aarch64 musl version + @echo "๐Ÿ”จ Building rustfs for aarch64-unknown-linux-musl..." + @echo "๐Ÿ’ก On macOS/Windows, use 'make build-docker' or 'make docker-dev' instead" + ./build-rustfs.sh --platform aarch64-unknown-linux-musl + +.PHONY: build-gnu-arm64 +build-gnu-arm64: ## Build aarch64 GNU version + @echo "๐Ÿ”จ Building rustfs for aarch64-unknown-linux-gnu..." + @echo "๐Ÿ’ก On macOS/Windows, use 'make build-docker' or 'make docker-dev' instead" + ./build-rustfs.sh --platform aarch64-unknown-linux-gnu + + +.PHONY: build-cross-all +build-cross-all: core-deps ## Build binaries for all architectures + @echo "๐Ÿ”ง Building all target architectures..." + @echo "๐Ÿ’ก On macOS/Windows, use 'make docker-dev' for reliable multi-arch builds" + @echo "๐Ÿ”จ Generating protobuf code..." + cargo run --bin gproto || true + + @echo "๐Ÿ”จ Building rustfs for x86_64-unknown-linux-musl..." + ./build-rustfs.sh --platform x86_64-unknown-linux-musl + + @echo "๐Ÿ”จ Building rustfs for x86_64-unknown-linux-gnu..." + ./build-rustfs.sh --platform x86_64-unknown-linux-gnu + + @echo "๐Ÿ”จ Building rustfs for aarch64-unknown-linux-musl..." + ./build-rustfs.sh --platform aarch64-unknown-linux-musl + + @echo "๐Ÿ”จ Building rustfs for aarch64-unknown-linux-gnu..." + ./build-rustfs.sh --platform aarch64-unknown-linux-gnu diff --git a/.config/make/check.mak b/.config/make/check.mak new file mode 100644 index 00000000..d0bbd392 --- /dev/null +++ b/.config/make/check.mak @@ -0,0 +1,24 @@ +## โ€”โ€” Check and Inform Dependencies ---------------------------------------------------------------- + +# Fatal check +# Checks all required dependencies and exits with error if not found +# (e.g., cargo, rustfmt) +check-%: + @command -v $* >/dev/null 2>&1 || { \ + echo >&2 "โŒ '$*' is not installed."; \ + exit 1; \ + } + +# Warning-only check +# Checks for optional dependencies and issues a warning if not found +# (e.g., cargo-nextest for enhanced testing) +warn-%: + @command -v $* >/dev/null 2>&1 || { \ + echo >&2 "โš ๏ธ '$*' is not installed."; \ + } + +# For checking dependencies use check- or warn- +.PHONY: core-deps fmt-deps test-deps +core-deps: check-cargo ## Check core dependencies +fmt-deps: check-rustfmt ## Check lint and formatting dependencies +test-deps: warn-cargo-nextest ## Check tests dependencies diff --git a/.config/make/deploy.mak b/.config/make/deploy.mak new file mode 100644 index 00000000..2c475652 --- /dev/null +++ b/.config/make/deploy.mak @@ -0,0 +1,6 @@ +## โ€”โ€” Deploy using dev_deploy.sh script ------------------------------------------------------------ + +.PHONY: deploy-dev +deploy-dev: build-musl ## Deploy to dev server + @echo "๐Ÿš€ Deploying to dev server: $${IP}" + ./scripts/dev_deploy.sh $${IP} \ No newline at end of file diff --git a/.config/make/help.mak b/.config/make/help.mak new file mode 100644 index 00000000..044bf1b8 --- /dev/null +++ b/.config/make/help.mak @@ -0,0 +1,38 @@ +## โ€”โ€” Help, Help Build and Help Docker ------------------------------------------------------------- + + +.PHONY: help +help: ## Shows This Help Menu + echo -e "$$HEADER" + grep -E '(^[a-zA-Z0-9_-]+:.*?## .*$$)|(^## )' $(MAKEFILE_LIST) | sed 's/^[^:]*://g' | awk 'BEGIN {FS = ":.*?## | #"} ; {printf "${cyan}%-30s${reset} ${white}%s${reset} ${green}%s${reset}\n", $$1, $$2, $$3}' | sed -e 's/\[36m##/\n[32m##/' + +.PHONY: help-build +help-build: ## Shows RustFS build help + @echo "" + @echo "๐Ÿ’ก build-rustfs.sh script provides more options, smart detection and binary verification" + @echo "" + @echo "๐Ÿ”ง Direct usage of build-rustfs.sh script:" + @echo "" + @echo " ./build-rustfs.sh --help # View script help" + @echo " ./build-rustfs.sh --no-console # Build without console resources" + @echo " ./build-rustfs.sh --force-console-update # Force update console resources" + @echo " ./build-rustfs.sh --dev # Development mode build" + @echo " ./build-rustfs.sh --sign # Sign binary files" + @echo " ./build-rustfs.sh --platform x86_64-unknown-linux-gnu # Specify target platform" + @echo " ./build-rustfs.sh --skip-verification # Skip binary verification" + @echo "" + +.PHONY: help-docker +help-docker: ## Shows docker environment and suggestion help + @echo "" + @echo "๐Ÿ“‹ Environment Variables:" + @echo " REGISTRY Image registry address (required for push)" + @echo " DOCKERHUB_USERNAME Docker Hub username" + @echo " DOCKERHUB_TOKEN Docker Hub access token" + @echo " GITHUB_TOKEN GitHub access token" + @echo "" + @echo "๐Ÿ’ก Suggestions:" + @echo " Production use: Use docker-buildx* commands (based on precompiled binaries)" + @echo " Local development: Use docker-dev* commands (build from source)" + @echo " Development environment: Use dev-env-* commands to manage dev containers" + @echo "" diff --git a/.config/make/lint-fmt.mak b/.config/make/lint-fmt.mak new file mode 100644 index 00000000..88742c97 --- /dev/null +++ b/.config/make/lint-fmt.mak @@ -0,0 +1,22 @@ +## โ€”โ€” Code quality and Formatting ------------------------------------------------------------------ + +.PHONY: fmt +fmt: core-deps fmt-deps ## Format code + @echo "๐Ÿ”ง Formatting code..." + cargo fmt --all + +.PHONY: fmt-check +fmt-check: core-deps fmt-deps ## Check code formatting + @echo "๐Ÿ“ Checking code formatting..." + cargo fmt --all --check + +.PHONY: clippy-check +clippy-check: core-deps ## Run clippy checks + @echo "๐Ÿ” Running clippy checks..." + cargo clippy --fix --allow-dirty + cargo clippy --all-targets --all-features -- -D warnings + +.PHONY: compilation-check +compilation-check: core-deps ## Run compilation check + @echo "๐Ÿ”จ Running compilation check..." + cargo check --all-targets diff --git a/.config/make/pre-commit.mak b/.config/make/pre-commit.mak new file mode 100644 index 00000000..43b2126e --- /dev/null +++ b/.config/make/pre-commit.mak @@ -0,0 +1,11 @@ +## โ€”โ€” Pre Commit Checks ---------------------------------------------------------------------------- + +.PHONY: setup-hooks +setup-hooks: ## Set up git hooks + @echo "๐Ÿ”ง Setting up git hooks..." + chmod +x .git/hooks/pre-commit + @echo "โœ… Git hooks setup complete!" + +.PHONY: pre-commit +pre-commit: fmt clippy-check compilation-check test ## Run pre-commit checks + @echo "โœ… All pre-commit checks passed!" \ No newline at end of file diff --git a/.config/make/tests.mak b/.config/make/tests.mak new file mode 100644 index 00000000..ae434376 --- /dev/null +++ b/.config/make/tests.mak @@ -0,0 +1,20 @@ +## โ€”โ€” Tests and e2e test --------------------------------------------------------------------------- + +.PHONY: test +test: core-deps test-deps ## Run all tests + @echo "๐Ÿงช Running tests..." + @if command -v cargo-nextest >/dev/null 2>&1; then \ + cargo nextest run --all --exclude e2e_test; \ + else \ + echo "โ„น๏ธ cargo-nextest not found; falling back to 'cargo test'"; \ + cargo test --workspace --exclude e2e_test -- --nocapture; \ + fi + cargo test --all --doc + +.PHONY: e2e-server +e2e-server: ## Run e2e-server tests + sh $(shell pwd)/scripts/run.sh + +.PHONY: probe-e2e +probe-e2e: ## Probe e2e tests + sh $(shell pwd)/scripts/probe.sh \ No newline at end of file diff --git a/Makefile b/Makefile index 40ac1738..ce2793d3 100644 --- a/Makefile +++ b/Makefile @@ -2,394 +2,80 @@ # Remote development requires VSCode with Dev Containers, Remote SSH, Remote Explorer # https://code.visualstudio.com/docs/remote/containers ########### + +.PHONY: SHELL + +# Makefile global config +# Use config.mak to override any of the following variables. +# Do not make changes here. + +.DEFAULT_GOAL := help +.EXPORT_ALL_VARIABLES: +.ONESHELL: +.SILENT: + +NUM_CORES := $(shell nproc 2>/dev/null || sysctl -n hw.ncpu) + +MAKEFLAGS += -j$(NUM_CORES) -l$(NUM_CORES) +MAKEFLAGS += --silent + +SHELL:= /bin/bash +.SHELLFLAGS = -eu -o pipefail -c + DOCKER_CLI ?= docker IMAGE_NAME ?= rustfs:v1.0.0 CONTAINER_NAME ?= rustfs-dev # Docker build configurations DOCKERFILE_PRODUCTION = Dockerfile DOCKERFILE_SOURCE = Dockerfile.source - -# Fatal check -# Checks all required dependencies and exits with error if not found -# (e.g., cargo, rustfmt) -check-%: - @command -v $* >/dev/null 2>&1 || { \ - echo >&2 "โŒ '$*' is not installed."; \ - exit 1; \ - } - -# Warning-only check -# Checks for optional dependencies and issues a warning if not found -# (e.g., cargo-nextest for enhanced testing) -warn-%: - @command -v $* >/dev/null 2>&1 || { \ - echo >&2 "โš ๏ธ '$*' is not installed."; \ - } - -# For checking dependencies use check- or warn- -.PHONY: core-deps fmt-deps test-deps -core-deps: check-cargo -fmt-deps: check-rustfmt -test-deps: warn-cargo-nextest - -# Code quality and formatting targets -.PHONY: fmt -fmt: core-deps fmt-deps - @echo "๐Ÿ”ง Formatting code..." - cargo fmt --all - -.PHONY: fmt-check -fmt-check: core-deps fmt-deps - @echo "๐Ÿ“ Checking code formatting..." - cargo fmt --all --check - -.PHONY: clippy -clippy: core-deps - @echo "๐Ÿ” Running clippy checks..." - cargo clippy --fix --allow-dirty - cargo clippy --all-targets --all-features -- -D warnings - -.PHONY: check -check: core-deps - @echo "๐Ÿ”จ Running compilation check..." - cargo check --all-targets - -.PHONY: test -test: core-deps test-deps - @echo "๐Ÿงช Running tests..." - @if command -v cargo-nextest >/dev/null 2>&1; then \ - cargo nextest run --all --exclude e2e_test; \ - else \ - echo "โ„น๏ธ cargo-nextest not found; falling back to 'cargo test'"; \ - cargo test --workspace --exclude e2e_test -- --nocapture; \ - fi - cargo test --all --doc - -.PHONY: setup-hooks -setup-hooks: - @echo "๐Ÿ”ง Setting up git hooks..." - chmod +x .git/hooks/pre-commit - @echo "โœ… Git hooks setup complete!" - -.PHONY: pre-commit -pre-commit: fmt clippy check test - @echo "โœ… All pre-commit checks passed!" - -.PHONY: e2e-server -e2e-server: - sh $(shell pwd)/scripts/run.sh - -.PHONY: probe-e2e -probe-e2e: - sh $(shell pwd)/scripts/probe.sh - -# Native build using build-rustfs.sh script -.PHONY: build -build: - @echo "๐Ÿ”จ Building RustFS using build-rustfs.sh script..." - ./build-rustfs.sh - -.PHONY: build-dev -build-dev: - @echo "๐Ÿ”จ Building RustFS in development mode..." - ./build-rustfs.sh --dev - -# Docker-based build (alternative approach) -# Usage: make BUILD_OS=ubuntu22.04 build-docker -# Output: target/ubuntu22.04/release/rustfs BUILD_OS ?= rockylinux9.3 -.PHONY: build-docker -build-docker: SOURCE_BUILD_IMAGE_NAME = rustfs-$(BUILD_OS):v1 -build-docker: SOURCE_BUILD_CONTAINER_NAME = rustfs-$(BUILD_OS)-build -build-docker: BUILD_CMD = /root/.cargo/bin/cargo build --release --bin rustfs --target-dir /root/s3-rustfs/target/$(BUILD_OS) -build-docker: - @echo "๐Ÿณ Building RustFS using Docker ($(BUILD_OS))..." - $(DOCKER_CLI) buildx build -t $(SOURCE_BUILD_IMAGE_NAME) -f $(DOCKERFILE_SOURCE) . - $(DOCKER_CLI) run --rm --name $(SOURCE_BUILD_CONTAINER_NAME) -v $(shell pwd):/root/s3-rustfs -it $(SOURCE_BUILD_IMAGE_NAME) $(BUILD_CMD) -.PHONY: build-musl -build-musl: - @echo "๐Ÿ”จ Building rustfs for x86_64-unknown-linux-musl..." - @echo "๐Ÿ’ก On macOS/Windows, use 'make build-docker' or 'make docker-dev' instead" - ./build-rustfs.sh --platform x86_64-unknown-linux-musl +# Makefile colors config +bold := $(shell tput bold) +normal := $(shell tput sgr0) +errorTitle := $(shell tput setab 1 && tput bold && echo '\n') +recommendation := $(shell tput setab 4) +underline := $(shell tput smul) +reset := $(shell tput -Txterm sgr0) +black := $(shell tput setaf 0) +red := $(shell tput setaf 1) +green := $(shell tput setaf 2) +yellow := $(shell tput setaf 3) +blue := $(shell tput setaf 4) +magenta := $(shell tput setaf 5) +cyan := $(shell tput setaf 6) +white := $(shell tput setaf 7) -.PHONY: build-gnu -build-gnu: - @echo "๐Ÿ”จ Building rustfs for x86_64-unknown-linux-gnu..." - @echo "๐Ÿ’ก On macOS/Windows, use 'make build-docker' or 'make docker-dev' instead" - ./build-rustfs.sh --platform x86_64-unknown-linux-gnu +define HEADER +How to use me: + # To get help for each target + ${bold}make help${reset} -.PHONY: build-musl-arm64 -build-musl-arm64: - @echo "๐Ÿ”จ Building rustfs for aarch64-unknown-linux-musl..." - @echo "๐Ÿ’ก On macOS/Windows, use 'make build-docker' or 'make docker-dev' instead" - ./build-rustfs.sh --platform aarch64-unknown-linux-musl + # To run and execute a target + ${bold}make ${cyan}${reset} -.PHONY: build-gnu-arm64 -build-gnu-arm64: - @echo "๐Ÿ”จ Building rustfs for aarch64-unknown-linux-gnu..." - @echo "๐Ÿ’ก On macOS/Windows, use 'make build-docker' or 'make docker-dev' instead" - ./build-rustfs.sh --platform aarch64-unknown-linux-gnu + ๐Ÿ’ก For more help use 'make help', 'make help-build' or 'make help-docker' -.PHONY: deploy-dev -deploy-dev: build-musl - @echo "๐Ÿš€ Deploying to dev server: $${IP}" - ./scripts/dev_deploy.sh $${IP} + ๐Ÿฆ€ RustFS Makefile Help: -# ======================================================================================== -# Docker Multi-Architecture Builds (Primary Methods) -# ======================================================================================== + ๐Ÿ“‹ Main Command Categories: + make help-build # Show build-related help + make help-docker # Show Docker-related help -# Production builds using docker-buildx.sh (for CI/CD and production) -.PHONY: docker-buildx -docker-buildx: - @echo "๐Ÿ—๏ธ Building multi-architecture production Docker images with buildx..." - ./docker-buildx.sh + ๐Ÿ”ง Code Quality: + make fmt # Format code + make clippy # Run clippy checks + make test # Run tests + make pre-commit # Run all pre-commit checks -.PHONY: docker-buildx-push -docker-buildx-push: - @echo "๐Ÿš€ Building and pushing multi-architecture production Docker images with buildx..." - ./docker-buildx.sh --push + ๐Ÿš€ Quick Start: + make build # Build RustFS binary + make docker-dev-local # Build development Docker image (local) + make dev-env-start # Start development environment -.PHONY: docker-buildx-version -docker-buildx-version: - @if [ -z "$(VERSION)" ]; then \ - echo "โŒ Error: Please specify version, example: make docker-buildx-version VERSION=v1.0.0"; \ - exit 1; \ - fi - @echo "๐Ÿ—๏ธ Building multi-architecture production Docker images (version: $(VERSION))..." - ./docker-buildx.sh --release $(VERSION) -.PHONY: docker-buildx-push-version -docker-buildx-push-version: - @if [ -z "$(VERSION)" ]; then \ - echo "โŒ Error: Please specify version, example: make docker-buildx-push-version VERSION=v1.0.0"; \ - exit 1; \ - fi - @echo "๐Ÿš€ Building and pushing multi-architecture production Docker images (version: $(VERSION))..." - ./docker-buildx.sh --release $(VERSION) --push +endef +export HEADER -# Development/Source builds using direct buildx commands -.PHONY: docker-dev -docker-dev: - @echo "๐Ÿ—๏ธ Building multi-architecture development Docker images with buildx..." - @echo "๐Ÿ’ก This builds from source code and is intended for local development and testing" - @echo "โš ๏ธ Multi-arch images cannot be loaded locally, use docker-dev-push to push to registry" - $(DOCKER_CLI) buildx build \ - --platform linux/amd64,linux/arm64 \ - --file $(DOCKERFILE_SOURCE) \ - --tag rustfs:source-latest \ - --tag rustfs:dev-latest \ - . +-include $(addsuffix /*.mak, $(shell find .config/make -type d)) -.PHONY: docker-dev-local -docker-dev-local: - @echo "๐Ÿ—๏ธ Building single-architecture development Docker image for local use..." - @echo "๐Ÿ’ก This builds from source code for the current platform and loads locally" - $(DOCKER_CLI) buildx build \ - --file $(DOCKERFILE_SOURCE) \ - --tag rustfs:source-latest \ - --tag rustfs:dev-latest \ - --load \ - . - -.PHONY: docker-dev-push -docker-dev-push: - @if [ -z "$(REGISTRY)" ]; then \ - echo "โŒ Error: Please specify registry, example: make docker-dev-push REGISTRY=ghcr.io/username"; \ - exit 1; \ - fi - @echo "๐Ÿš€ Building and pushing multi-architecture development Docker images..." - @echo "๐Ÿ’ก Pushing to registry: $(REGISTRY)" - $(DOCKER_CLI) buildx build \ - --platform linux/amd64,linux/arm64 \ - --file $(DOCKERFILE_SOURCE) \ - --tag $(REGISTRY)/rustfs:source-latest \ - --tag $(REGISTRY)/rustfs:dev-latest \ - --push \ - . - -# Local production builds using direct buildx (alternative to docker-buildx.sh) -.PHONY: docker-buildx-production-local -docker-buildx-production-local: - @echo "๐Ÿ—๏ธ Building single-architecture production Docker image locally..." - @echo "๐Ÿ’ก Alternative to docker-buildx.sh for local testing" - $(DOCKER_CLI) buildx build \ - --file $(DOCKERFILE_PRODUCTION) \ - --tag rustfs:production-latest \ - --tag rustfs:latest \ - --load \ - --build-arg RELEASE=latest \ - . - -# ======================================================================================== -# Single Architecture Docker Builds (Traditional) -# ======================================================================================== - -.PHONY: docker-build-production -docker-build-production: - @echo "๐Ÿ—๏ธ Building single-architecture production Docker image..." - @echo "๐Ÿ’ก Consider using 'make docker-buildx-production-local' for multi-arch support" - $(DOCKER_CLI) build -f $(DOCKERFILE_PRODUCTION) -t rustfs:latest . - -.PHONY: docker-build-source -docker-build-source: - @echo "๐Ÿ—๏ธ Building single-architecture source Docker image..." - @echo "๐Ÿ’ก Consider using 'make docker-dev-local' for multi-arch support" - DOCKER_BUILDKIT=1 $(DOCKER_CLI) build \ - --build-arg BUILDKIT_INLINE_CACHE=1 \ - -f $(DOCKERFILE_SOURCE) -t rustfs:source . - -# ======================================================================================== -# Development Environment -# ======================================================================================== - -.PHONY: dev-env-start -dev-env-start: - @echo "๐Ÿš€ Starting development environment..." - $(DOCKER_CLI) buildx build \ - --file $(DOCKERFILE_SOURCE) \ - --tag rustfs:dev \ - --load \ - . - $(DOCKER_CLI) stop $(CONTAINER_NAME) 2>/dev/null || true - $(DOCKER_CLI) rm $(CONTAINER_NAME) 2>/dev/null || true - $(DOCKER_CLI) run -d --name $(CONTAINER_NAME) \ - -p 9010:9010 -p 9000:9000 \ - -v $(shell pwd):/workspace \ - -it rustfs:dev - -.PHONY: dev-env-stop -dev-env-stop: - @echo "๐Ÿ›‘ Stopping development environment..." - $(DOCKER_CLI) stop $(CONTAINER_NAME) 2>/dev/null || true - $(DOCKER_CLI) rm $(CONTAINER_NAME) 2>/dev/null || true - -.PHONY: dev-env-restart -dev-env-restart: dev-env-stop dev-env-start - -# ======================================================================================== -# Build Utilities -# ======================================================================================== - -.PHONY: docker-inspect-multiarch -docker-inspect-multiarch: - @if [ -z "$(IMAGE)" ]; then \ - echo "โŒ Error: Please specify image, example: make docker-inspect-multiarch IMAGE=rustfs/rustfs:latest"; \ - exit 1; \ - fi - @echo "๐Ÿ” Inspecting multi-architecture image: $(IMAGE)" - docker buildx imagetools inspect $(IMAGE) - -.PHONY: build-cross-all -build-cross-all: - @echo "๐Ÿ”ง Building all target architectures..." - @echo "๐Ÿ’ก On macOS/Windows, use 'make docker-dev' for reliable multi-arch builds" - @echo "๐Ÿ”จ Generating protobuf code..." - cargo run --bin gproto || true - @echo "๐Ÿ”จ Building x86_64-unknown-linux-gnu..." - ./build-rustfs.sh --platform x86_64-unknown-linux-gnu - @echo "๐Ÿ”จ Building aarch64-unknown-linux-gnu..." - ./build-rustfs.sh --platform aarch64-unknown-linux-gnu - @echo "๐Ÿ”จ Building x86_64-unknown-linux-musl..." - ./build-rustfs.sh --platform x86_64-unknown-linux-musl - @echo "๐Ÿ”จ Building aarch64-unknown-linux-musl..." - ./build-rustfs.sh --platform aarch64-unknown-linux-musl - @echo "โœ… All architectures built successfully!" - -# ======================================================================================== -# Help and Documentation -# ======================================================================================== - -.PHONY: help-build -help-build: - @echo "๐Ÿ”จ RustFS Build Help:" - @echo "" - @echo "๐Ÿš€ Local Build (Recommended):" - @echo " make build # Build RustFS binary (includes console by default)" - @echo " make build-dev # Development mode build" - @echo " make build-musl # Build x86_64 musl version" - @echo " make build-gnu # Build x86_64 GNU version" - @echo " make build-musl-arm64 # Build aarch64 musl version" - @echo " make build-gnu-arm64 # Build aarch64 GNU version" - @echo "" - @echo "๐Ÿณ Docker Build:" - @echo " make build-docker # Build using Docker container" - @echo " make build-docker BUILD_OS=ubuntu22.04 # Specify build system" - @echo "" - @echo "๐Ÿ—๏ธ Cross-architecture Build:" - @echo " make build-cross-all # Build binaries for all architectures" - @echo "" - @echo "๐Ÿ”ง Direct usage of build-rustfs.sh script:" - @echo " ./build-rustfs.sh --help # View script help" - @echo " ./build-rustfs.sh --no-console # Build without console resources" - @echo " ./build-rustfs.sh --force-console-update # Force update console resources" - @echo " ./build-rustfs.sh --dev # Development mode build" - @echo " ./build-rustfs.sh --sign # Sign binary files" - @echo " ./build-rustfs.sh --platform x86_64-unknown-linux-gnu # Specify target platform" - @echo " ./build-rustfs.sh --skip-verification # Skip binary verification" - @echo "" - @echo "๐Ÿ’ก build-rustfs.sh script provides more options, smart detection and binary verification" - -.PHONY: help-docker -help-docker: - @echo "๐Ÿณ Docker Multi-architecture Build Help:" - @echo "" - @echo "๐Ÿš€ Production Image Build (Recommended to use docker-buildx.sh):" - @echo " make docker-buildx # Build production multi-arch image (no push)" - @echo " make docker-buildx-push # Build and push production multi-arch image" - @echo " make docker-buildx-version VERSION=v1.0.0 # Build specific version" - @echo " make docker-buildx-push-version VERSION=v1.0.0 # Build and push specific version" - @echo "" - @echo "๐Ÿ”ง Development/Source Image Build (Local development testing):" - @echo " make docker-dev # Build dev multi-arch image (cannot load locally)" - @echo " make docker-dev-local # Build dev single-arch image (local load)" - @echo " make docker-dev-push REGISTRY=xxx # Build and push dev image" - @echo "" - @echo "๐Ÿ—๏ธ Local Production Image Build (Alternative):" - @echo " make docker-buildx-production-local # Build production single-arch image locally" - @echo "" - @echo "๐Ÿ“ฆ Single-architecture Build (Traditional way):" - @echo " make docker-build-production # Build single-arch production image" - @echo " make docker-build-source # Build single-arch source image" - @echo "" - @echo "๐Ÿš€ Development Environment Management:" - @echo " make dev-env-start # Start development container environment" - @echo " make dev-env-stop # Stop development container environment" - @echo " make dev-env-restart # Restart development container environment" - @echo "" - @echo "๐Ÿ”ง Auxiliary Tools:" - @echo " make build-cross-all # Build binaries for all architectures" - @echo " make docker-inspect-multiarch IMAGE=xxx # Check image architecture support" - @echo "" - @echo "๐Ÿ“‹ Environment Variables:" - @echo " REGISTRY Image registry address (required for push)" - @echo " DOCKERHUB_USERNAME Docker Hub username" - @echo " DOCKERHUB_TOKEN Docker Hub access token" - @echo " GITHUB_TOKEN GitHub access token" - @echo "" - @echo "๐Ÿ’ก Suggestions:" - @echo " - Production use: Use docker-buildx* commands (based on precompiled binaries)" - @echo " - Local development: Use docker-dev* commands (build from source)" - @echo " - Development environment: Use dev-env-* commands to manage dev containers" - -.PHONY: help -help: - @echo "๐Ÿฆ€ RustFS Makefile Help:" - @echo "" - @echo "๐Ÿ“‹ Main Command Categories:" - @echo " make help-build # Show build-related help" - @echo " make help-docker # Show Docker-related help" - @echo "" - @echo "๐Ÿ”ง Code Quality:" - @echo " make fmt # Format code" - @echo " make clippy # Run clippy checks" - @echo " make test # Run tests" - @echo " make pre-commit # Run all pre-commit checks" - @echo "" - @echo "๐Ÿš€ Quick Start:" - @echo " make build # Build RustFS binary" - @echo " make docker-dev-local # Build development Docker image (local)" - @echo " make dev-env-start # Start development environment" - @echo "" - @echo "๐Ÿ’ก For more help use 'make help-build' or 'make help-docker'" diff --git a/_typos.toml b/_typos.toml index e291ee07..b79e2226 100644 --- a/_typos.toml +++ b/_typos.toml @@ -36,6 +36,7 @@ clen = "clen" datas = "datas" bre = "bre" abd = "abd" +mak = "mak" [files] extend-exclude = [] \ No newline at end of file diff --git a/scripts/makefile-header.sh b/scripts/makefile-header.sh new file mode 100755 index 00000000..01ed2d35 --- /dev/null +++ b/scripts/makefile-header.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Total width of the whole line +WIDTH=100 # adjust if you want longer/shorter lines + +print_heading() { + local title="$1" + local prefix="## โ€”โ€” " + local suffix=" " + local dash="-" + + # length of the visible title block + local block_len=$(( ${#prefix} + ${#title} + ${#suffix} )) + + # number of dashes needed + local dash_count=$(( WIDTH - block_len )) + + # build dash line + local dashes + dashes=$(printf "%*s" "$dash_count" "" | tr ' ' "$dash") + + # print the final heading + printf "%s%s%s%s\n" "$prefix" "$title" "$suffix" "$dashes" +} + +print_heading "$1"