-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
66 lines (53 loc) · 2.44 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
TARGET_REPO ?= /Users/luke.ogg/Projects/ai-navigator-cluster-info-agent
TOFU_OPTS := -var owner=$(shell whoami) -auto-approve
EC2_INSTANCE_USER ?= ubuntu
ifneq ("$(wildcard $(CURDIR)/inventory)","")
EC2_INSTANCE_HOST ?= $(strip $(shell cat inventory | grep -E "(.*)amazonaws\.com"))
EC2_SSH_KEY ?= $(shell cat inventory | grep -E ".*\.pem" | cut -d "=" -f 2)
endif
SSH_OPTS := -i $(EC2_SSH_KEY) -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -o ServerAliveInterval=3600
RSYNC_OPTS := -rav --delete --exclude .idea --exclude .local --exclude artifacts --exclude pkg/generated --exclude bin -e "ssh $(SSH_OPTS)" $(TARGET_REPO) $(EC2_INSTANCE_USER)@$(EC2_INSTANCE_HOST):~/go/src/github.com/mesosphere
SSH_TUNNEL_PORT := 1337
PORT_FORWARD ?= 8888
# Start one-way synchronization of the $(TARGET_REPO) to the remote host
.PHONY: sync-repo
sync-repo:
# Perform initial sync
rsync $(RSYNC_OPTS)
# Watch for changes and sync
fswatch --one-per-batch --recursive --latency 1 $(TARGET_REPO) | xargs -I{} rsync $(RSYNC_OPTS)
# Create SSH tunnel to the remote instance
.PHONY: tunnel
tunnel:
ssh $(SSH_OPTS) -D $(SSH_TUNNEL_PORT) -f -C -q -N $(EC2_INSTANCE_USER)@$(EC2_INSTANCE_HOST)
.PHONY: dashboard
dashboard: tunnel
dashboard:
@echo Obtaining DKP credentials...
@ssh $(SSH_OPTS) $(EC2_INSTANCE_USER)@$(EC2_INSTANCE_HOST) "kubectl -n kommander get secret dkp-credentials \
-o go-template='{{ \"\n\"}}Username: {{.data.username|base64decode}}{{ \"\n\"}}Password: {{.data.password|base64decode}}{{ \"\n\"}}'"
@echo "---------------------------------------------------"
@echo Launching Kommander Dashboard...
@open $(shell ssh $(SSH_OPTS) $(EC2_INSTANCE_USER)@$(EC2_INSTANCE_HOST) "kubectl -n kommander get svc kommander-traefik \
-o go-template='https://{{with index .status.loadBalancer.ingress 0}}{{or .hostname .ip}}{{end}}/dkp/kommander/dashboard{{ \"\n\"}}'")
# Connect to the remote instance
.PHONY: connect
connect:
ssh $(SSH_OPTS) $(EC2_INSTANCE_USER)@$(EC2_INSTANCE_HOST)
# Create an EC2 instance with tofu
.PHONY: create
create:
tofu init
tofu apply $(TOFU_OPTS)
# Destroy an EC2 instance
.PHONY: destroy
destroy:
tofu destroy $(TOFU_OPTS)
.PHONY: clean
clean:
rm -rf .terraform* *.pem terraform.tfstate*
.PHONY: port-forward
port-forward:
ssh $(SSH_OPTS) -N -L $(PORT_FORWARD):localhost:$(PORT_FORWARD) $(EC2_INSTANCE_USER)@$(EC2_INSTANCE_HOST)
copy-certs:
scp $(SSH_OPTS) ~/.ssh/linux_cloud_dev_ed25519 $(EC2_INSTANCE_USER)@$(EC2_INSTANCE_HOST):~/.ssh/