-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
146 lines (122 loc) · 4.8 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
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# DejaCode is a trademark of nexB Inc.
# SPDX-License-Identifier: AGPL-3.0-only
# See https://github.com/aboutcode-org/dejacode for support or download.
# See https://aboutcode.org for more information about AboutCode FOSS projects.
#
PYTHON_EXE=python3.12
VENV_LOCATION=.venv
ACTIVATE?=. ${VENV_LOCATION}/bin/activate;
MANAGE=${VENV_LOCATION}/bin/python manage.py
PIP_ARGS=--find-links=./thirdparty/dist/ --no-index --no-cache-dir
GET_SECRET_KEY=`cat /dev/urandom | head -c 50 | base64`
# Customize with `$ make envfile ENV_FILE=/etc/dejacode/.env`
ENV_FILE=.env
DOCS_LOCATION=./docs
DOCKER_COMPOSE=docker compose -f docker-compose.yml
DOCKER_EXEC=${DOCKER_COMPOSE} exec
DB_NAME=dejacode_db
DB_USERNAME=dejacode
DB_CONTAINER_NAME=db
DB_INIT_FILE=./data/postgresql/initdb.sql.gz
POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8
TIMESTAMP=$(shell date +"%Y-%m-%d_%H%M")
virtualenv:
@echo "-> Bootstrap the virtualenv with PYTHON_EXE=${PYTHON_EXE}"
${PYTHON_EXE} -m venv ${VENV_LOCATION}
conf: virtualenv
@echo "-> Install dependencies"
@${ACTIVATE} pip install ${PIP_ARGS} --editable .
@echo "-> Create the var/ directory"
@mkdir -p var
dev: virtualenv
@echo "-> Configure and install development dependencies"
@${ACTIVATE} pip install ${PIP_ARGS} --editable .[dev]
envfile:
@echo "-> Create the .env file and generate a secret key"
@if test -f ${ENV_FILE}; then echo "${ENV_FILE} file exists already"; exit 1; fi
@mkdir -p $(shell dirname ${ENV_FILE}) && touch ${ENV_FILE}
@echo "SECRET_KEY=${GET_SECRET_KEY}" > ${ENV_FILE}
doc8:
@echo "-> Run doc8 validation"
@${ACTIVATE} doc8 --max-line-length 100 --ignore-path docs/_build/ \
--ignore-path docs/installation_and_sysadmin/ --quiet docs/
valid:
@echo "-> Run Ruff format"
@${ACTIVATE} ruff format
@echo "-> Run Ruff linter"
@${ACTIVATE} ruff check --fix
check:
@echo "-> Run Ruff linter validation (pycodestyle, bandit, isort, and more)"
@${ACTIVATE} ruff check
@echo "-> Run Ruff format validation"
@${ACTIVATE} ruff format --check
@echo "-> Running ABOUT files validation"
@${ACTIVATE} about check ./thirdparty/
@$(MAKE) doc8
check-deploy:
@echo "-> Check Django deployment settings"
${MANAGE} check --deploy
clean:
@echo "-> Cleaning the Python env"
rm -rf .venv/ .*_cache/ *.egg-info/ build/ dist/
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
initdb:
@echo "-> Stop Docker services that access the database"
${DOCKER_COMPOSE} stop web worker
@echo "-> Ensure the db Docker service is started"
${DOCKER_COMPOSE} start db
@echo "-> Rename the current ${DB_NAME} database as backup"
${DOCKER_EXEC} --no-TTY ${DB_CONTAINER_NAME} psql --username=${DB_USERNAME} postgres \
--command='ALTER DATABASE ${DB_NAME} RENAME TO "${DB_NAME}_${TIMESTAMP}"'
@echo "-> Create the ${DB_NAME} database"
${DOCKER_EXEC} --no-TTY ${DB_CONTAINER_NAME} \
createdb --username=${DB_USERNAME} --encoding=utf-8 --owner=dejacode ${DB_NAME}
echo "-> Loading initial data"
gunzip < ${DB_INIT_FILE} | ${DOCKER_EXEC} --no-TTY ${DB_CONTAINER_NAME} \
psql --username=${DB_USERNAME} ${DB_NAME}
@echo "Starting Docker services"
${DOCKER_COMPOSE} start
migrate:
@echo "-> Apply database migrations"
${MANAGE} migrate
# make postgresdb DB_PASSWORD=YOUR_PASSWORD
postgresdb:
@echo "-> Configure PostgreSQL database"
@echo "-> Create database user ${DB_NAME}"
@createuser --no-createrole --no-superuser --login --inherit --createdb '${DB_USERNAME}' || true
@psql -c "alter user ${DB_USERNAME} with encrypted password '${DB_PASSWORD}';" || true
@echo "-> Drop ${DB_NAME} database if exists"
@dropdb ${DB_NAME} || true
@echo "-> Create ${DB_NAME} database"
@createdb --owner=${DB_USERNAME} ${POSTGRES_INITDB_ARGS} ${DB_NAME}
@gunzip < ${DB_INIT_FILE} | psql --username=${DB_USERNAME} ${DB_NAME}
run:
${MANAGE} runserver 8000 --insecure
worker:
${MANAGE} rqworker
test:
@echo "-> Run the test suite"
${MANAGE} test --noinput --parallel auto
docs:
@echo "-> Builds the installation_and_sysadmin docs"
rm -rf ${DOCS_LOCATION}/_build/
@${ACTIVATE} pip install -r docs/requirements.txt
@${ACTIVATE} sphinx-build -b singlehtml ${DOCS_LOCATION} ${DOCS_LOCATION}/_build/singlehtml/
@${ACTIVATE} sphinx-build -b html ${DOCS_LOCATION} ${DOCS_LOCATION}/_build/html/
build:
@echo "-> Build the Docker images"
${DOCKER_COMPOSE} build
bash:
${DOCKER_EXEC} web bash
shell:
${DOCKER_EXEC} web ./manage.py shell
psql:
${DOCKER_EXEC} ${DB_CONTAINER_NAME} psql --username=${DB_USERNAME} postgres
# $ make log SERVICE=db
log:
${DOCKER_COMPOSE} logs --tail="100" ${SERVICE}
createsuperuser:
${DOCKER_EXEC} web ./manage.py createsuperuser
.PHONY: virtualenv conf dev envfile check doc8 valid check-deploy clean initdb postgresdb migrate run test docs build psql bash shell log createsuperuser