generated from aboutcode-org/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile
179 lines (143 loc) · 6.2 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
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# purldb is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/aboutcode-org/purldb for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
# Python version can be specified with `$ PYTHON_EXE=python3.x make conf`
PYTHON_EXE?=python3
VENV=venv
MANAGE=${VENV}/bin/python manage_purldb.py
MATCHCODE_MANAGE=${VENV}/bin/python manage_matchcode.py
ACTIVATE?=. ${VENV}/bin/activate;
VIRTUALENV_PYZ=../etc/thirdparty/virtualenv.pyz
# Do not depend on Python to generate the SECRET_KEY
GET_SECRET_KEY=`base64 /dev/urandom | head -c50`
# Customize with `$ make envfile ENV_FILE=/etc/purldb/.env`
ENV_FILE=.env
# Customize with `$ make postgres PACKAGEDB_DB_PASSWORD=YOUR_PASSWORD`
PACKAGEDB_DB_PASSWORD=packagedb
MATCHCODEIO_DB_PASSWORD=matchcodeio
SCANCODEIO_DB_PASSWORD=scancodeio
# Django settings shortcuts
DJSM_PDB=DJANGO_SETTINGS_MODULE=purldb_project.settings
DJSM_MAT=DJANGO_SETTINGS_MODULE=matchcode_project.settings
# Use sudo for postgres, but only on Linux
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
SUDO_POSTGRES=sudo -u postgres
else
SUDO_POSTGRES=
endif
virtualenv:
@echo "-> Bootstrap the virtualenv with PYTHON_EXE=${PYTHON_EXE}"
@${PYTHON_EXE} ${VIRTUALENV_PYZ} --never-download --no-periodic-update ${VENV}
conf:
@echo "-> Install dependencies"
@PYTHON_EXECUTABLE=${PYTHON_EXE} ./configure
dev:
@echo "-> Configure and install development dependencies"
@PYTHON_EXECUTABLE=${PYTHON_EXE} ./configure --dev
@echo "-> Configure and install documentation dependencies"
@PYTHON_EXECUTABLE=${PYTHON_EXE} ./configure --docs
envfile:
@echo "-> Create the .env file and generate a secret key"
@if test -f ${ENV_FILE}; then echo ".env file exists already"; exit 1; fi
@mkdir -p $(shell dirname ${ENV_FILE}) && touch ${ENV_FILE}
@echo SECRET_KEY=\"${GET_SECRET_KEY}\" > ${ENV_FILE}
envfile_testing: envfile
@echo PACKAGEDB_DB_USER=\"postgres\" >> ${ENV_FILE}
@echo PACKAGEDB_DB_PASSWORD=\"postgres\" >> ${ENV_FILE}
@echo SCANCODEIO_DB_USER=\"postgres\" >> ${ENV_FILE}
@echo SCANCODEIO_DB_PASSWORD=\"postgres\" >> ${ENV_FILE}
valid:
@echo "-> Run Ruff format"
@${ACTIVATE} ruff format --exclude etc/scripts/ --exclude purldb-toolkit/ --exclude purl2vcs/
@echo "-> Run Ruff linter"
@${ACTIVATE} ruff check --fix --exclude etc/scripts/ --exclude purldb-toolkit/ --exclude purl2vcs/
check: check_docs
@echo "-> Run Ruff linter validation (pycodestyle, bandit, isort, and more)"
@${ACTIVATE} ruff check --exclude etc/scripts/ --exclude purldb-toolkit/ --exclude purl2vcs/
@echo "-> Run Ruff format validation"
@${ACTIVATE} ruff format --check --exclude etc/scripts/ --exclude purldb-toolkit/ --exclude purl2vcs/
clean:
@echo "-> Clean the Python env"
@PYTHON_EXECUTABLE=${PYTHON_EXE} ./configure --clean
rm -rf .venv/ .*cache/ *.egg-info/ build/ dist/
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
migrate:
@echo "-> Apply database migrations"
${MANAGE} migrate
postgres:
@echo "-> Configure PostgreSQL database"
@echo "-> Create database user 'packagedb'"
${SUDO_POSTGRES} createuser --no-createrole --no-superuser --login --inherit --createdb packagedb || true
${SUDO_POSTGRES} psql -c "alter user packagedb with encrypted password '${PACKAGEDB_DB_PASSWORD}';" || true
@echo "-> Drop 'packagedb' database"
${SUDO_POSTGRES} dropdb packagedb || true
@echo "-> Create 'packagedb' database"
${SUDO_POSTGRES} createdb --encoding=utf-8 --owner=packagedb packagedb
@$(MAKE) migrate
postgres_matchcodeio:
@echo "-> Configure PostgreSQL database"
@echo "-> Create database user 'matchcodeio'"
${SUDO_POSTGRES} createuser --no-createrole --no-superuser --login --inherit --createdb matchcodeio || true
${SUDO_POSTGRES} psql -c "alter user matchcodeio with encrypted password '${MATCHCODEIO_DB_PASSWORD}';" || true
@echo "-> Drop 'matchcodeio' database"
${SUDO_POSTGRES} dropdb matchcodeio || true
@echo "-> Create 'matchcodeio' database"
${SUDO_POSTGRES} createdb --encoding=utf-8 --owner=matchcodeio matchcodeio
${MATCHCODE_MANAGE} migrate
run:
${MANAGE} runserver 8001 --insecure
run_matchcodeio:
${MATCHCODE_MANAGE} runserver 8002 --insecure
seed:
${MANAGE} seed
run_visit: seed
${MANAGE} run_visit --ignore-robots --ignore-throttle
run_map:
${MANAGE} run_map
test_purldb:
${ACTIVATE} ${DJSM_PDB} pytest -vvs --lf minecode packagedb purl2vcs purldb_project purldb_public_project --ignore packagedb/tests/test_throttling.py
${ACTIVATE} ${DJSM_PDB} pytest -vvs --lf packagedb/tests/test_throttling.py
test_toolkit:
${ACTIVATE} pytest -vvs purldb-toolkit/
test_clearcode:
${ACTIVATE} ${DJSM_PDB} ${PYTHON_EXE} -m pytest -vvs clearcode clearindex
test_matchcode:
${ACTIVATE} ${DJSM_MAT} ${PYTHON_EXE} -m pytest -vvs matchcode_pipeline matchcode-toolkit matchcode
test: test_purldb test_matchcode test_toolkit test_clearcode
shell:
${MANAGE} shell
clearsync:
${MANAGE} clearsync --save-to-db --verbose -n 3
clearindex:
${MANAGE} run_clearindex
index_packages:
${MANAGE} index_packages
priority_queue:
${MANAGE} priority_queue
bump:
@echo "-> Bump the version"
bin/bumpver update --no-fetch --patch
docs:
rm -rf docs/_build/
@${ACTIVATE} sphinx-build docs/source docs/_build/
check_docs:
@echo "Check Sphinx Documentation build minimally"
@${ACTIVATE} sphinx-build -E -W docs/source build
@echo "Check for documentation style errors"
@${ACTIVATE} doc8 --max-line-length 100 docs/source --ignore-path docs/_build/ --ignore D000 --quiet
docker-images:
@echo "-> Build Docker services"
docker-compose build
@echo "-> Pull service images"
docker-compose pull
@echo "-> Save the service images to a compressed tar archive in the dist/ directory"
@mkdir -p dist/
@docker save minecode minecode_minecode nginx | gzip > dist/minecode-images-`git describe --tags`.tar.gz
# keep this sorted
.PHONY: black bump check check_docs clean `clearindex clearsync conf dev docker-images docs envfile envfile_testing index_packages isort migrate postgres postgres_matchcodeio priority_queue run run_map run_matchcodeio run_visit seed shell test test_clearcode test_matchcode test_purldb test_toolkit valid virtualenv