-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
130 lines (94 loc) · 4.22 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Run `make` or `make help` command to get help
# Use one shell for all commands in a target recipe
.ONESHELL:
# Commands
.PHONY: help build name list launch mount umount bootstrap up down ssh destroy lint upgrade force-upgrade
# Set default goal
.DEFAULT_GOAL := help
# Use bash shell in Make instead of sh
SHELL := /bin/bash
# Charm variables
CHARM_NAME := prometheus-libvirt-exporter
CHARM_STORE_URL := cs:~huntdatacenter/prometheus-libvirt-exporter
CHARM_HOMEPAGE := https://github.com/huntdatacenter/prometheus-libvirt-exporter-charm/
CHARM_BUGS_URL := https://github.com/huntdatacenter/prometheus-libvirt-exporter-charm/issues
CHARM_BUILD_DIR := /tmp/charm-builds
CHARM_PATH := $(CHARM_BUILD_DIR)/$(CHARM_NAME).charm
# Multipass variables
UBUNTU_VERSION = jammy
MOUNT_TARGET = /home/ubuntu/vagrant
DIR_NAME = "$(shell basename $(shell pwd))"
VM_NAME = juju-dev--$(DIR_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
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)
lint: ## Run linter
tox -e lint
build: ## Build charm
mkdir -p $(CHARM_BUILD_DIR)
tox -e build
cp prometheus-libvirt-exporter_ubuntu-20.04-amd64_ubuntu-22.04-amd64.charm $(CHARM_PATH)
deploy: ## Deploy charm
juju deploy $(CHARM_PATH)
upgrade: ## Upgrade charm
juju upgrade-charm $(CHARM_NAME) --path $(CHARM_PATH)
force-upgrade: ## Force upgrade charm
juju upgrade-charm $(CHARM_NAME) --path $(CHARM_PATH) --force-units
test-xenial-bundle: ## Test Xenial bundle
tox -e test-xenial
test-bionic-bundle: ## Test Bionic bundle
tox -e test-bionic
push: clean build generate-repo-info ## Push charm to stable channel
@echo "Publishing $(CHARM_STORE_URL)"
@export rev=$$(charm push $(CHARM_PATH) $(CHARM_STORE_URL) 2>&1 \
| tee /dev/tty | grep url: | cut -f 2 -d ' ') \
&& charm release --channel stable $$rev \
&& charm grant $$rev --acl read everyone \
&& charm set $$rev extra-info=$$(git rev-parse --short HEAD) \
bugs-url=$(CHARM_BUGS_URL) homepage=$(CHARM_HOMEPAGE)
clean: ## Clean .tox and build
@echo "Cleaning files"
@if [ -d $(CHARM_PATH) ] ; then rm -r $(CHARM_PATH) ; fi
@if [ -d .tox ] ; then rm -r .tox ; fi
# Internal targets
clean-repo:
@if [ -n "$$(git status --porcelain)" ]; then \
echo '!!! Hard resetting repo and removing untracked files !!!'; \
git reset --hard; \
git clean -fdx; \
fi
generate-repo-info:
@if [ -f $(CHARM_PATH)/repo-info ] ; then rm -r $(CHARM_PATH)/repo-info ; fi
@echo "commit: $$(git rev-parse HEAD)" >> $(CHARM_PATH)/repo-info
@echo "commit-short: $$(git rev-parse --short HEAD)" >> $(CHARM_PATH)/repo-info
@echo "branch: $$(git rev-parse --abbrev-ref HEAD)" >> $(CHARM_PATH)/repo-info
@echo "remote: $$(git config --get remote.origin.url)" >> $(CHARM_PATH)/repo-info
@echo "generated: $$(date -u)" >> $(CHARM_PATH)/repo-info
# 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)