forked from ymzkryo/chainpoint-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (147 loc) · 6.32 KB
/
Makefile
File metadata and controls
177 lines (147 loc) · 6.32 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
# First target in the Makefile is the default.
all: help
# without this 'source' won't work.
SHELL := /bin/bash
# Include the `.env` file with variables defined.
# This allows using variables defined in that file
# with the form e.g `echo $(NODE_TNT_ADDRESS)`
# See : https://unix.stackexchange.com/questions/235223/makefile-include-env-file
include .env
export $(shell sed 's/=.*//' .env)
# Get the location of this makefile.
ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# Specify the binary dependencies
REQUIRED_BINS := docker docker-compose
$(foreach bin,$(REQUIRED_BINS),\
$(if $(shell command -v $(bin) 2> /dev/null),$(),$(error Please install `$(bin)` first!)))
.PHONY : help
help : Makefile
@sed -n 's/^##//p' $<
## up : Start Node
.PHONY : up
up: guard-ubuntu ntpd-start tls-generate-cert build-rocksdb fix-keys-dir-perms
@export COMPOSE_IGNORE_ORPHANS=true; docker-compose up -d
## down : Shutdown Node
.PHONY : down
down: ntpd-stop
@export COMPOSE_IGNORE_ORPHANS=true; docker-compose down
## restart : Restart Node
.PHONY : restart
restart:
@export COMPOSE_IGNORE_ORPHANS=true; docker-compose restart chainpoint-node
## logs : Tail Node logs
.PHONY : logs
logs:
@docker-compose logs -f -t | awk '/chainpoint-node/ && !(/DEBUG/ || /failed with exit code 99/ || /node server\.js/ || /yarnpkg\.com/)'
## logs-ntpd : Tail ntpd logs
.PHONY : logs-ntpd
logs-ntpd:
@docker-compose -f docker-compose-ntpd.yaml logs -f -t | awk '/chainpoint-ntpd/'
## ps : View running processes
.PHONY : ps
ps:
@docker-compose ps
ip:
@echo $(CHAINPOINT_NODE_PUBLIC_URI)
@echo $(CHAINPOINT_NODE_PUBLIC_URI) | \
awk -F[/:] '{print $$4}'
## tls-generate-cert : Create new self-signed TLS certificate
.PHONY : tls-generate-cert
tls-generate-cert:
@[ ! -f ./cert.key ] && \
./certgen.sh 127.0.0.1 && \
echo 'TLS certificate generated' || true
## tls-regenerate-cert : Recreate new self-signed TLS certificate (replaces existing)
.PHONY : tls-regenerate-cert
tls-regenerate-cert:
@./certgen.sh 127.0.0.1 && \
echo 'TLS certificate regenerated' || true
## build-config : Create new `.env` config file from `.env.sample`
.PHONY : build-config
build-config:
@[ ! -f ./.env ] && \
cp .env.sample .env && \
echo 'Copied config .env.sample to .env' || true
## fix-keys-dir-perms : Fix key dir permissions to allow Docker container to backup
.PHONY : fix-keys-dir-perms
fix-keys-dir-perms:
@sudo chown -R root keys && sudo chmod 777 keys && sudo chmod 777 keys/backups
## git-fetch : Git fetch latest
.PHONY : git-fetch
git-fetch:
git fetch && git checkout master && git pull
## upgrade : Stop Node, git pull, upgrade docker-compose, and start Node
.PHONY : upgrade
upgrade: down git-fetch fix-keys-dir-perms clear-containers guard-ubuntu upgrade-docker-compose up
guard-ubuntu:
@os=$$(lsb_release -si); \
if [ "$${os}" != "Ubuntu" ]; then \
echo "*********************************************************"; \
echo "WARNING : Unsupported OS. Ubuntu 16.04 LTS is supported."; \
echo "*********************************************************"; \
fi
# clear-containers : Stop and remove any running Chainpoint Docker containers
.PHONY : clear-containers
clear-containers:
@-containers=$$(docker ps -aq -f "label=org.chainpoint.service"); \
if [ "$${containers}" != "" ]; then \
echo "flushing docker containers..."; \
docker stop $${containers}; \
docker rm $${containers}; \
fi
## upgrade-docker-compose : Upgrade local docker-compose installation
.PHONY : upgrade-docker-compose
upgrade-docker-compose:
@sudo mkdir -p /usr/local/bin; \
curl -sSL https://chainpoint-node.storage.googleapis.com/docker-compose-install.sh | bash
## print-auth-keys : Print to console the filename and contents of auth key (HMAC) backups
.PHONY : print-auth-keys
print-auth-keys: up
@docker exec -it chainpoint-node node auth-keys-print.js
.PHONY : sign-chainpoint-security-txt
sign-chainpoint-security-txt:
gpg --armor --output chainpoint-security.txt.sig --detach-sig chainpoint-security.txt
## ntpd-start : Start docker ntpd
.PHONY : ntpd-start
ntpd-start:
@status=$$(ps -ef | grep -v -E '(grep|ntpd-start)' | grep -E '(ntpd|timesyncd|timed|pacemaker)' | wc -l); \
if test $${status} -ge 1; then \
echo "Local time sync daemon seems to be running. Skipping chainpoint-ntpd..."; \
else \
echo "Local time sync daemon does not appear to be running. Starting chainpoint-ntpd.."; \
export COMPOSE_IGNORE_ORPHANS=true; docker-compose -f docker-compose-ntpd.yaml up -d; \
fi
## ntpd-stop : Stop docker ntpd
.PHONY : ntpd-stop
ntpd-stop:
-@export COMPOSE_IGNORE_ORPHANS=true; docker-compose -f docker-compose-ntpd.yaml down;
## ntpd-status : Show docker ntpd status
.PHONY : ntpd-status
ntpd-status:
@echo ''
@docker exec -it chainpoint-ntpd ntpctl -s all
# private target. Upload the installer shell script to a common location.
.PHONY : upload-installer
upload-installer:
gsutil cp scripts/setup.sh gs://chainpoint-node/setup.sh
gsutil acl ch -u AllUsers:R gs://chainpoint-node/setup.sh
gsutil setmeta -h "Cache-Control:private, max-age=0, no-transform" gs://chainpoint-node/setup.sh
# private target. Upload the docker compose installer shell script to a common location.
.PHONY : upload-docker-compose-installer
upload-docker-compose-installer:
gsutil cp docker-compose-install.sh gs://chainpoint-node/docker-compose-install.sh
gsutil acl ch -u AllUsers:R gs://chainpoint-node/docker-compose-install.sh
gsutil setmeta -h "Cache-Control:private, max-age=0, no-transform" gs://chainpoint-node/docker-compose-install.sh
gsutil cp docker-compose.tar.gz gs://chainpoint-node/docker-compose.tar.gz
gsutil acl ch -u AllUsers:R gs://chainpoint-node/docker-compose.tar.gz
gsutil setmeta -h "Cache-Control:private, max-age=0, no-transform" gs://chainpoint-node/docker-compose.tar.gz
# private target. Ensure the RocksDB data dir exists before
# it gets mounted into the container as a volume.
.PHONY : build-rocksdb
build-rocksdb:
@os=$$(lsb_release -si); \
if [ "$${os}" = "Ubuntu" ]; then \
sudo mkdir -p .data/rocksdb && sudo chown root .data/rocksdb && sudo chmod 777 .data/rocksdb; \
else \
mkdir -p .data/rocksdb && chmod 777 .data/rocksdb; \
fi