forked from imgproxy/imgproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
198 lines (168 loc) · 5.13 KB
/
Copy pathMakefile
File metadata and controls
198 lines (168 loc) · 5.13 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# imgproxy Makefile
BINARY := ./imgproxy
MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
GOCMD := go
GOBUILD := $(GOCMD) build
GOCLEAN := $(GOCMD) clean
GOTEST := $(GOCMD) test
GOFMT := gofmt
GOLINT := golangci-lint
CLANG_FORMAT := clang-format
GOTESTSUM := gotestsum
SRCDIR := ./cli
RCFILE := ./.imgproxyrc
BREW_PREFIX :=
BASE_IMAGE ?= ghcr.io/imgproxy/imgproxy-base:v4.1.4
# Common environment setup for CGO builds
ifneq ($(shell which brew),)
BREW_PREFIX := $(shell brew --prefix)
endif
# Export CGO environment variables
export CGO_LDFLAGS_ALLOW := -s|-w
# Library paths for Homebrew-installed libraries on macOS
ifdef BREW_PREFIX
export PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(shell brew --prefix libffi)/lib/pkgconfig
export PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(shell brew --prefix libarchive)/lib/pkgconfig
export PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):$(shell brew --prefix cfitsio)/lib/pkgconfig
export CGO_LDFLAGS := $(CGO_LDFLAGS) -Wl,-no_warn_duplicate_libraries
endif
# Get build arguments
ifeq (build,$(firstword $(MAKECMDGOALS)))
BUILD_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
endif
# Get run arguments
ifeq (run,$(firstword $(MAKECMDGOALS)))
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
endif
ifeq (build-and-run,$(firstword $(MAKECMDGOALS)))
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
endif
# Get version to bump to in bump-version target
ifeq (bump-version,$(firstword $(MAKECMDGOALS)))
NEW_VERSION := $(wordlist 2,2,$(MAKECMDGOALS))
endif
# Wrapper action to run commands in Docker
.PHONY: _run-in-docker
_run-in-docker:
ifdef IMGPROXY_IN_BASE_CONTAINER
@$(MAKE) $(DOCKERCMD)
else
@docker volume create imgproxy-cache >/dev/null
@docker run --rm -v imgproxy-cache:/data busybox sh -c 'mkdir -p /data/cache /data/go-mod'
@docker run --init --rm -it \
-v "$(MAKEFILE_DIR):/workspaces/imgproxy" \
--mount type=volume,source=imgproxy-cache,target=/root/.cache,volume-subpath=cache \
--mount type=volume,source=imgproxy-cache,target=/root/go/pkg/mod,volume-subpath=go-mod \
-w /workspaces/imgproxy \
-e IMGPROXY_IN_BASE_CONTAINER=1 \
$(BASE_IMAGE) \
bash -c "make $(DOCKERCMD)"
endif
# Default target
.PHONY: all
all: build
# Build the binary. If -o is not provided, it defaults to $(BINARY).
#
# Usage:
# make build -- -o output_name
.PHONY: build
build:
@$(GOBUILD) -v -o $(BINARY) $(BUILD_ARGS) $(SRCDIR)
# Clean
.PHONY: clean
clean:
echo $$PKG_CONFIG_PATH
@$(GOCLEAN)
rm -f $(BINARY)
# Run imgproxy binary
#
# Usage:
# make run -- arg1 arg2
#
# If .imgproxyrc exists, it will be sourced before running the binary.
.PHONY: run
run: SHELL := bash
run:
ifneq (,$(wildcard $(RCFILE)))
@source $(RCFILE) && $(BINARY) $(RUN_ARGS)
else
@$(BINARY) $(RUN_ARGS)
endif
.PHONY: build-and-run
build-and-run: build run
# Run tests
#
# Usage:
# make test -- -run FooTest
.PHONY: test _test
test: DOCKERCMD := _test
test: _run-in-docker
_test:
ifneq ($(shell which $(GOTESTSUM)),)
@$(GOTESTSUM) ./...
else
@$(GOTEST) -v ./...
endif
# Format code
.PHONY: fmt
fmt:
@$(GOFMT) -s -w .
# Lint code (requires golangci-lint installed)
.PHONY: lint-go _lint-go
lint-go: DOCKERCMD := _lint-go
lint-go: _run-in-docker
_lint-go:
@$(GOLINT) run
# Lint C code (requires clang-format installed)
.PHONY: lint-clang _lint-clang
lint-clang: DOCKERCMD := _lint-clang
lint-clang: _run-in-docker
_lint-clang:
@find . -not -path "./.tmp/*" -not -path "./.git/*" \( -iname "*.h" -o -iname "*.c" -o -iname "*.cpp" \) | xargs $(CLANG_FORMAT) --dry-run --Werror
# Run all linters
.PHONY: lint
lint: lint-go ling-clang
# Upgrade direct Go dependencies
.PHONY: upgrade
upgrade:
@$(GOCMD) mod tidy
@$(GOCMD) get $$($(GOCMD) list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all)
@$(GOCMD) mod tidy
# Run lychee
.PHONY: lychee _lychee
lychee: DOCKERCMD := _lychee
lychee: _run-in-docker
_lychee:
@lychee README.md CHANGELOG.md
.PHONY: devcontainer
devcontainer:
devcontainer exec --workspace-folder $(MAKEFILE_DIR) bash
.PHONY: update-gh-actions
update-gh-actions:
ifneq ($(shell which pinact),)
@pinact run -u --min-age 7
else
$(error pinact is not installed. See installation instructions at https://github.com/suzuki-shunsuke/pinact/blob/main/INSTALL.md)
endif
.PHONY: bump-version
bump-version: NEW_VERSION ?= $(error NEW_VERSION variable is required)
bump-version:
@echo "$(NEW_VERSION)" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$$' || \
{ echo "Error: invalid version format '$(NEW_VERSION)' (expected X.Y.Z)"; exit 1; }
@echo "Bumping version to $(NEW_VERSION)\n"
@sed -i.bak "s/const Version = \".*\"/const Version = \"$(NEW_VERSION)\"/" version/version.go
@rm version/version.go.bak
@echo "✓ Updated version/version.go"
@sed -i.bak "s/## \[$(NEW_VERSION)] .*/## [$(NEW_VERSION)] - $(shell date +%Y-%m-%d)/" CHANGELOG.md
@rm CHANGELOG.md.bak
@echo "✓ Updated CHANGELOG.md"
@echo "\nTo complete the version bump:"
@echo " git add ."
@echo " git commit -am \"Bump version to $(NEW_VERSION)\""
@echo " git push"
@echo " git tag v$(NEW_VERSION)"
@echo " git push origin v$(NEW_VERSION)"
# Make any unknown target do nothing to avoid "up to date" messages
.PHONY: FORCE
%: FORCE
@: