-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c5c0a3
commit 84fda34
Showing
5 changed files
with
166 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool | ||
*.out | ||
|
||
# Go workspace file | ||
go.work | ||
go.work.sum | ||
|
||
# Dependency directories | ||
# vendor/ | ||
|
||
# Build results | ||
dist/ | ||
*.prof | ||
|
||
# IDE configuration files | ||
.idea/ | ||
.vscode/ | ||
|
||
# Environment variable files | ||
.env | ||
|
||
# Temporary files | ||
*.tmp | ||
*.log | ||
*.swp | ||
*.swo | ||
.DS_Store | ||
|
||
# Configuration files | ||
*.toml | ||
|
||
# Exclude deployment-related files | ||
deployments/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,94 @@ | ||
-include .env | ||
|
||
CURRENT_DIR = $(shell realpath .) | ||
MODULE_DIRS = $(shell find $(CURRENT_DIR) -name go.mod -exec dirname {} \;) | ||
|
||
DOCKER_IMAGE = $(shell basename -s .git $(shell git config --get remote.origin.url)) | ||
DOCKER_TAG = $(shell git tag --sort=-v:refname | grep -v '/' | head -n 1 || echo "latest") | ||
DOCKERFILE = deployments/Dockerfile | ||
|
||
CGO_ENABLED ?= 1 | ||
|
||
.PHONY: init generate build clean tidy update sync check test coverage benchmark lint fmt vet staticcheck doc docker-build | ||
|
||
.PHONY: init | ||
init: | ||
@cp .go.work go.work | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; go install -v ./...' | ||
@$(MAKE) install-tools | ||
@$(MAKE) install-modules | ||
|
||
install-tools: | ||
@go install honnef.co/go/tools/cmd/staticcheck@latest | ||
@go install golang.org/x/tools/cmd/godoc@latest | ||
|
||
.PHONY: generate | ||
install-modules: | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && go install -v ./...; \ | ||
done | ||
|
||
generate: | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; go generate ./...' | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && go generate ./...; \ | ||
done | ||
|
||
.PHONY: build | ||
build: | ||
@go clean -cache | ||
@mkdir -p dist | ||
@cd cmd && go build -ldflags "-s -w" -o ../dist ./... | ||
@cd cmd && CGO_ENABLED=$(CGO_ENABLED) go build -ldflags "-s -w" -o ../dist ./... | ||
|
||
.PHONY: clean | ||
clean: | ||
@go clean -cache | ||
@rm -rf dist | ||
|
||
.PHONY: tidy | ||
tidy: | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; go mod tidy' | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && go mod tidy; \ | ||
done | ||
|
||
.PHONY: update | ||
update: | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; go get -u all && go mod tidy' | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && go get -u all && go mod tidy; \ | ||
done | ||
|
||
.PHONY: sync | ||
sync: | ||
@go work sync | ||
|
||
.PHONY: check | ||
check: lint test | ||
|
||
.PHONY: test | ||
test: | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; go test -race $(test-options) ./...' | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && go test -race $(test-options) ./...; \ | ||
done | ||
|
||
.PHONY: coverage | ||
coverage: | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; go test -race --coverprofile=coverage.out --covermode=atomic $(test-options) ./...' | ||
@find $(realpath .) -name go.mod | xargs dirname | grep '${CURRENT_DIR}/' | xargs -I {} sh -c 'cd {}; cat coverage.out >> '${CURRENT_DIR}/coverage.out' && rm coverage.out' | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && go test -race --coverprofile=coverage.out --covermode=atomic $(test-options) ./...; \ | ||
cat coverage.out >> $(CURRENT_DIR)/coverage.out && rm coverage.out; \ | ||
done | ||
|
||
.PHONY: benchmark | ||
benchmark: | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; go test -run="-" -bench=".*" -benchmem $(test-options) ./...' | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && go test -run="-" -bench=".*" -benchmem $(test-options) ./...; \ | ||
done | ||
|
||
.PHONY: lint | ||
lint: fmt vet staticcheck | ||
|
||
.PHONY: fmt | ||
fmt: | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; go fmt ./...' | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && go fmt ./...; \ | ||
done | ||
|
||
.PHONY: vet | ||
vet: | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; go vet ./...' | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && go vet ./...; \ | ||
done | ||
|
||
.PHONY: staticcheck | ||
staticcheck: init | ||
@find $(realpath .) -name go.mod | xargs dirname | xargs -I {} sh -c 'cd {}; staticcheck ./...' | ||
@for dir in $(MODULE_DIRS); do \ | ||
cd $$dir && staticcheck ./...; \ | ||
done | ||
|
||
.PHONY: doc | ||
doc: init | ||
@godoc -http=:6060 | ||
|
||
docker-build: | ||
docker build --no-cache -t $(DOCKER_IMAGE):$(DOCKER_TAG) -f $(DOCKERFILE) $(CURRENT_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM golang:1.23 as builder | ||
|
||
WORKDIR /app | ||
|
||
COPY ./ . | ||
|
||
RUN make init | ||
RUN make build CGO_ENABLED=0 | ||
|
||
FROM alpine:latest | ||
|
||
WORKDIR /root/ | ||
|
||
COPY --from=builder /app/dist/uniflow ./uniflow | ||
|
||
ENTRYPOINT ["./uniflow"] |