-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
146 lines (110 loc) · 3.04 KB
/
Makefile
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
#
# Ecix Whoiscache API Server
#
# This makefile provides scripts for building
# the distribution and creating a .rpm file
#
# The project to build
# When changing this, remember to update your startup scripts
# and other dependent config files.
APP=whoiscache
# Remote RPM building server
BUILD_SERVER=''
### END CONFIGURATION ###
#
# Do not change anything below this line, unless you
# really know what you are doing.
#
APP_VERSION=$(shell cat VERSION)
VERSION=$(APP_VERSION)
# Distribution directory
DIST=BUILD-RPM
REMOTE_DIST=$(APP)-$(DIST)
BUILD_ARCHIVE=.$(APP)-BUILD.tar.gz
APP_DIST=$(DIST)/opt/ecix/$(APP)
LOCAL_RPMS=RPMS
RPM=$(APP)-$(VERSION)-1.noarch.rpm
all: test
echo "Just running some tests"
build_server:
ifeq ($(BUILD_SERVER), '')
$(error BUILD_SERVER not configured)
endif
remote_rpm: build_server $(LOCAL_RPMS)/$(RPM)
dist: clean
# Create dist filesystem
mkdir -p $(DIST)/etc
# Copy configuration and startup
cp -r etc/* $(DIST)/etc/.
# Create app install target
mkdir -p $(APP_DIST)
# Copy app
rsync -av \
--exclude Makefile \
--exclude $(DIST) \
--exclude $(LOCAL_RPMS) \
--exclude venv \
--exclude data \
--exclude *local* \
--exclude *.pid \
--exclude *.swp \
--exclude *.swo \
--exclude *.pyc \
--exclude *.sqlite3 \
* $(APP_DIST)
# Copy deploy scripts
cp -r deploy/* $(DIST)/.
rpm: dist
fpm -s dir -t rpm -n $(APP) -v $(VERSION) -C $(DIST) \
--architecture noarch \
--depends gcc \
--depends python-virtualenv \
--config-files /etc/ecix/python/__init__.py \
--config-files /etc/ecix/python/settings_local_whoiscache.py \
--after-install $(DIST)/after_install \
--before-install $(DIST)/before_install \
etc/ opt/
# Move rpm to target directory
mkdir -p $(LOCAL_RPMS)
mv $(RPM) $(LOCAL_RPMS)/.
#
# BUILD the rpm on the build server
#
$(LOCAL_RPMS)/$(RPM): dist
# Make build archive and copy to server
tar czf $(BUILD_ARCHIVE) $(DIST)/*
scp $(BUILD_ARCHIVE) $(BUILD_SERVER):.
rm $(BUILD_ARCHIVE)
# Unpack distribution build server
ssh $(BUILD_SERVER) -- rm -rf $(REMOTE_DIST)
ssh $(BUILD_SERVER) -- mkdir $(REMOTE_DIST)
ssh $(BUILD_SERVER) -- "cd $(REMOTE_DIST) && tar xzf ../$(BUILD_ARCHIVE)"
# Clean existing rpm on server
ssh $(BUILD_SERVER) -- \
rm -f $(RPM)
ssh $(BUILD_SERVER) -- \
fpm -s dir -t rpm -n $(APP) -v $(VERSION) -C $(REMOTE_DIST)/$(DIST) \
--architecture noarch \
--depends gcc \
--depends python-virtualenv \
--config-files /etc/ecix/python/__init__.py \
--config-files /etc/ecix/python/settings_local_whoiscache.py \
--after-install $(REMOTE_DIST)/$(DIST)/after_install \
--before-install $(REMOTE_DIST)/$(DIST)/before_install \
etc/ opt/
# Get rpm from server
mkdir -p $(LOCAL_RPMS)
scp $(BUILD_SERVER):$(RPM) $(LOCAL_RPMS)/.
test:
pytest -v -s
develop:
bin/venv_init
echo "Now activate the virtualenv by running: source venv/bin/activate"
clean:
find . -name "*.pyc" -exec rm {} \;
find . -name "__pycache__" -exec rm -fr {} \;
rm -f *.pid
rm -rf $(DIST)
tag:
git tag v$(shell cat VERSION)
git push origin v$(shell cat VERSION)