addons-server/Makefile-docker

220 строки
6.4 KiB
Plaintext

export PYTHON_COMMAND=python3
# As we're using user-local installs inside the docker-container we need
# to be cautious about uprading pip and not confusing it with the
# globally installed version. This will take `$PYTHONUSERBASE` and `$PIP_USER`
# into account.
# See https://github.com/pypa/pip/issues/7205
export PIP_COMMAND=$(PYTHON_COMMAND) -m pip
APP=src/olympia/
NODE_MODULES := $(NPM_CONFIG_PREFIX)node_modules/
REQUIRED_FILES := \
Makefile \
Makefile-os \
Makefile-docker \
/deps/package.json \
/deps/package-lock.json \
/addons-server-docker-container \
.PHONY: help_redirect
help_redirect:
@$(MAKE) help --no-print-directory
.PHONY: check_debian_packages
check_debian_packages: ## check the existence of multiple debian packages
./scripts/check_debian_packages.sh
.PHONY: check_pip_packages
check_pip_packages: ## check the existence of multiple python packages
@ ./scripts/check_pip_packages.sh prod.txt
# "production" corresponds to the "propduction" DOCKER_TARGET defined in the Dockerfile
# When the target is "production" it means we cannot expect dev.txt dependencies to be installed.
@if [ "$(DOCKER_TARGET)" != "production" ]; then \
./scripts/check_pip_packages.sh dev.txt; \
fi
.PHONY: check_files
check_files: ## check the existence of multiple files
@for file in $(REQUIRED_FILES); do test -f "$$file" || (echo "$$file is missing." && exit 1); done
@echo "All required files are present."
.PHONY: check_olympia_user
check_olympia_user: ## check if the olympia user exists and is current user
@if [ "$$(id -u olympia)" != "$$(id -u)" ]; then echo "The current user is not the olympia user."; exit 1; fi
@echo "The current user is the olympia user."
.PHONY: check_django
check_django: ## check if the django app is configured properly
echo 'from olympia.lib.settings_base import *' > settings_local.py
DJANGO_SETTINGS_MODULE='settings_local' python3 ./manage.py check
rm settings_local.py
.PHONY: check_nginx
check_nginx: ## check if the nginx config for local development is configured properly
mkdir -p /data/olympia/storage/shared_storage/uploads
echo "OK" > /data/olympia/storage/shared_storage/uploads/.check
@if [ "$$(curl -sf http://nginx/user-media/.check)" != "OK" ]; then echo "Requesting http://nginx/user-media/.check failed"; exit 1; fi
@echo "Nginx user-media configuration looks correct."
.PHONY: check
check: check_nginx check_files check_olympia_user check_debian_packages check_pip_packages check_django
.PHONY: data_dump
data_dump:
./manage.py data_dump $(ARGS)
.PHONY: data_load
data_load:
./manage.py data_load $(ARGS)
.PHONY: update_assets
update_assets:
# Copy files required in compress_assets to the static folder
# If changing this here, make sure to adapt tests in amo/test_commands.py
$(PYTHON_COMMAND) manage.py compress_assets
$(PYTHON_COMMAND) manage.py generate_jsi18n_files
# Collect static files: This MUST be run last or files will be missing
$(PYTHON_COMMAND) manage.py collectstatic --noinput
# TOOD: remove this after we migrate addons-frontned to not depend on it.
.PHONY: setup-ui-tests
setup-ui-tests:
@echo "This is a deprecated target, please stop using it."
.PHONY: lint
lint: ## lint the code
ruff check .
ruff format --check .
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- prettier --check '**'
curlylint src/
lint-codestyle: lint
.PHONY: docs
docs: ## build the documentation
$(MAKE) -C docs html SPHINXOPTS='-nW'
.PHONY: djshell
djshell: ## connect to django shell
$(PYTHON_COMMAND) ./manage.py shell_plus
.PHONY: dbshell
dbshell: ## connect to a database shell
$(PYTHON_COMMAND) ./manage.py dbshell
.PHONY: initialize
initialize: ## ensure database exists
@echo "Initializing data..."
@echo "args: $(ARGS)"
$(PYTHON_COMMAND) ./manage.py initialize $(ARGS)
PYTEST_SRC := src/olympia/
.PHONY: test_needs_locales_compilation
test_needs_locales_compilation:
pytest $(PYTEST_SRC) \
-m 'needs_locales_compilation' \
$(ARGS)
.PHONY: test_static_assets
test_static_assets: run_js_tests
pytest $(PYTEST_SRC) \
-m 'static_assets' \
$(ARGS)
.PHONY: test_main
test_main:
pytest $(PYTEST_SRC) \
-n auto \
-m 'not es_tests and not needs_locales_compilation and not static_assets and not internal_routes_allowed' \
$(ARGS)
.PHONY: test_internal_routes_allowed
test_internal_routes_allowed:
# We need to change the setting in the file because we can't
# override an env variable here, and the next command requires
# `INTERNAL_ROUTES_ALLOWED` to be set to `True`.
sed -i 's/^INTERNAL_ROUTES_ALLOWED.*/INTERNAL_ROUTES_ALLOWED=True/' settings_test.py
pytest \
$(PYTEST_SRC) \
-m 'internal_routes_allowed' \
$(ARGS)
.PHONY: test_es_tests
test_es_tests:
pytest \
$(PYTEST_SRC) \
-m 'es_tests and not needs_locales_compilation and not static_assets' \
$(ARGS)
.PHONY: test
test: ## run the entire test suite
pytest \
$(PYTEST_SRC) \
$(ARGS)
.PHONY: test_es
test_es: ## run the ES tests
pytest \
$(PYTEST_SRC) \
-m es_tests \
$(ARGS)
.PHONY: test_no_es
test_no_es: ## run all but the ES tests
pytest \
$(PYTEST_SRC) \
-m "not es_tests" \
$(ARGS)
.PHONY: test_force_db
test_force_db: ## run the entire test suite with a new database
pytest \
$(PYTEST_SRC) \
--create-db \
$(ARGS)
.PHONY: tdd
tdd: ## run the entire test suite, but stop on the first error
pytest \
$(PYTEST_SRC) \
-x --pdb \
$(ARGS)
.PHONY: test_failed
test_failed: ## rerun the failed tests from the previous run
pytest \
$(PYTEST_SRC) \
--lf \
$(ARGS)
.PHONY: run_js_tests
run_js_tests: ## Run the JavaScript test suite (requires compiled/compressed assets).
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- jest tests/js
.PHONY: watch_js_tests
watch_js_tests: ## Run+watch the JavaScript test suite (requires compiled/compressed assets).
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- jest --watch
.PHONY: format
format: ## Autoformat our codebase.
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- prettier --write '**'
ruff check --fix-only .
ruff format .
.PHONY: extract_locales
extract_locales: ## extracts and merges translation strings
./scripts/run_l10n_extraction.sh
.PHONE: compile_locales
compile_locales: ## compiles translation strings
$(PIP_COMMAND) install --progress-bar=off --no-deps -r requirements/locale.txt
./locale/compile-mo.sh ./locale/
.PHONY: help_submake
help_submake:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile-docker | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'