Collection of invoke commands used by Saritasa
Project description
saritasa-invocations
Collection of invoke commands used by Saritasa
Table of contents
- Installation
- Configuration
- Modules
Installation
pip install saritasa-invocations
or if you are using poetry
poetry add saritasa-invocations
Configuration
Configuration can be set in tasks.py
file.
Below is an example of config:
import invoke
import saritasa_invocations
ns = invoke.Collection(
saritasa_invocations.docker,
saritasa_invocations.git,
saritasa_invocations.github_actions,
saritasa_invocations.pre_commit,
saritasa_invocations.system,
)
# For K8S settings you just need to create a instances of K8SSettings for each
# environnement. It'll be all collected automatically.
saritasa_invocations.K8SSettings(
name="dev",
cluster="teleport.company.somewhere.com",
namespace="project_name",
proxy="teleport.company.com",
db_config=saritasa_invocations.K8SDBSettings(
namespace="db",
pod_selector="app=pod-selector-db",
),
)
saritasa_invocations.K8SSettings(
name="prod",
cluster="teleport.client.somewhere.com",
namespace="project_name",
proxy="teleport.client.com",
db_config=saritasa_invocations.K8SDBSettings(
namespace="db",
pod_selector="app=pod-selector-db",
),
)
# Configurations for run command
ns.configure(
{
"run": {
"pty": True,
"echo": True,
},
"saritasa_invocations": saritasa_invocations.Config(
pre_commit=saritasa_invocations.PreCommitSettings(
hooks=(
"pre-commit",
"pre-push",
"commit-msg",
)
),
git=saritasa_invocations.GitSettings(
merge_ff="true",
pull_ff="only",
),
docker=saritasa_invocations.DockerSettings(
main_containers=(
"opensearch",
"redis",
),
),
system=saritasa_invocations.SystemSettings(
vs_code_settings_template=".vscode/recommended_settings.json",
settings_template="config/.env.local",
save_settings_from_template_to="config/.env",
),
),
},
)
Modules
printing
While this module doesn't contain any invocations, it's used to print message
via rich.panel.Panel
. There are three types:
print_success
- print message in green panelprint_warning
- print message in yellow panelprint_error
- print message in red panel
system
system.copy-local-settings
Copies local template for settings into specified file
Settings:
settings_template
path to settings template (Default:config/settings/local.template.py
)save_settings_from_template_to
path to where save settings (Default:config/settings/local.py
)
system.copy-vscode-settings
Copies local template for vscode settings into .vscode
folder
Settings:
vs_code_settings_template
path to settings template (Default:.vscode/recommended_settings.json
)
system.chown
Change owner ship of project files to current user.
Shortcut for owning apps dir by current user after some files were generated using docker-compose (migrations, new app, etc).
system.create-tmp-folder
Create folder for temporary files(.tmp
).
git
git.set-git-setting
Set git setting in config
git.setup
Preform setup of git:
- Install pre-commit hooks
- Set merge.ff
- Set pull.ff
Settings:
merge_ff
setting value formerge.ff
(Default:false
)pull_ff
setting value forpull.ff
(Default:only
)
pre-commit
pre-commit.install
Install git hooks via pre-commit.
Settings:
hooks
list of hooks to install (Default:["pre-commit", "pre-push", "commit-msg"]
)
pre-commit.run-hooks
Run all hooks against all files
docker
docker.build-service
Build service image from docker compose
docker.buildpack
Build project via pack-cli
Settings:
buildpack_builder
image tag of builder (Default:paketobuildpacks/builder:base
)buildpack_runner
image tag of runner (Default:paketobuildpacks/run:base
)build_image_tag
image tag of builder (Default: Name of project fromproject_name
)buildpack_requirements_path
path to folder with requirements (Default:requirements
)
docker.stop-all-containers
Shortcut for stopping ALL running docker containers
docker.up
Bring up main containers and start them.
Settings:
main_containers
image tag of builder (Default:["postgres", "redis"]
)
docker.stop
Stop main containers.
Settings:
main_containers
image tag of builder (Default:["postgres", "redis"]
)
docker.clear
Stop and remove all containers defined in docker-compose. Also remove images.
github-actions
github-actions.set-up-hosts
Add hosts to /etc/hosts
.
Settings:
hosts
image tag of builder (Default: seedocker-main-containers
)
python
As of now we support two environments for python local
and docker
.
local
is a python that is located in your current virtualenvdocker
is python that is located inside your docker image of service (python_docker_service
).
This was done to have ability to run code against environment close deployed one or simply test it out.
Example of usage
PYTHON_ENV=docker inv python.run-python --command="--version"
python.run
Run python command depending on PYTHON_ENV
variable(docker
or local
).
Settings:
entry
python entry command (Default:python
)docker_service
python service name (Default:web
)docker_service_params
params for docker (Default:--rm
)
django
django.manage
Run manage.py
with specified command.
This command also handle starting of required services and waiting DB to be ready.
Requires django_probes
django.makemigrations
Run makemigrations
command and chown created migrations (only for docker env).
django.check_new_migrations
Check if there is new migrations or not. Result should be check via exit code.
django.migrate
Run migrate
command.
Settings:
migrate_command
migrate command (Default:migrate
)
django.resetdb
Reset database to initial state (including test DB).
Requires django-extensions
Settings:
django_settings_path
default django settings (Default:config.settings.local
)
django.createsuperuser
Create superuser.
Settings:
default_superuser_email
default email of superuser (Default:root@localhost
)default_superuser_username
default username of superuser (Default:root
)default_superuser_password
default password of superuser (Default:root
)
django.run
Run development web-server.
Settings:
runserver_docker_params
params for docker (Default:--rm --service-ports
)runserver_command
runserver command (Default:runserver_plus
)runserver_host
host of server (Default:0.0.0.0
)runserver_port
port of server (Default:8000
)runserver_params
params for runserver command (Default:""
)
django.shell
Shortcut for manage.py shell command.
Settings:
shell_command
command to start python shell (Default:shell_plus --ipython
)
django.dbshell
Open database shell with credentials from current django settings.
django.load-db-dump
Reset db and load db dump.
Uses resetdb and load-db-dump
Settings:
django_settings_path
default django settings (Default:config.settings.local
)
django.backup-local-db
Back up local db.
Uses backup_local_db
Settings:
django_settings_path
default django settings (Default:config.settings.local
)
django.backup-remote-db
Make dump of remote db and download it.
Uses create_dump and get-dump
Settings:
django_settings_path
default django settings (Default:config.settings.local
)
django.load-remote-db
Make dump of remote db and download it and apply to local db.
Uses create_dump and get-dump and load-db-dump
Settings:
django_settings_path
default django settings (Default:config.settings.local
)
fastapi
fastapi.run
Run development web-server.
Settings:
docker_params
params for docker (Default:--rm --service-ports
)uvicorn_command
uvicorn command (Default:-m uvicorn
)app
path to fastapi app (Default:config:fastapi_app
)host
host of server (Default:0.0.0.0
)port
port of server (Default:8000
)params
params for uvicorn (Default:--reload
)
alembic
alembic.run
Run alembic command
Settings:
command
alembic command (Default:-m alembic
)
alembic.autogenerate
Generate migrations
Settings:
migrations_folder
migrations files location (Default:db/migrations/versions
)
alembic.upgrade
Upgrade database
alembic.downgrade
Downgrade database
alembic.check-for-migrations
Check if there any missing migrations to be generated
alembic.check-for-adjust-messages
Check migration files for adjust messages
Settings:
migrations_folder
migrations files location (Default:db/migrations/versions
)adjust_messages
list of alembic adjust messages (Default:# ### commands auto generated by Alembic - please adjust! ###
,# ### end Alembic commands ###
)
celery
celery.run
Start celery worker.
Settings:
local_cmd
command for celery (Default:celery --app config.celery:app worker --beat --scheduler=django --loglevel=info
)service_name
name of celery service (Default:celery
)
open-api
open-api.validate-swagger
Check that generated open_api spec is valid. This command uses drf-spectacular and it's default validator. It creates spec file in ./tmp folder and then validates it.
db
db.load-db-dump
Load db dump to local db.
Settings:
load_dump_command
template for load command(Default located in_config.pp > dbSettings
)dump_filename
filename for dump (Default:local_db_dump
)load_additional_params
additional params for load command (Default:--quite
)
db.backup-local-db
Back up local db.
Settings:
dump_command
template for dump command (Default located in_config.pp > dbSettings
)dump_filename
filename for dump (Default:local_db_dump
)dump_additional_params
additional params for dump command (Default:--no-owner
)
k8s
For K8S settings you just need to create a instances of K8SSettings
for each
environnement. It'll be all collected automatically.
k8s.login
Login into k8s via teleport.
Settings:
proxy
teleport proxy (REQUIRED)port
teleport port (Default:443
)auth
teleport auth method (Default:github
)
k8s.set-context
Set k8s context to current project
Settings:
namespace
namespace for k8s (Default: Name of project fromproject_name
)
k8s.logs
Get logs for k8s pod
Settings:
default_component
default component (Default:backend
)
k8s.pods
Get pods from k8s.
k8s.execute
Execute command inside k8s pod.
Settings:
default_component
default component (Default:backend
)default_entry
default entry cmd (Default:/cnb/lifecycle/launcher bash
)
k8s.python-shell
Enter python shell inside k8s pod.
Settings:
default_component
default component (Default:backend
)python_shell
shell cmd (Default:shell_plus
)
k8s.health-check
Check health of component.
Settings:
default_component
default component (Default:backend
)health_check
health check cmd (Default:health_check
)
k8s.download-file
Download file from pod.
default_component
default component (Default:backend
)
db-k8s
While you probably won't use this module directly some other modules commands are use it(getting remote db dump)
Make sure to set up these configs:
pod_namespace
db namespace (REQUIRED)pod_selector
pod selector for db (REQUIRED)
db-k8s.create-dump
Execute dump command in db pod.
Settings:
pod_namespace
db namespace (REQUIRED)pod_selector
pod selector for db (REQUIRED)pod_command
template for fetching db pod (Default located in_config.pp > K8SdbSettings
)dump_filename
default dump filename (Default: Name of project fromproject_name
plus_db_dump
)dump_command
dump command template (Default located in_config.pp > K8SDBSettings
)dump_additional_params
additional dump commands (Default:--no-owner
)
db-k8s.get-dump
Download db data from db pod if it present
Settings:
pod_namespace
db namespace (REQUIRED)pod_selector
pod selector for db (REQUIRED)pod_command
template for fetching db pod (Default located in_config.pp > K8SDBSettings
)dump_filename
default dump filename (Default: Name of project fromproject_name
plus_db_dump
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for saritasa_invocations-0.5.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40c7c285aaf1a518cbc94027bf5834407fc6ee97f7b94a6e12e0bf132ece3522 |
|
MD5 | 3b7afd525338e74723b185b6aca211dc |
|
BLAKE2b-256 | db3ff9d2296c34fc696455c24434f97b9bcfd21e3531e71853370b2d236887b7 |
Hashes for saritasa_invocations-0.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 735e320406d7d7b44c80789a0c5b79f578fbda9acba6dd11746eaccc0b5a6e21 |
|
MD5 | 00e5defdcc251d5ee7eda68f7b52a9fe |
|
BLAKE2b-256 | 1307b9732c9203f5358ef1e29f4a0aecbf43fec1cd787576ff9a64f80abe5b8d |