-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
79 additions
and
121 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 |
---|---|---|
@@ -1,102 +1,53 @@ | ||
ME = $(lastword $(MAKEFILE_LIST)) | ||
.DEFAULT_GOAL := help | ||
.PHONY: help | ||
help: # prints this help | ||
@bash -c "$$AUTOGEN_HELP_BASH" < $(ME) | ||
.PHONY: run watch clean test ubuntu coverage lint quality fmt | ||
|
||
BINARY_NAME=tinytune | ||
VERSION=0.0.1 | ||
|
||
COMMIT_HASH=$(shell git rev-parse --short HEAD) | ||
BUILD_TIMESTAMP=$(shell date '+%Y-%m-%dT%H:%M:%S') | ||
|
||
LDFLAGS=-ldflags "-X 'main.Version=${VERSION}' -X 'main.CommitHash=${COMMIT_HASH}' -X 'main.BuildTimestamp=${BUILD_TIMESTAMP}' -X 'main.Mode=Production'" | ||
|
||
CGO_LDFLAGS=-ljemalloc | ||
CGO_CFLAGS=-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free | ||
|
||
.PHONY: build | ||
build: ## build executables | ||
echo "Building frontend assets" | ||
GO=CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS="${CGO_LDFLAGS}" go | ||
|
||
LINUX_AMD64 = out/${BINARY_NAME}_linux_amd64 | ||
WEB_ASSETS = web/assets/index.min.js | ||
|
||
RUN_FOLDER = ./test/ | ||
|
||
build: ${LINUX_AMD64} | ||
|
||
${WEB_ASSETS}: | ||
make -C ./web build | ||
mkdir -p out/ | ||
echo "Building executable" | ||
GOARCH=amd64 \ | ||
GOOS=linux \ | ||
CGO_CFLAGS="${CGO_CFLAGS}" \ | ||
CGO_LDFLAGS="${CGO_LDFLAGS}" \ | ||
go build ${LDFLAGS} -o out/${BINARY_NAME}_linux_amd64 cmd/tinytune/tinytune.go | ||
chmod +x out/${BINARY_NAME}_linux_amd64 | ||
echo "Done" | ||
|
||
.PHONY: run | ||
|
||
${LINUX_AMD64}: ${WEB_ASSETS} | ||
GOARCH=amd64 GOOS=linux ${GO} build ${LDFLAGS} -o ${LINUX_AMD64} cmd/tinytune/tinytune.go | ||
|
||
run: ## run tinytune server | ||
CGO_CFLAGS="${CGO_CFLAGS}" CGO_LDFLAGS="${CGO_LDFLAGS}" go run cmd/tinytune/tinytune.go ./test/ | ||
${GO} run cmd/tinytune/tinytune.go "${RUN_FOLDER}" | ||
|
||
.PHONY: watch | ||
watch: ## run tinytune server and frontend in hot-reload way | ||
reflex -r '\.(html|go)$\' -s make run & make -C ./web watch | ||
|
||
.PHONY: clean | ||
clean: ## clean | ||
clear: ## clean | ||
go clean | ||
rm -rf out/ | ||
rm -f coverage*.out | ||
make -C ./web clear | ||
|
||
.PHONY: test | ||
test: ## run server tests | ||
go test -timeout 2m -race -failfast ./... | ||
|
||
.PHONY: ubuntu | ||
ubuntu: ## Install deps for ubuntu (libvips, ffmpeg) | ||
sudo apt install build-essential libvips pkg-config libvips-dev libjemalloc-dev ffmpeg -y | ||
npm i --prefix ./web | ||
|
||
.PHONY: coverage | ||
coverage: ## coverage | ||
make test | ||
go tool cover -html=coverage.out | ||
|
||
.PHONY: lint | ||
lint: ## run server linting | ||
golangci-lint run --fix | ||
|
||
.PHONY: quality | ||
quality: ## check-quality | ||
make fmt | ||
make lint | ||
|
||
.PHONY: fmt | ||
fmt: ## run server prettyfier | ||
go fmt ./... | ||
|
||
$(VERBOSE).SILENT: | ||
|
||
|
||
define AUTOGEN_HELP_BASH | ||
declare -A targets; declare -a torder | ||
targetre='^([A-Za-z]+):.* *# *(.*)' | ||
if [[ $$TERM && $$TERM != dumb && -t 1 ]]; then | ||
ul=$$'\e[0;4m'; bbold=$$'\e[34;1m'; reset=$$'\e[0m' | ||
fi | ||
if [[ -n "$(TITLE)" ]]; then | ||
printf "\n %sMakefile targets - $(TITLE)%s\n\n" "$$ul" "$$reset" | ||
else | ||
printf "\n %sMakefile targets%s\n\n" "$$ul" "$$reset" | ||
fi | ||
while read -r line; do | ||
if [[ $$line =~ $$targetre ]]; then | ||
target=$${BASH_REMATCH[1]}; help=$${BASH_REMATCH[2]} | ||
torder+=("$$target") | ||
targets[$$target]=$$help | ||
if (( $${#target} > max )); then max=$${#target}; fi | ||
fi | ||
done | ||
for t in "$${torder[@]}"; do | ||
printf " %smake %-*s%s %s\n" "$$bbold" $$max "$$t" "$$reset" \ | ||
"$${targets[$$t]}" | ||
done | ||
if [[ -n "$(HOMEPAGE)" ]]; then | ||
printf "\n Homepage:\n $(HOMEPAGE)\n\n" | ||
else | ||
printf "\n" | ||
fi | ||
endef | ||
export AUTOGEN_HELP_BASH | ||
quality: fmt lint ## check-quality |
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package throttle | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
type Throttler interface { | ||
Throttle(ctx context.Context) error | ||
} | ||
|
||
type throttler struct { | ||
maxMemoryOccupied float64 | ||
maxWaitingTime time.Duration | ||
} | ||
|
||
//nolint:ireturn | ||
func NewThrottler(maxMemoryOccupied float64, maxWaitingTime time.Duration) Throttler { | ||
return &throttler{maxMemoryOccupied, maxWaitingTime} | ||
} |
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 @@ | ||
NONAME TEST FILE |
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,46 +1,20 @@ | ||
ME = $(lastword $(MAKEFILE_LIST)) | ||
.DEFAULT_GOAL := help | ||
.PHONY: help | ||
help: # prints this help | ||
@bash -c "$$AUTOGEN_HELP_BASH" < $(ME) | ||
.PHONY: watch clear | ||
|
||
VENDOR = assets/vendor.bundle.js | ||
INDEX =assets/index.min.js | ||
|
||
$(VERBOSE).SILENT: | ||
|
||
.PHONY: build | ||
build: ## build all assets (.js, .css) | ||
npm run build-all | ||
build: ${VENDOR} ${INDEX} ## build all assets (.js, .css) | ||
|
||
${VENDOR}: | ||
npm run build-vendor | ||
|
||
${INDEX}: | ||
npm run build | ||
|
||
.PHONY: watch | ||
watch: ## build all assets in hot-reload way | ||
npm run watch | ||
|
||
define AUTOGEN_HELP_BASH | ||
declare -A targets; declare -a torder | ||
targetre='^([A-Za-z]+):.* *# *(.*)' | ||
if [[ $$TERM && $$TERM != dumb && -t 1 ]]; then | ||
ul=$$'\e[0;4m'; bbold=$$'\e[34;1m'; reset=$$'\e[0m' | ||
fi | ||
if [[ -n "$(TITLE)" ]]; then | ||
printf "\n %sMakefile targets - $(TITLE)%s\n\n" "$$ul" "$$reset" | ||
else | ||
printf "\n %sMakefile targets%s\n\n" "$$ul" "$$reset" | ||
fi | ||
while read -r line; do | ||
if [[ $$line =~ $$targetre ]]; then | ||
target=$${BASH_REMATCH[1]}; help=$${BASH_REMATCH[2]} | ||
torder+=("$$target") | ||
targets[$$target]=$$help | ||
if (( $${#target} > max )); then max=$${#target}; fi | ||
fi | ||
done | ||
for t in "$${torder[@]}"; do | ||
printf " %smake %-*s%s %s\n" "$$bbold" $$max "$$t" "$$reset" \ | ||
"$${targets[$$t]}" | ||
done | ||
if [[ -n "$(HOMEPAGE)" ]]; then | ||
printf "\n Homepage:\n $(HOMEPAGE)\n\n" | ||
else | ||
printf "\n" | ||
fi | ||
endef | ||
export AUTOGEN_HELP_BASH | ||
clear: | ||
rm -rf ${VENDOR} ${INDEX} |