-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
88 lines (66 loc) · 3.33 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
.PHONY: help clean connect nb init setup start stop status ip name id dns info
.DEFAULT_GOAL := help
include .env
#source: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
clean: ## Cleans the project
-@rm .aws-*
init: courses
init: ## Setup machine to start the courses
setup: init ~/.ssh/aws-key-fast-ai.pem
setup: ## Run initial setup scripts
~/.ssh/aws-key-fast-ai.pem: ## Using
./courses/setup/setup_p2.sh
courses:
@git clone [email protected]:fastai/courses.git
.aws-instance-name:
@if [ "${INAME}" = "" ]; then \
echo "Environment variable INAME not set"; \
exit 1; \
fi
@echo '${INAME}' > $@
.aws-instance-id: .aws-instance-name
@echo `instanceName=$$(cat .aws-instance-name); aws ec2 describe-instances --filters "Name=tag:Name,Values=*$$instanceName*" --query "Reservations[0].Instances[0].InstanceId"` > $@
.aws-instance-ip: .aws-instance-id
@echo `instanceId=$$(cat .aws-instance-id); aws ec2 describe-instances --filters "Name=instance-id,Values=$$instanceId" --query "Reservations[0].Instances[0].PublicIpAddress"` > $@
.aws-instance-dns: .aws-instance-id
@echo `instanceId=$$(cat .aws-instance-id); aws ec2 describe-instances --filters "Name=instance-id,Values=$$instanceId" --query "Reservations[0].Instances[0].PublicDnsName"` > $@
start: .aws-instance-id
start: ## Starts the instance
@instanceId=$$(cat .aws-instance-id); aws ec2 start-instances --instance-ids $$instanceId && aws ec2 wait instance-running --instance-ids $$instanceId
stop: .aws-instance-id
stop: ## Stops the instance
@instanceId=$$(cat .aws-instance-id); aws ec2 stop-instances --instance-ids $$instanceId
status: ## Gets the status of all instances & volumes
@aws ec2 describe-instances --output table \
--filters 'Name=instance-type, Values=p2.xlarge,t2.micro' \
--query 'Reservations[].Instances[].[Tags[?Key==`Name`] | [0].Value, InstanceId, State.Name]'
@aws ec2 describe-volumes --output table \
--filters 'Name=attachment.device, Values=/dev/sda1' \
--query 'Volumes[0].Attachments[].[Device, State, InstanceId]'
id: .aws-instance-id
id: ## Gets the IP of the instance
@instanceId=$$(cat .aws-instance-id); echo "ID is $$instanceId"
ip: .aws-instance-ip
ip: ## Gets the IP of the instance
@instanceIp=$$(cat .aws-instance-ip); echo "IP is $$instanceIp"
name: .aws-instance-name
@instanceName=$$(cat .aws-instance-name); echo "Name is $$instanceName"
dns: .aws-instance-dns
@instanceDNS=$$(cat .aws-instance-dns); echo "DNS is $$instanceDNS"
info: id ip name dns
info: ## Displays the info for the current instance
connect: .aws-instance-ip
connect: ## SSH into the instance
@instanceIp=$$(cat .aws-instance-ip); ssh -i ~/.ssh/aws-key-fast-ai.pem ubuntu@$$instanceIp
nb: .aws-instance-dns
nb: ## Open a browser to the notebook running in the instance
@instanceDNS=$$(cat .aws-instance-dns); open -a "Google Chrome" "http://$$instanceDNS:$(NB_PORT)"
@echo 'Password is dl_course'
run-nb: CMD=cd ~/courses/deeplearning1/nbs && jupyter notebook
run-nb: NAME=jup-nb
run-nb: ## Runs the jupyter notebook on the remote instance
@echo "THIS DOES NOT WORK!"
@exit 1
@instanceIp=$$(cat .aws-instance-ip); ssh -n -f -i ~/.ssh/aws-key-fast-ai.pem ubuntu@$$instanceIp "bash -c '$(CMD)' > $(NAME).out 2> $(NAME).err < /dev/null &"