Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 104-vulnerabilities-api
Browse files Browse the repository at this point in the history
  • Loading branch information
pombredanne committed Dec 7, 2024
2 parents 72f693f + 8312190 commit f9e010f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
53 changes: 41 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,30 @@ PYTHON_EXE=python3.12
VENV_LOCATION=.venv
ACTIVATE?=. ${VENV_LOCATION}/bin/activate;
MANAGE=${VENV_LOCATION}/bin/python manage.py
# Do not depend on Python to generate the SECRET_KEY
GET_SECRET_KEY=`head -c50 /dev/urandom | base64 | head -c50`
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
DOCKER_EXEC=${DOCKER_COMPOSE} eUSERNAMExec
DB_NAME=dejacode_db
DB_USERNAME=dejacode
DB_PASSWORD=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")

# Use sudo for postgres, 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} -m venv ${VENV_LOCATION}
Expand All @@ -42,12 +52,17 @@ 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}
@echo SECRET_KEY=\"${GET_SECRET_KEY}\" > ${ENV_FILE}

envfile_dev: envfile
@echo "-> Update the .env file for development"
@echo DATABASE_PASSWORD=\"dejacode\" >> ${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/
--ignore-path docs/installation_and_sysadmin/ \
--quiet docs/

valid:
@echo "-> Run Ruff format"
Expand All @@ -62,14 +77,17 @@ check:
@${ACTIVATE} ruff format --check
@echo "-> Running ABOUT files validation"
@${ACTIVATE} about check ./thirdparty/
@${ACTIVATE} about check ./data/
@${ACTIVATE} about check ./dje/
@${ACTIVATE} about check ./dejacode_toolkit/
@$(MAKE) doc8

check-deploy:
@echo "-> Check Django deployment settings"
${MANAGE} check --deploy

clean:
@echo "-> Cleaning the Python env"
@echo "-> Clean the Python env"
rm -rf .venv/ .*_cache/ *.egg-info/ build/ dist/
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete

Expand All @@ -94,17 +112,28 @@ migrate:
@echo "-> Apply database migrations"
${MANAGE} migrate

# make postgresdb DB_PASSWORD=YOUR_PASSWORD
upgrade:
@echo "-> Upgrade local git checkout"
@git pull
@$(MAKE) migrate

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
@${SUDO_POSTGRES} createuser --no-createrole --no-superuser --login --inherit --createdb '${DB_USERNAME}' || true
@${SUDO_POSTGRES} 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}
@${SUDO_POSTGRES} dropdb ${DB_NAME} || true
@echo "-> Create ${DB_NAME} database: createdb --owner=${DB_USERNAME} ${POSTGRES_INITDB_ARGS} ${DB_NAME}"
@${SUDO_POSTGRES} createdb --owner=${DB_USERNAME} ${POSTGRES_INITDB_ARGS} ${DB_NAME}
@gunzip < ${DB_INIT_FILE} | psql --username=${DB_USERNAME} ${DB_NAME}
@echo "-> Apply database migrations"
${MANAGE} migrate

postgresdb_clean:
@echo "-> Drop PostgreSQL user and database"
@${SUDO_POSTGRES} dropdb ${DB_NAME} || true
@${SUDO_POSTGRES} dropuser '${DB_USERNAME}' || true

run:
${MANAGE} runserver 8000 --insecure
Expand Down Expand Up @@ -143,4 +172,4 @@ log:
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
.PHONY: virtualenv conf dev envfile envfile_dev check doc8 valid check-deploy clean initdb postgresdb postgresdb_clean migrate upgrade run test docs build psql bash shell log createsuperuser
13 changes: 11 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Supported Platforms

**DejaCode** has been tested and is supported on the following operating systems:

#. **Debian-based** Linux distributions
#. **Debian-based** Linux distributions. It is reported to work well Fedora.
#. **macOS** 10.14 and up

.. warning::
Expand All @@ -183,6 +183,10 @@ Before you install DejaCode, make sure you have the following prerequisites:
#. **Git**: most recent release available at https://git-scm.com/
#. **PostgreSQL**: release 16 or later found at https://www.postgresql.org/ or
https://postgresapp.com/ on macOS
#. **ldap** development libraries to build python-ldap on Linux.
For instance on Debian::

apt-get install -y libldap2-dev libsasl2-dev

.. _system_dependencies:

Expand All @@ -199,7 +203,7 @@ Clone and Configure

#. Create an environment file::

make envfile
make envfile_dev

Database
--------
Expand All @@ -209,6 +213,11 @@ To set up the database user, database, and table, run::

make postgresdb

To entirely delete the database user, database, and tables, run::

make postgresdb_clean


Tests
-----

Expand Down

0 comments on commit f9e010f

Please sign in to comment.