/
Makefile
90 lines (79 loc) · 3.55 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
SHELL = /bin/bash
start-bootstrap-agent-dna:
cd ~/src/holofuel; \
echo "" > bootstrap-agent.output; \
HC_N3H_MODE=REAL \
HC_AGENT=testAgent_bootstrap \
HC_N3H_WORK_DIR=$$( mktemp -d ) \
hc run --networked --logging --port 3000 | tee -a bootstrap-agent.output
start-agent-dna: start-agent-dna-1
start-agent-dna-%:
cd ~/src/holofuel; \
echo "" > agent_$*.output; \
IPC=$$( ( tail +1f bootstrap-agent.output & ) | grep -m 1 "\- ipc\:" \
| sed 's/[[:space:]]*\- ipc:[[:space:]]*\(.*\)/\1/' ); \
P2P=$$( ( tail +1f bootstrap-agent.output & ) | grep -m 1 "\- p2p\:" \
| sed 's/[[:space:]]*\- p2p:[[:space:]]*\[\"\(.*\)".*/\1/' ); \
HC_N3H_MODE=REAL \
HC_AGENT=testAgent_$* \
HC_N3H_WORK_DIR=$$( mktemp -d ) \
HC_N3H_BOOTSTRAP_NODE=$$P2P \
HC_N3H_IPC_URI=$$IPC \
hc run --networked --logging --port "$$(( 3099 + $* ))" | tee -a agent_$*.output
kill-n3h:
kill $$( pgrep -f 'n3h' )
# Start the conductors to access the DNA w/ real keys; ...-agent-0 is the "bootstrap" node
# - Copy the conductor-config.toml to conductor-config-agent-N.toml w/ the appropriate changes
# - If keystore-agent-N.key doesn't exist create a new key and symbolic link to it
# - If we try to start an agent 1,2,..., and there isn't yet an output file for Agent 0, we'll start one.
.PHONY: bootstrap serve-%
bootstrap: serve-0
serve-%: conductor-%.toml
@echo "Starting Holochain w/ config $<..."
RUST_BACKTRACE=full holochain -c $< 2>&1 | tee conductor-$*.out &
sleep 10 # actually, wait for output signalling conductor has started...
@echo " Started Holochain conductor, into conductor-$*.out"
# Create a conductor configuration using an agent # (1, 2, ...) and a keystore-agent-#.key link (which must link to
# a filename ending in the public key, eg.
# $ ls -l keystore-agent-3.key
# lrwxrwxr-x 1 perry staff 125 18 Apr 13:58 keystore-agent-3.key -> /Users/p.../keys/HcSCiGvvwq63Yyqa46H3C8OgioEkyt9ye3UF6J9PmINHuyrpUUh7Oisbfrr49da
#$(MAKE) keystore-%.key conductor-0.out conductor.toml.master
.PRECIOUS: conductor-%.toml
conductor-%.toml: keystore-%.key
@(( $* )) && [ ! -r conductor-0.out ] && $(MAKE) serve-0; \
echo "Creating Holochain conductor config for Agent $*..."; \
AGENT=$*; \
PUBKEY=$$( ls -l $< ); PUBKEY=$${PUBKEY##*/}; \
KEYFILE=$<; \
WSPORT=$$(( 3000 + $* )); \
UIPORT=$$(( 8800 + $* )); \
IPCURI=$$( if (( $* )); then \
sed -n 's/[[:space:]]*\- ipc:[[:space:]]*\(.*\)/\1/p' \
< conductor-0.out; \
fi ); \
BSNODES=$$( if (( $* )); then \
sed -n 's/[[:space:]]*\- p2p:[[:space:]]*\[\([^]]*\)\]/\1/p' \
< conductor-0.out; \
fi ); \
sed -e "s/PUBKEY/$$PUBKEY/g" \
-e "s/KEYFILE/$$KEYFILE/g" \
-e "s/WSPORT/$$WSPORT/g" \
-e "s/UIPORT/$$UIPORT/g" \
-e "s|IPCURI|$$IPCURI|g" \
-e "s|BSNODES|$$BSNODES|g" \
-e "s|AGENT|$$AGENT|g" \
< conductor.toml.master \
> $@; \
echo " Wrote new $@"
# If the target doesn't exist, create a new key. The last segment of the link. Don't delete it, if
# we do had to create one as an intermediate target.
.PRECIOUS: keystore-%.key
keystore-%.key:
@echo -n "Creating Holochain key for Agent $*..."; \
eval $$( hc keygen --nullpass --quiet \
| python -c "import sys; \
print('\n'.join('%s=%s' % ( k, v.strip() ) \
for (k, v) in zip(['KEY','KEYFILE'], sys.stdin.readlines())))" \
); \
echo " $@ -> $$KEYFILE"; \
ln -fs $$KEYFILE $@