-
Notifications
You must be signed in to change notification settings - Fork 16
/
justfile
133 lines (105 loc) · 4.67 KB
/
justfile
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# This justfile requires https://github.com/casey/just
# Load environment variables from `.env` file.
set dotenv-load
timestamp := `date +%s`
semver := env_var('PROJECT_VERSION')
commit := `git show -s --format=%h`
version := semver + "+" + commit
coverage_profile_log := "coverage_profile.txt"
# print available targets
default:
@just --list --justfile {{justfile()}}
# evaluate and print all just variables
evaluate:
@just --evaluate
# print system information such as OS and architecture
system-info:
@echo "architecture: {{arch()}}"
@echo "os: {{os()}}"
@echo "os family: {{os_family()}}"
# detect known vulnerabilities (requires https://github.com/sonatype-nexus-community/nancy)
audit:
go list -json -m all | nancy sleuth --loud
# benchmark the app's HTTP endpoint with plow (requires https://github.com/six-ddc/plow)
benchmark-plow:
@echo plow -c 100 --duration=30s http://localhost:${APP_PORT}/status
@plow -c 100 --duration=30s http://localhost:${APP_PORT}/status
# benchmark the app's HTTP endpoint with wrk (requires https://github.com/wg/wrk)
benchmark-wrk:
@echo wrk -t 10 -c 100 --latency --duration 30 http://localhost:${APP_PORT}/status
@wrk -t 10 -c 100 --latency --duration 30 http://localhost:${APP_PORT}/status
# build executable for local OS
build: test-vanilla
@echo "Building executable for local OS ..."
go build -trimpath -ldflags="-X 'main.Version={{version}}'" -o app cmd/golang-docker-build-tutorial/main.go
# show test coverage
coverage:
go test -coverprofile={{coverage_profile_log}} ./...
go tool cover -html={{coverage_profile_log}}
# show dependencies
deps:
go mod graph
# create a docker image (requires Docker)
docker-image-create:
@echo "Creating a docker image ..."
@PROJECT_VERSION={{version}} ./create_image.sh
# run the docker image (requires Docker)
docker-image-run:
@echo "Running container from docker image ..."
@./start_container.sh
# size of the docker image (requires Docker)
docker-image-size:
@docker images $DOCKER_IMAGE_NAME
# explain lint identifier (e.g., "SA1006")
explain lint-identifier:
staticcheck -explain {{lint-identifier}}
# format source code
format:
@echo "Formatting source code ..."
gofmt -l -s -w .
# run linters (requires https://github.com/dominikh/go-tools)
lint:
staticcheck -f stylish ./... || \
(echo "\nRun \`just explain <LintIdentifier, e.g. SA1006>\` for details." && \
exit 1)
# detect outdated modules (requires https://github.com/psampaz/go-mod-outdated)
outdated:
go list -u -m -json all | go-mod-outdated -update
# build release executables for all supported platforms
release: test-vanilla
@echo "Building release executables (incl. cross compilation) ..."
# `go tool dist list` shows supported architectures (GOOS)
GOOS=darwin GOARCH=arm64 \
go build -trimpath -ldflags "-X 'main.Version={{version}}' -s -w" -o app_macos-arm64 cmd/golang-docker-build-tutorial/main.go
GOOS=linux GOARCH=386 \
go build -trimpath -ldflags "-X 'main.Version={{version}}' -s -w" -o app_linux-386 cmd/golang-docker-build-tutorial/main.go
GOOS=linux GOARCH=amd64 \
go build -trimpath -ldflags "-X 'main.Version={{version}}' -s -w" -o app_linux-amd64 cmd/golang-docker-build-tutorial/main.go
GOOS=linux GOARCH=arm \
go build -trimpath -ldflags "-X 'main.Version={{version}}' -s -w" -o app_linux-arm cmd/golang-docker-build-tutorial/main.go
GOOS=linux GOARCH=arm64 \
go build -trimpath -ldflags "-X 'main.Version={{version}}' -s -w" -o app_linux-arm64 cmd/golang-docker-build-tutorial/main.go
# run executable for local OS
run:
@echo "Running golang-docker-build-tutorial with defaults ..."
go run -ldflags="-X 'main.Version={{version}}'" cmd/golang-docker-build-tutorial/main.go
# send request to the app's HTTP endpoint (requires curl and running container)
send-request-to-app:
@curl http://localhost:${APP_PORT}/status
# run tests with colorized output (requires https://github.com/kyoh86/richgo)
test *FLAGS:
richgo test -cover {{FLAGS}} ./...
# run tests (vanilla), used for CI workflow
test-vanilla *FLAGS:
go test -cover {{FLAGS}} ./...
# add missing module requirements for imported packages, removes requirements that aren't used anymore
tidy:
go mod tidy
# detect known vulnerabilities (requires https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck)
vulnerabilities:
govulncheck ./...
# watch sources for changes and trigger a rebuild (requires https://github.com/watchexec/watchexec)
watch:
# Watch all go files in the current directory and all subdirectories for
# changes. If something changed, re-run the build.
@watchexec -e go -- just build