addons-server/Makefile-docker

307 строки
9.6 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/
NUM_ADDONS=10
NUM_THEMES=$(NUM_ADDONS)
NPM_ARGS :=
ifneq ($(NPM_CONFIG_PREFIX),)
NPM_ARGS := --prefix $(NPM_CONFIG_PREFIX)
endif
ifneq ($(NPM_CACHE_DIR),)
NPM_ARGS := $(NPM_ARGS) --cache $(NPM_CACHE_DIR)
endif
ifneq ($(NPM_DEBUG),)
NPM_ARGS := $(NPM_ARGS) --loglevel verbose
endif
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
.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
check: check_files check_olympia_user check_debian_packages check_pip_packages check_django
.PHONY: initialize_db
2019-08-29 16:34:26 +03:00
initialize_db: ## create a new database
rm -rf ./user-media/* ./tmp/*
$(PYTHON_COMMAND) manage.py create_db --force
$(PYTHON_COMMAND) manage.py migrate --noinput
$(PYTHON_COMMAND) manage.py loaddata initial.json
$(PYTHON_COMMAND) manage.py import_prod_versions
# The superuser needs to have a mozilla.com address for admin tools access
$(PYTHON_COMMAND) manage.py createsuperuser \
--no-input \
--username "local_admin" \
--email "local_admin@mozilla.com"
$(PYTHON_COMMAND) manage.py loaddata zadmin/users
.PHONY: reindex_data
reindex_data: ## reindex the data in elasticsearch
$(PYTHON_COMMAND) manage.py reindex --force --noinput
.PHONY: populate_data
2019-08-29 16:34:26 +03:00
populate_data: ## populate a new database
# reindex --wipe will force the ES mapping to be re-installed. Useful to
# make sure the mapping is correct before adding a bunch of add-ons.
$(PYTHON_COMMAND) manage.py reindex --wipe --force --noinput
$(PYTHON_COMMAND) manage.py generate_addons --app firefox $(NUM_ADDONS)
$(PYTHON_COMMAND) manage.py generate_addons --app android $(NUM_ADDONS)
$(PYTHON_COMMAND) manage.py generate_themes $(NUM_THEMES)
# These add-ons are specifically useful for the addons-frontend
# homepage. You may have to re-run this, in case the data there
# changes.
$(PYTHON_COMMAND) manage.py generate_default_addons_for_frontend
.PHONY: update_deps_pip
update_deps_pip: ## Install pip
# Work arounds "Multiple .dist-info directories" issue.
rm -rf /deps/build/*
$(PIP_COMMAND) install --progress-bar=off --no-deps --exists-action=w -r requirements/pip.txt
.PHONY: update_deps_development
update_deps_development: ## update the python and node dependencies for development
$(PIP_COMMAND) install --progress-bar=off --no-deps --exists-action=w -r requirements/dev.txt
npm install $(NPM_ARGS) --no-save --include=dev
.PHONY: update_deps_production
update_deps_production: ## update the python and node dependencies for production
$(PIP_COMMAND) install --progress-bar=off --no-deps --exists-action=w -r requirements/prod.txt
npm ci $(NPM_ARGS) --include=prod
.PHONY: update_deps
update_deps: update_deps_pip update_deps_production update_deps_development ## update the python and node dependencies
.PHONY: prune_deps
prune_deps: ## remove unused dependencies
npm prune $(NPM_ARGS) --production
.PHONY: update_db
2019-08-29 16:34:26 +03:00
update_db: ## run the database migrations
$(PYTHON_COMMAND) manage.py migrate --noinput
.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
.PHONY: update
2019-08-29 16:34:26 +03:00
update: update_deps update_db update_assets ## update the dependencies, the database, and assets
.PHONY: reindex
2019-08-29 16:34:26 +03:00
reindex: ## reindex everything in elasticsearch, for AMO
$(PYTHON_COMMAND) manage.py reindex $(ARGS)
.PHONY: setup-ui-tests
setup-ui-tests:
rm -rf ./user-media/* ./tmp/*
# Reset the database and fake database migrations
$(PYTHON_COMMAND) manage.py create_db --force
$(PYTHON_COMMAND) manage.py migrate --noinput
# Reindex
$(PYTHON_COMMAND) manage.py reindex --force --noinput --wipe
# Let's load some initial data and import mozilla-product versions
$(PYTHON_COMMAND) manage.py loaddata initial.json
$(PYTHON_COMMAND) manage.py loaddata zadmin/users
$(PYTHON_COMMAND) manage.py loaddata src/olympia/access/fixtures/initial.json
$(PYTHON_COMMAND) manage.py import_prod_versions
# Create a proper superuser that can be used to access the API
$(PYTHON_COMMAND) manage.py waffle_switch super-create-accounts on --create
$(PYTHON_COMMAND) manage.py waffle_switch activate-autograph-signing on --create
$(PYTHON_COMMAND) manage.py generate_addons --app firefox $(NUM_ADDONS)
$(PYTHON_COMMAND) manage.py generate_addons --app android $(NUM_ADDONS)
$(PYTHON_COMMAND) manage.py generate_themes $(NUM_THEMES)
$(PYTHON_COMMAND) manage.py generate_default_addons_for_frontend
# Now that addons have been generated, reindex.
$(PYTHON_COMMAND) manage.py reindex --force --noinput
.PHONY: perf-tests
perf-tests: setup-ui-tests
$(PIP_COMMAND) install --progress-bar=off --no-deps -r requirements/perftests.txt
locust --no-web -c 1 -f tests/performance/locustfile.py --host "http://olympia.test"
.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
2019-08-29 16:34:26 +03:00
docs: ## build the documentation
$(MAKE) -C docs html SPHINXOPTS='-nW'
.PHONY: djshell
2019-08-29 16:34:26 +03:00
djshell: ## connect to django shell
$(PYTHON_COMMAND) ./manage.py shell_plus
.PHONY: dbshell
2019-08-29 16:34:26 +03:00
dbshell: ## connect to a database shell
$(PYTHON_COMMAND) ./manage.py dbshell
.PHONY: initialize
initialize: update_deps initialize_db update_assets populate_data reindex_data ## init the dependencies, the database, and assets
reload-uwsgi: reload
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
2019-08-29 16:34:26 +03:00
test: ## run the entire test suite
pytest \
$(PYTEST_SRC) \
$(ARGS)
.PHONY: test_es
2019-08-29 16:34:26 +03:00
test_es: ## run the ES tests
pytest \
$(PYTEST_SRC) \
-m es_tests \
$(ARGS)
.PHONY: test_no_es
2019-08-29 16:34:26 +03:00
test_no_es: ## run all but the ES tests
pytest \
$(PYTEST_SRC) \
-m "not es_tests" \
$(ARGS)
.PHONY: test_force_db
2019-08-29 16:34:26 +03:00
test_force_db: ## run the entire test suite with a new database
pytest \
$(PYTEST_SRC) \
--create-db \
$(ARGS)
.PHONY: tdd
2019-08-29 16:34:26 +03:00
tdd: ## run the entire test suite, but stop on the first error
pytest \
$(PYTEST_SRC) \
-x --pdb \
$(ARGS)
.PHONY: test_failed
2019-08-29 16:34:26 +03:00
test_failed: ## rerun the failed tests from the previous run
pytest \
$(PYTEST_SRC) \
--lf \
$(ARGS)
2019-08-29 16:34:26 +03:00
.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
2019-08-29 16:34:26 +03:00
2020-08-03 15:55:07 +03:00
.PHONY: format
format: ## Autoformat our codebase.
NODE_PATH=$(NODE_MODULES) npm exec $(NPM_ARGS) -- prettier --write '**'
ruff check --fix-only .
ruff format .
2020-08-03 15:55:07 +03:00
.PHONY: extract_locales
extract_locales: ## extracts and merges translation strings
./scripts/run_l10n_extraction.sh
.PHONE: compile_locales
compile_locales: ## compiles translation strings
./locale/compile-mo.sh ./locale/
2019-08-29 16:34:26 +03:00
.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}'