forked from theherk/pr0nbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (90 loc) · 3.19 KB
/
Makefile
File metadata and controls
117 lines (90 loc) · 3.19 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
PHONY: all clean clean-build clean-dist clean-tmp dockes-shim dte tf-apply tf-plan
.DEFAULT_GOAL := help
help:
$(info available targets:)
@awk '/^[a-zA-Z\-\_0-9\.\$$\(\)\%/]+:/ { \
helpMsg = $$0; \
nb = sub(/^[^:]*:.* ## /, "", helpMsg); \
if (nb) \
print $$1 "\t" helpMsg; \
}' \
$(MAKEFILE_LIST) | column -ts $$'\t' | \
grep --color '^[^ ]*'
# project variables
PROJ_NAME := pr0nbot
VERSION = $(if $(SNAP),SNAPSHOT,$(shell git describe --always --dirty))
# helper variables
BUILD := build
DIST := dist
LAMBDA_DIR := lambdas
TF := terraform
TMP := $(BUILD)/tmp
REPO_PATH := github.com/theherk/pr0nbot
LDFLAGS = "-X $(REPO_PATH)/util.Version=$(VERSION)"
LAMBDA_ARCS :=
define LAMBDA_template
LAMBDA_ARCS += $(DIST)/$(1).zip
endef
LAMBDAS := test-lambda
$(foreach LAMBDA,$(LAMBDAS),$(eval $(call LAMBDA_template,$(LAMBDA))))
ifeq ($(OS),Windows_NT)
MKDIR := mkdir
FixPath = $(subst /,\,$1)
else
MKDIR := mkdir -p
FixPath = $1
endif
t:
echo $(OS)
$(MKDIR) $(call FixPath,test/path)
all: bin lambda-arcs ## build binary and lambda distributions
bin: $(BUILD)/$(PROJ_NAME) ## build the main program / cli
clean: clean-build clean-dist clean-tmp ## remove build, dist, and tmp directories
clean-build: ## remove build directory
rm -rf $(BUILD)
clean-dist: ## remove build directory
rm -rf $(DIST)
clean-tmp: ## remove temporary directory
rm -rf $(TMP)
docker-shim: ## pull docker image for building lambdas
docker pull eawsy/aws-lambda-go-shim:latest
dte: $(TF)/api.tf ## generate api.tf from downtoearth.json
lambda-arcs: $(LAMBDA_ARCS) ## build all plugins and distribution archives
test: test-unit test-integration ## run all tests
test-unit: ## unit tests
go test ./cmd/... ./lib/... -v -tags unit
test-integration: ## integration tests
@echo "No integration tests to run"
tf-apply: ## apply environment state changes
terraform apply -refresh=true -state=$(TF)/terraform.tfstate $(TF)/
tf-plan: ## show environment state changes
terraform plan -refresh=true -state=$(TF)/terraform.tfstate $(TF)/
$(BUILD)/$(PROJ_NAME): ## build the main program / cli
$(MKDIR) $(call FixPath,$(TMP))
go build -i -v -ldflags=$(LDFLAGS) -o $@
$(DIST)/%.zip: clean-tmp docker-shim ## lambda distribution archive
$(MKDIR) $(call FixPath,$(BUILD)/$*)
$(MKDIR) $(call FixPath, $(DIST))
$(MKDIR) $(call FixPath, $(TMP)/handler)
docker run --rm \
-v $(GOPATH):/go \
-v $(CURDIR):/work \
-w /work \
eawsy/aws-lambda-go-shim:latest make $(TMP)/$*.zip
mv $(TMP)/$*.zip $@
$(TF)/api.tf: ## generate api.tf from downtoearth.json
downtoearth generate terraform/downtoearth.json -c terraform/$(PROJ_NAME)-root.tf
# WARNING: The following targets are expected to be run inside docker.
# DO NOT run directly.
.PRECIOUS: $(BUILD)/%/handler.so
$(BUILD)/%/handler.so:
go build -buildmode=plugin -ldflags='-w -s' -o $@ $(LAMBDA_DIR)/$*/handler.go
@chown $(shell stat -c '%u:%g' .) $@
$(TMP)/%.zip: $(BUILD)/%/handler.so
@cp $< $(TMP)/
@cp /shim/__init__.pyc $(TMP)/handler/__init__.pyc
@cp /shim/proxy.pyc $(TMP)/handler/proxy.pyc
@cp /shim/runtime.so $(TMP)/handler/runtime.so
@find $(TMP)/ -exec touch -t 201302210800 {} +
cd $(TMP) && zip -qrX $(notdir $@) * ; cd $(CURDIR)
@chown -R $(shell stat -c '%u:%g' .) $(TMP)