-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (71 loc) · 1.97 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
.PHONY: all echo clean build validate tf-shell create-box delete-box ssh
OS_USER=`whoami`
BOX_IP=`cat .box_ip | cut -f2 -d '"'`
PUBLIC_SSH_KEY=`cat ~/.ssh/id_rsa.pub`
all: clean validate build
echo:
@ echo "OS_USER set to $(OS_USER)"
@ echo "BOX_IP set to $(BOX_IP)"
@ echo "LINODE_TOKEN set to $(LINODE_TOKEN)"
@ echo "PUBLIC_SSH_KEY set to $(PUBLIC_SSH_KEY)"
clean:
if [ -d .terraform ]; then sudo chown -R $(OS_USER):$(OS_USER) .terraform; fi
rm -rf .terraform
rm -f *~ terraform.tfstate* packer-manifest.json .box_ip
docker image prune -f
build:
docker run -it \
-v `pwd`:/var/app \
-v /home/$(OS_USER)/.ssh:/tmp/.ssh \
-w /var/app \
hashicorp/packer:light \
build -force -var "api_token=$(LINODE_TOKEN)" pair-box.pkr.hcl
validate:
docker run -it \
-v `pwd`:/var/app \
-v /home/$(OS_USER)/.ssh:/tmp/.ssh \
-w /var/app \
hashicorp/packer:light \
validate -var "api_token=$(LINODE_TOKEN)" pair-box.pkr.hcl
tf-shell:
docker run -it \
-v `pwd`:/var/app \
-v /home/$(OS_USER)/.ssh:/tmp/.ssh \
-w /var/app \
-e LINODE_TOKEN="$(LINODE_TOKEN)" \
--entrypoint sh \
hashicorp/terraform:1.1.2
create-box: tf-init tf-apply tf-output
tf-init:
docker run -it \
-v `pwd`:/var/app \
-v /home/$(OS_USER)/.ssh:/tmp/.ssh \
-w /var/app \
-e LINODE_TOKEN="$(LINODE_TOKEN)" \
hashicorp/terraform:1.1.2 init
tf-apply:
docker run -it \
-v `pwd`:/var/app \
-v /home/$(OS_USER)/.ssh:/tmp/.ssh \
-w /var/app \
-e LINODE_TOKEN="$(LINODE_TOKEN)" \
hashicorp/terraform:1.1.2 apply -auto-approve \
-var "public_ssh_key=$(PUBLIC_SSH_KEY)"
tf-output:
docker run -it \
-v `pwd`:/var/app \
-v /home/$(OS_USER)/.ssh:/tmp/.ssh \
-w /var/app \
-e LINODE_TOKEN="$(LINODE_TOKEN)" \
hashicorp/terraform:1.1.2 \
output box_ip >.box_ip
delete-box:
docker run -it \
-v `pwd`:/var/app \
-v /home/$(OS_USER)/.ssh:/tmp/.ssh \
-w /var/app \
-e LINODE_TOKEN="$(LINODE_TOKEN)" \
hashicorp/terraform:1.1.2 destroy \
-auto-approve -var "public_ssh_key=x"
ssh:
ssh -A -i ~/.ssh/id_rsa pair@$(BOX_IP)