-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
72 lines (57 loc) · 2.24 KB
/
Copy pathMakefile
File metadata and controls
72 lines (57 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
SHELL := /bin/bash
GO ?= go
IMAGE ?= gokhalh/localaik:test
PORT ?= 18090
CONTAINER_NAME ?= localaik-dev
BUILD_IMAGE ?= 1
GOCACHE ?= $(CURDIR)/.cache/go-build
GOFILES := $(shell find cmd internal integration -name '*.go' -type f | sort)
export GOCACHE
.PHONY: help fmt fmt-check lint test-unit test-integration test build docker-build docker-build-proxy docker-up docker-down
help:
@printf '%s\n' \
'make fmt Format Go sources' \
'make fmt-check Fail if Go sources are not formatted' \
'make lint Run formatting check and go vet' \
'make test-unit Run unit tests under cmd/ and internal/' \
'make test-integration Run all integration tests; assumes docker-up is already running' \
'make test Run lint, unit tests, and integration tests' \
'make build Build the localaik binary' \
'make docker-build Build the Docker image' \
'make docker-build-proxy Build the proxy-only image' \
'make docker-up Start the Docker image on PORT' \
'make docker-down Stop and remove the Docker container'
fmt:
@gofmt -w $(GOFILES)
fmt-check:
@test -z "$$(gofmt -l $(GOFILES))"
lint: fmt-check
@$(GO) vet ./...
test-unit:
@$(GO) test ./cmd/... ./internal/...
test-integration:
@$(GO) test -count=1 -tags=docker_integration ./integration
test: lint test-unit test-integration
build:
@$(GO) build ./cmd/localaik
docker-build:
@docker build -t "$(IMAGE)" .
docker-build-proxy:
@docker build --target proxy -t "$(IMAGE)-proxy" .
docker-up:
@if [[ "$(BUILD_IMAGE)" == "1" ]]; then $(MAKE) docker-build IMAGE="$(IMAGE)"; fi
@docker rm -f "$(CONTAINER_NAME)" >/dev/null 2>&1 || true
@docker run -d --name "$(CONTAINER_NAME)" -p "$(PORT):8090" "$(IMAGE)" >/dev/null
@echo "localaik is starting on http://127.0.0.1:$(PORT)"
@for _ in $$(seq 1 90); do \
if curl -fsS "http://127.0.0.1:$(PORT)/health" >/dev/null 2>&1; then \
echo "localaik is ready on http://127.0.0.1:$(PORT)"; \
exit 0; \
fi; \
sleep 2; \
done; \
echo "localaik did not become healthy on http://127.0.0.1:$(PORT)" >&2; \
docker logs "$(CONTAINER_NAME)" >&2 || true; \
exit 1
docker-down:
@docker rm -f "$(CONTAINER_NAME)" >/dev/null 2>&1 || true