forked from ansible/galaxy_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
303 lines (238 loc) · 11.5 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
.SILENT:
DOCKER_IMAGE_NAME = localhost/galaxy_ng/galaxy_ng
RUNNING = $(shell docker ps -q -f name=api)
# if running is empty, then DJ_MANAGER = manage, else DJ_MANAGER = django-admin
DJ_MANAGER = $(shell if [ "$(RUNNING)" = "" ]; then echo manage; else echo django-admin; fi)
# set the OCI_ENV_PATH to be ../oci_env/ if this isn't set in the user's environment
export OCI_ENV_PATH = $(shell if [ -n "$$OCI_ENV_PATH" ]; then echo "$$OCI_ENV_PATH"; else echo ${PWD}/../oci_env/; fi)
define exec_or_run
# Tries to run on existing container if it exists, otherwise starts a new one.
@echo $(1)$(2)$(3)$(4)$(5)$(6)
@if [ "$(RUNNING)" != "" ]; then \
echo "Running on existing container $(RUNNING)" 1>&2; \
./compose exec $(1) $(2) $(3) $(4) $(5) $(6); \
else \
echo "Starting new container" 1>&2; \
./compose run --use-aliases --service-ports --rm $(1) $(2) $(3) $(4) $(5) $(6); \
fi
endef
.DEFAULT:
.PHONY: help
help: ## Show the help.
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@fgrep "##" Makefile | fgrep -v fgrep | sed 's/^/\n/' | sed 's/#/\n/'
# Update python dependencies lock files (i.e. requirements.*.txt)
.PHONY: requirements/no-pip-upgrade
requirements/no-pip-upgrade: ## Update based on setup.py and *.in files without asking pip for latest version
pip-compile -o requirements/requirements.common.txt setup.py
pip-compile -o requirements/requirements.insights.txt requirements/requirements.insights.in setup.py
pip-compile -o requirements/requirements.standalone.txt requirements/requirements.standalone.in setup.py
.PHONY: requirements/pip-upgrade-single-package
requirements/pip-upgrade-single-package: ## Update based on setup.py and *.in files, and parameter via pip, i.e. package=djangorestframework
pip-compile -o requirements/requirements.common.txt setup.py --upgrade-package $(package)
pip-compile -o requirements/requirements.insights.txt requirements/requirements.insights.in setup.py --upgrade-package $(package)
pip-compile -o requirements/requirements.standalone.txt requirements/requirements.standalone.in setup.py --upgrade-package $(package)
.PHONY: requirements/pip-upgrade-all
requirements/pip-upgrade-all: ## Update based on setup.py and *.in files, and all packages via pip
pip-compile -o requirements/requirements.common.txt setup.py --upgrade
pip-compile -o requirements/requirements.insights.txt setup.py requirements/requirements.insights.in --upgrade
pip-compile -o requirements/requirements.standalone.txt setup.py requirements/requirements.standalone.in --upgrade
.PHONY: pulp/plugin-template-check
pulp/plugin-template-check:
./dev/common/check_pulp_template.sh
.PHONY: pulp/run-plugin-template-script
pulp/run-plugin-template-script:
echo "Running plugin_template script in sibling directory"
cd ../plugin_template/ && ./plugin-template --github galaxy_ng
# Repository management
.PHONY: changelog
changelog: ## Build the changelog
towncrier build
.PHONY: lint
lint: ## Lint the code
check-manifest
flake8 --config flake8.cfg
.PHONY: fmt
fmt: ## Format the code using Darker
@echo "Formatting code using darker, just like black, but only on changed regions of files."
darker
# Container environment management
.PHONY: docker/prune
docker/prune: ## Clean all development images and volumes
@docker system prune --all --volumes
.PHONY: docker/build
docker/build: ## Build all development images.
./compose build
.PHONY: docker/test/unit
docker/test/unit: ## Run unit tests with option TEST param otherwise run all, ex: TEST=.api.test_api_ui_sync_config
$(call exec_or_run, api, $(DJ_MANAGER), test, galaxy_ng.tests.unit$(TEST))
.PHONY: docker/test/integration
docker/test/integration: ## Run integration tests with optional MARK param otherwise run all, ex: MARK=galaxyapi_smoke
if [ "$(shell docker exec -it galaxy_ng_api_1 env | grep PULP_GALAXY_REQUIRE_CONTENT_APPROVAL)" != "PULP_GALAXY_REQUIRE_CONTENT_APPROVAL=true" ]; then\
echo "The integration tests will not run correctly unless you set PULP_GALAXY_REQUIRE_CONTENT_APPROVAL=true";\
exit 1;\
fi
if [ "$(MARK)" ]; then\
HUB_LOCAL=1 ./dev/standalone/RUN_INTEGRATION.sh "-m $(MARK)";\
else\
HUB_LOCAL=1 ./dev/standalone/RUN_INTEGRATION.sh;\
fi
.PHONY: docker/test/integration/container
docker/test/integration/container: ## Run integration tests.
docker build . -f dev/standalone/integration-test-dockerfile -t galaxy-integration-runner
docker run -it --rm --add-host=localhost:host-gateway galaxy-integration-runner $(FLAGS)
.PHONY: oci-env/integration
oci-env/integration:
oci-env exec bash /src/galaxy_ng/profiles/base/run_integration.sh $(FLAGS)
.PHONY: gh-action/ldap
gh-action/ldap:
python3 dev/oci_env_integration/actions/ldap.py
.PHONY: gh-action/x_repo_search
gh-action/x_repo_search:
python3 dev/oci_env_integration/actions/x_repo_search.py
.PHONY: gh-action/iqe_rbac
gh-action/iqe_rbac:
python3 dev/oci_env_integration/actions/iqe_rbac.py
.PHONY: gh-action/keycloak
gh-action/keycloak:
python3 dev/oci_env_integration/actions/keycloak.py
.PHONY: gh-action/rbac
gh-action/rbac:
python3 dev/oci_env_integration/actions/rbac.py
.PHONY: gh-action/insights
gh-action/insights:
python3 dev/oci_env_integration/actions/insights.py
.PHONY: gh-action/standalone
gh-action/standalone:
python3 dev/oci_env_integration/actions/standalone.py
.PHONY: gh-action/community
gh-action/community:
python3 dev/oci_env_integration/actions/community.py
.PHONY: gh-action/certified-sync
gh-action/certified-sync:
python3 dev/oci_env_integration/actions/certified-sync.py
.PHONY: docker/loaddata
docker/loaddata: ## Load initial data from python script
$(call exec_or_run, api, "/bin/bash", "-c", "/entrypoint.sh manage shell < app/dev/common/setup_test_data.py")
.PHONY: docker/makemigrations
docker/makemigrations: ## Run django migrations
$(call exec_or_run, api, $(DJ_MANAGER), makemigrations)
.PHONY: docker/migrate
docker/migrate: ## Run django migrations
$(call exec_or_run, api, $(DJ_MANAGER), migrate)
.PHONY: docker/add-signing-service
docker/add-signing-service: ## Add a Signing service using default GPG key
$(call exec_or_run, worker, $(DJ_MANAGER), add-signing-service, ansible-default, /var/lib/pulp/scripts/collection_sign.sh, [email protected])
.PHONY: docker/resetdb
docker/resetdb: ## Cleans database
# Databases must be stopped to be able to reset them.
./compose down
./compose stop
./compose run --rm api /bin/bash -c "yes yes | ./entrypoint.sh manage reset_db && django-admin migrate"
.PHONY: docker/db_snapshot
NAME ?= galaxy
docker/db_snapshot: ## Snapshot database with optional NAME param. Example: make docker/db_snapshot NAME=my_special_backup
docker exec galaxy_ng_postgres_1 pg_dump -U galaxy_ng -F c -b -f "/galaxy.backup" galaxy_ng
mkdir -p db_snapshots/
docker cp galaxy_ng_postgres_1:/galaxy.backup db_snapshots/$(NAME).backup
.PHONY: docker/db_restore
NAME ?= galaxy
docker/db_restore: ## Restore database from a snapshot with optional NAME param. Example: make docker/db_restore NAME=my_special_backup
docker cp db_snapshots/$(NAME).backup galaxy_ng_postgres_1:/galaxy.backup
docker exec galaxy_ng_postgres_1 pg_restore --clean -U galaxy_ng -d galaxy_ng "/galaxy.backup"
.PHONY: docker/translations
docker/translations: ## Generate the translation messages
$(call exec_or_run, api, "/bin/bash", "-c", "cd /app/galaxy_ng && /entrypoint.sh manage makemessages --all")
.PHONY: docker/all
docker/all: ## Build, migrate, loaddata, translate and add test collections.
make docker/build
make docker/migrate
make docker/loaddata
make docker/translations
# Application management and debugging
# e.g: make api/get URL=/content/community/v3/collections/
.PHONY: api/get
api/get: ## Make an api get request using 'httpie'
# Makes 2 requests: One to get the token and another to request given URL
http --version && (http :8002/api/automation-hub/$(URL) "Authorization: Token $$(http --session DEV_SESSION --auth admin:admin -v POST 'http://localhost:5001/api/automation-hub/v3/auth/token/' username=admin password=admin -b | jq -r '.token')" || echo "http error, check if api is running.") || echo "!!! this command requires httpie - please run 'pip install httpie'"
.PHONY: api/shell
api/shell: ## Opens django management shell in api container
$(call exec_or_run, api, $(DJ_MANAGER), shell_plus)
.PHONY: api/bash
api/bash: ## Opens bash session in the api container
$(call exec_or_run, api, /bin/bash)
.PHONY: api/runserver
api/runserver: ## Runs api using django webserver for debugging
# Stop all running containers if any
./compose stop
# Start only services if containers exists, else create the containers and start.
./compose start worker content-app ui || ./compose up -d worker content-app ui
# ensure API is not running
./compose stop api
# Run api using django runserver for debugging
./compose run --service-ports --use-aliases --name api --rm api manage runserver 0.0.0.0:8000
.PHONY: api/routes
api/routes: ## Prints all available routes
$(call exec_or_run, api, $(DJ_MANAGER), show_urls)
.EXPORT_ALL_VARIABLES:
.ONESHELL:
.PHONY: api/create-test-collections
api/create-test-collections: ## Creates a set of test collections
@read -p "How many namespaces to create? : " NS; \
read -p "Number of collections on each namespace? : " COLS; \
read -p "Add a prefix? : " PREFIX; \
ARGS="--prefix=$${PREFIX:-dev} --strategy=$${STRATEGY:-faux} --ns=$${NS:-6} --cols=$${COLS:-6}"; \
echo "Creating test collections with args: $${ARGS}"; \
export ARGS; \
./compose exec api django-admin create-test-collections $${ARGS}
.PHONY: api/push-test-images
api/push-test-images: ## Pushes a set of test container images
docker login -u admin -p admin localhost:5001 || echo "!!! docker login failed, check if docker is running"
for foo in postgres treafik mongo mariadb redis node mysql busybox alpine docker python hhtpd nginx memcached golang; do docker pull $$foo; docker image tag $$foo localhost:5001/$$foo:latest; docker push localhost:5001/$$foo:latest; done
.PHONY: api/list-permissions
api/list-permissions: ## List all permissions - CONTAINS=str
$(call exec_or_run, api, $(DJ_MANAGER), shell -c 'from django.contrib.auth.models import Permission;from pprint import pprint;pprint([f"{perm.content_type.app_label}:{perm.codename}" for perm in Permission.objects.filter(name__icontains="$(CONTAINS)")])')
# Version / bumpversion management
# 'bumpversion path' to go from 4.1.0 -> 4.1.1
dev/bumpversion-patch:
bump2version --verbose patch
# 'bumpversion minor' to go from 4.1.1 -> 4.2.0
dev/bumpversion-minor:
bump2version --verbose minor
# 'bumpversion major' to go from 4.2.9 -> 5.0.0
dev/bumpversion-major:
bump2version --verbose major
# 'bumpversion build' to go from 5.3.7.a1 -> 5.3.7.a2
dev/bumpversion-build:
bump2version --verbose build
# 'bumpversion release' to from 5.3.7.a1 -> 5.3.7.b1
# another 'bumpversion release' to from from 5.3.7.b1 -> 5.3.7
dev/bumpversion-release:
bump2version --verbose release
docs/install:
@pip install -r docs_requirements.txt
@pip install -U 'Jinja2==3.0.1'
docs/build:
@mkdocs build --clean
docs/serve:
@mkdocs serve
#########################################################
# Simple stack spinup ... please don't overengineer this
#########################################################
.PHONY: oci/standalone
oci/standalone:
dev/oci_start standalone
.PHONY: oci/insights
oci/insights:
dev/oci_start insights
.PHONY: oci/keycloak
oci/keycloak:
dev/oci_start keycloak
.PHONY: oci/ldap
oci/ldap:
dev/oci_start ldap
.PHONY: oci/community
oci/community:
dev/oci_start community