-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
153 lines (114 loc) · 5.15 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
REMOTE ?= origin
APSTRA_COLLECTION_ROOT := ansible_collections/juniper/apstra
VERSION := $(shell sed -n '/^version: / s,.*"\(.*\)"$$,\1,p' $(APSTRA_COLLECTION_ROOT)/galaxy.yml)
APSTRA_COLLECTION := $(APSTRA_COLLECTION_ROOT)/juniper-apstra-$(VERSION).tar.gz
# Get all .py files in the APSTRA_COLLECTION_ROOT directory
PY_FILES := $(shell find $(APSTRA_COLLECTION_ROOT) -name *.py)
PY_VERSION := $(shell cat .python-version)
APSTRA_COLLECTION = juniper-apstra-$(VERSION).tar.gz
.PHONY: setup build release-build install clean clean-pipenv pipenv docs tag image
# OS-specific settings
OS := $(shell uname -s)
ifeq ($(OS),Darwin)
PYENV_INSTALL_PREFIX := PYTHON_CONFIGURE_OPTS=--enable-framework
endif
# By default use .venv in the current directory
export PIPENV_VENV_IN_PROJECT=1
# Needed for antsi-build doc build
CERT_PATH = $(shell python -m certifi 2>/dev/null)
export SSL_CERT_FILE=$(CERT_PATH)
export REQUESTS_CA_BUNDLE=$(CERT_PATH)
setup: clean-pipenv
pyenv uninstall --force $(PY_VERSION)
rm -rf $(HOME)/.pyenv/versions/$(PY_VERSION)
$(PYENV_INSTALL_PREFIX) pyenv install --force $(PY_VERSION)
$(MAKE) pipenv
define install_collection_if_missing
pipenv run ansible-doc $(1) &>/dev/null || pipenv run ansible-galaxy collection install --ignore-certs --force $(1)
endef
pipenv: build/wheels/aos_sdk-0.1.0-py3-none-any.whl
(pip install pipenv pre-commit && \
pre-commit install && \
pipenv install --dev)
build/wheels:
mkdir -p build/wheels
build/wheels/aos_sdk-0.1.0-py3-none-any.whl: build/wheels
# If this fails, download the wheel from juniper.net to the wheels directory...
(test -r "$@" && touch "$@") || curl -fso "$@" https://s-artifactory.juniper.net:443/artifactory/atom-generic/aos_sdk_5.1.0/aos_sdk-0.1.0-py3-none-any.whl 2>/dev/null
tag:
git tag -a $(VERSION) -m "Release $(VERSION)"
git push $(REMOTE) $(VERSION)
git push --tags
image: build
mkdir -p build/collections
rm -f build/collections/juniper-apstra.tar.gz
cp "$(APSTRA_COLLECTION)" build/collections/juniper-apstra.tar.gz
TAG=$(VERSION) pipenv run build/build_image.sh
release-build: docs
make build
build: $(APSTRA_COLLECTION_ROOT)/.apstra-collection
APSTRA_COLLECTION_DOCS_BUILD := ansible_collections/juniper/apstra/_build
docs: pipenv install
rm -rf "$(APSTRA_COLLECTION_DOCS_BUILD)" "$(APSTRA_COLLECTION_ROOT)/.apstra-collection"
mkdir -p $(APSTRA_COLLECTION_ROOT)/_build
chmod og-rwx $(APSTRA_COLLECTION_ROOT)/_build
pipenv run antsibull-docs sphinx-init \
--dest-dir $(APSTRA_COLLECTION_DOCS_BUILD) \
--no-indexes \
--no-add-antsibull-docs-version \
--output-format simplified-rst \
--use-current \
--squash-hierarchy \
--lenient \
--project "Juniper Network Apstra Ansible Collection" \
--copyright "Juniper Networks, Inc." \
--title "Apstra Ansible Collection" \
--title "Apstra Ansible Collection" \
juniper.apstra
pipenv run $(APSTRA_COLLECTION_DOCS_BUILD)/build.sh
cp $(APSTRA_COLLECTION_DOCS_BUILD)/rst/*.rst $(APSTRA_COLLECTION_ROOT)/docs/
$(APSTRA_COLLECTION_ROOT)/.apstra-collection: $(APSTRA_COLLECTION_ROOT)/requirements.txt $(APSTRA_COLLECTION_ROOT)/galaxy.yml $(PY_FILES)
rm -f juniper-apstra-*.tar.gz
pipenv run ansible-galaxy collection build $(APSTRA_COLLECTION_ROOT)
touch "$@"
$(APSTRA_COLLECTION_ROOT)/requirements.txt: Pipfile Makefile pipenv
pipenv clean && pipenv requirements --from-pipfile > "$@"
install: build
pipenv run ansible-galaxy collection install --ignore-certs --force $(APSTRA_COLLECTION)
.PHONY: test \
test-apstra_facts \
test-blueprint \
test-virtual_network \
test-routing_policy \
test-security_zone \
test-endpoint_policy \
test-tag \
test-resource_group
# Ignore warnings about localhost from ansible-playbook
export ANSIBLE_LOCALHOST_WARNING=False
export ANSIBLE_INVENTORY_UNPARSED_WARNING=False
ANSIBLE_FLAGS ?= -v
test-apstra_facts: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/apstra_facts.yml
test-blueprint: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/blueprint.yml
test-virtual_network: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/virtual_network.yml
test-routing_policy: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/routing_policy.yml
test-security_zone: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/security_zone.yml
test-endpoint_policy: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/endpoint_policy.yml
test-tag: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/tag.yml
test-resource_group: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) $(APSTRA_COLLECTION_ROOT)/tests/resource_group.yml
test: test-apstra_facts test-blueprint test-virtual_network test-routing_policy test-security_zone test-endpoint_policy test-tag test-resource_group
clean-pipenv:
PIPENV_VENV_IN_PROJECT= pipenv --rm 2>/dev/null || true
rm -rf .venv
clean: clean-pipenv
rm -rf $(APSTRA_COLLECTION_ROOT)/.apstra-collection $(APSTRA_COLLECTION_ROOT)/requirements.txt juniper-apstra-*.tar.gz
demo: install
pipenv run ansible-playbook $(ANSIBLE_FLAGS) demo/security_zone.yml