-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (73 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
89
90
91
92
93
94
95
96
97
98
# Run `make` or `make help` command to get help
# Use one shell for all commands in a target recipe
.ONESHELL:
.EXPORT_ALL_VARIABLES:
.PHONY: help clean rename build deploy list launch mount umount bootstrap up down ssh destroy bridge
# Set default goal
.DEFAULT_GOAL := help
# Use bash shell in Make instead of sh
SHELL := /bin/bash
# Charm variables
CHARM_NAME := ansible.charm
CHARMHUB_NAME := huntdatacenter-ansible
CHARM_STORE_URL := https://charmhub.io/huntdatacenter-charm-ansible
CHARM_HOMEPAGE := https://github.com/huntdatacenter/charm-ansible/
CHARM_BUGS_URL := https://github.com/huntdatacenter/charm-ansible/issues
CHARM_BUILD := ansible_ubuntu-20.04-amd64-arm64_ubuntu-22.04-amd64-arm64_ubuntu-24.04-amd64-arm64.charm
# Multipass variables
UBUNTU_VERSION = jammy
MOUNT_TARGET = /home/ubuntu/vagrant
DIR_NAME = "$(shell basename $(shell pwd))"
VM_NAME = juju-dev--$(DIR_NAME)
clean: ## Remove artifacts
charmcraft clean --verbose
rm -vf $(CHARM_BUILD) $(CHARM_NAME)
$(CHARM_BUILD):
charmcraft pack --verbose
$(CHARM_NAME): $(CHARM_BUILD)
mv -v $(CHARM_BUILD) $(CHARM_NAME)
build: $(CHARM_NAME) ## Build charm
clean-build: $(CHARM_NAME) ## Build charm from scratch
deploy: ## Deploy charm
juju deploy ./$(CHARM_NAME)
login:
bash -c "test -s ~/.charmcraft-auth || charmcraft login --export ~/.charmcraft-auth"
release: login ## Release charm
@echo "# -- Releasing charm: https://charmhub.io/$(CHARMHUB_NAME)"
$(eval CHARMCRAFT_AUTH := $(shell cat ~/.charmcraft-auth))
charmcraft upload --name $(CHARMHUB_NAME) --release latest/stable $(CHARM_NAME)
name: ## Print name of the VM
echo "$(VM_NAME)"
list: ## List existing VMs
multipass list
launch:
multipass launch $(UBUNTU_VERSION) -v --timeout 3600 --name $(VM_NAME) --memory 4G --cpus 4 --disk 20G --cloud-init juju.yaml \
&& multipass exec $(VM_NAME) -- cloud-init status
mount:
echo "Assure allowed in System settings > Privacy > Full disk access for multipassd"
multipass mount --type 'classic' --uid-map $(shell id -u):1000 --gid-map $(shell id -g):1000 $(PWD) $(VM_NAME):$(MOUNT_TARGET)
umount:
multipass umount $(VM_NAME):$(MOUNT_TARGET)
bootstrap:
$(eval ARCH := $(shell multipass exec $(VM_NAME) -- dpkg --print-architecture))
multipass exec $(VM_NAME) -- juju bootstrap localhost lxd --bootstrap-constraints arch=$(ARCH) \
&& multipass exec $(VM_NAME) -- juju add-model default \
&& multipass exec $(VM_NAME) -- juju model-config enable-os-upgrade=false
up: launch mount bootstrap ssh ## Start a VM
fwd: ## Forward app port: make unit=prometheus/0 port=9090 fwd
$(eval VMIP := $(shell multipass exec $(VM_NAME) -- hostname -I | cut -d' ' -f1))
echo "Opening browser: http://$(VMIP):$(port)"
bash -c "(sleep 1; open 'http://$(VMIP):$(port)') &"
multipass exec $(VM_NAME) -- juju ssh $(unit) -N -L 0.0.0.0:$(port):0.0.0.0:$(port)
down: ## Stop the VM
multipass down $(VM_NAME)
ssh: ## Connect into the VM
multipass exec -d $(MOUNT_TARGET) $(VM_NAME) -- bash
destroy: ## Destroy the VM
multipass delete -v --purge $(VM_NAME)
bridge:
sudo route -nv add -net 192.168.64.0/24 -interface bridge100
# Delete if exists: sudo route -nv delete -net 192.168.64.0/24
# Display target comments in 'make help'
help: ## Show this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)