feat(ci): add deploy workflow and Makefile
- Add .gitea/workflows/deploy.yml for CD pipeline - Add Makefile for build automation - Update .gitignore to exclude docs/
This commit is contained in:
59
Makefile
Normal file
59
Makefile
Normal file
@@ -0,0 +1,59 @@
|
||||
.PHONY: build test run docker docker-push clean help
|
||||
|
||||
APP_NAME := carrot_bbs
|
||||
VERSION := $(shell git rev-parse --short HEAD 2>/dev/null || echo "dev")
|
||||
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
|
||||
LDFLAGS := -ldflags "-s -w -X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)"
|
||||
|
||||
REGISTRY := code.littlelan.cn
|
||||
IMAGE_NAME := carrot_bbs/backend
|
||||
|
||||
help:
|
||||
@echo "Available targets:"
|
||||
@echo " make build - Build the binary"
|
||||
@echo " make test - Run tests"
|
||||
@echo " make run - Run locally"
|
||||
@echo " make docker - Build Docker image"
|
||||
@echo " make docker-push - Push Docker image to registry"
|
||||
@echo " make clean - Clean build artifacts"
|
||||
|
||||
build:
|
||||
@echo "Building $(APP_NAME)..."
|
||||
CGO_ENABLED=0 go build $(LDFLAGS) -o server ./cmd/server
|
||||
|
||||
test:
|
||||
@echo "Running tests..."
|
||||
go test -v -race -coverprofile=coverage.out ./...
|
||||
go tool cover -html=coverage.out -o coverage.html
|
||||
|
||||
run:
|
||||
@echo "Running $(APP_NAME)..."
|
||||
go run ./cmd/server
|
||||
|
||||
docker:
|
||||
@echo "Building Docker image..."
|
||||
docker build -t $(REGISTRY)/$(IMAGE_NAME):$(VERSION) -t $(REGISTRY)/$(IMAGE_NAME):latest .
|
||||
|
||||
docker-push:
|
||||
@echo "Pushing Docker image..."
|
||||
docker push $(REGISTRY)/$(IMAGE_NAME):$(VERSION)
|
||||
docker push $(REGISTRY)/$(IMAGE_NAME):latest
|
||||
|
||||
clean:
|
||||
@echo "Cleaning..."
|
||||
rm -f server
|
||||
rm -f coverage.out coverage.html
|
||||
go clean
|
||||
|
||||
lint:
|
||||
@echo "Running linter..."
|
||||
golangci-lint run ./...
|
||||
|
||||
fmt:
|
||||
@echo "Formatting code..."
|
||||
go fmt ./...
|
||||
goimports -w .
|
||||
|
||||
wire:
|
||||
@echo "Generating wire..."
|
||||
cd cmd/server && wire
|
||||
Reference in New Issue
Block a user