generated from nexB/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
167 lines (136 loc) · 5.63 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
#
# 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/nexB/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
# 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:
@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}
@echo SCANCODEIO_DB_PORT=\"5433\" >> ${ENV_FILE}
isort:
@echo "-> Apply isort changes to ensure proper imports ordering"
${VENV}/bin/isort .
black:
@echo "-> Apply black code formatter"
${VENV}/bin/black .
doc8:
@echo "-> Run doc8 validation"
@${ACTIVATE} doc8 --max-line-length 100 --ignore-path docs/_build/ --quiet docs/
valid: isort black
check:
@echo "-> Run pycodestyle (PEP8) validation"
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=venv,lib,thirdparty,docs,migrations,settings.py .
@echo "-> Run isort imports ordering validation"
@${ACTIVATE} isort --check-only .
@echo "-> Run black validation"
@${ACTIVATE} black --check ${BLACK_ARGS}
clean:
@echo "-> Clean the Python env"
@PYTHON_EXECUTABLE=${PYTHON_EXE} ./configure --clean
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:
@echo "-> Run the test suite"
${ACTIVATE} DJANGO_SETTINGS_MODULE=purldb_project.settings ${PYTHON_EXE} -m pytest -vvs --ignore matchcode_pipeline --ignore matchcode_project --ignore purldb-toolkit --ignore packagedb/tests/test_throttling.py
${ACTIVATE} DJANGO_SETTINGS_MODULE=purldb_project.settings ${PYTHON_EXE} -m pytest -vvs packagedb/tests/test_throttling.py
${ACTIVATE} DJANGO_SETTINGS_MODULE=matchcode_project.settings ${PYTHON_EXE} -m pytest -vvs matchcode_pipeline
${ACTIVATE} ${PYTHON_EXE} -m pytest -vvs purldb-toolkit/
${ACTIVATE} DJANGO_SETTINGS_MODULE=purldb_project.settings ${PYTHON_EXE} -m pytest -vvs purl2vcs
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/
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
.PHONY: virtualenv conf dev envfile isort black doc8 valid check clean migrate postgres run test shell clearsync clearindex index_packages bump docs docker-images