73 lines
2.4 KiB
Makefile
73 lines
2.4 KiB
Makefile
.PHONY: build clean push release help
|
|
|
|
VERSION ?= 1.0.0
|
|
S3_BUCKET ?=
|
|
BINARY_NAME ?= installer
|
|
BUILD_DIR := ./dist
|
|
|
|
ARCHS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
|
|
|
|
build: $(addprefix $(BUILD_DIR)/$(BINARY_NAME)-, $(subst /,-,$(ARCHS)))
|
|
|
|
$(BUILD_DIR)/$(BINARY_NAME)-linux-amd64:
|
|
@mkdir -p $(BUILD_DIR)
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v3 go build -ldflags="-extldflags -static" -o $@ ./cmd
|
|
|
|
$(BUILD_DIR)/$(BINARY_NAME)-linux-arm64:
|
|
@mkdir -p $(BUILD_DIR)
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-extldflags -static" -o $@ ./cmd
|
|
|
|
$(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64:
|
|
@mkdir -p $(BUILD_DIR)
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $@ ./cmd
|
|
|
|
$(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64:
|
|
@mkdir -p $(BUILD_DIR)
|
|
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o $@ ./cmd
|
|
|
|
$(BUILD_DIR)/$(BINARY_NAME)-windows-amd64:
|
|
@mkdir -p $(BUILD_DIR)
|
|
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $@ ./cmd
|
|
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|
|
|
|
push: build
|
|
ifndef S3_BUCKET
|
|
$(error S3_BUCKET is not set)
|
|
endif
|
|
aws s3 sync $(BUILD_DIR)/ s3://$(S3_BUCKET)/installer/$(VERSION)/ --exclude '*' --include '$(BINARY_NAME)-*'
|
|
aws s3 sync $(BUILD_DIR)/ s3://$(S3_BUCKET)/installer/latest/ --exclude '*' --include '$(BINARY_NAME)-*'
|
|
|
|
release: build
|
|
ifndef S3_BUCKET
|
|
$(error S3_BUCKET is not set)
|
|
endif
|
|
@for arch in $(ARCHS); do \
|
|
os=$$(echo $$arch | cut -d/ -f1); \
|
|
arch_name=$$(echo $$arch | cut -d/ -f2); \
|
|
ext=$$(if [ $$os = windows ]; then .exe; else ''; fi); \
|
|
src="$(BUILD_DIR)/$(BINARY_NAME)-$$arch"; \
|
|
dest="s3://$(S3_BUCKET)/installer/$(VERSION)/$(BINARY_NAME)-$$os-$$arch_name$$ext"; \
|
|
aws s3 cp $$src $$dest; \
|
|
aws s3 cp $$src "s3://$(S3_BUCKET)/installer/latest/$(BINARY_NAME)-$$os-$$arch_name$$ext"; \
|
|
done
|
|
|
|
help:
|
|
@echo "Variables:"
|
|
@echo " VERSION - Version tag (default: 1.0.0)"
|
|
@echo " S3_BUCKET - S3 bucket name (required for push/release)"
|
|
@echo " BINARY_NAME - Binary name (default: installer)"
|
|
@echo ""
|
|
@echo "Targets:"
|
|
@echo " build - Build binaries for all architectures"
|
|
@echo " push - Sync dist/ to S3 (version + latest)"
|
|
@echo " release - Copy each binary to S3 with proper naming"
|
|
@echo " clean - Remove dist/"
|
|
@echo " help - Show this help"
|
|
@echo ""
|
|
@echo "Examples:"
|
|
@echo " make build"
|
|
@echo " make build VERSION=2.0.0"
|
|
@echo " make push S3_BUCKET=my-bucket VERSION=1.0.0"
|
|
@echo " make release S3_BUCKET=my-bucket VERSION=2.0.0"
|