Package: saritasa-invocations
saritasa-invocationsCollection ofinvokecommands used by SaritasaTable of contentsInstallationConfigurationModulesprintingsystemsystem.copy-local-settingssystem.copy-vscode-settingssystem.chownsystem.create-tmp-foldergitgit.set-git-settinggit.setupgit.clone-repopre-commitpre-commit.installpre-commit.run-hookspre-commit.updatedockerdocker.build-servicedocker.buildpackdocker.stop-all-containersdocker.updocker.stopdocker.cleargithub-actionsgithub-actions.set-up-hostspythonrundjangodjango.managedjango.makemigrationsdjango.migratedjango.resetdbdjango.createsuperuserdjango.rundjango.shelldjango.dbshelldjango.django.recompile-messagesdjango.load-db-dumpdjango.backup-local-dbdjango.backup-remote-dbdjango.load-remote-dbfastapifastapi.runalembicalembic.runalembic.autogeneratealembic.upgradealembic.downgradealembic.check-for-migrationsalembic.check-for-adjust-messagesalembic.load-db-dumpalembic.backup-local-dbalembic.backup-remote-dbalembic.load-remote-dbcelerycelery.runcelery.send-taskopen-apiopen-api.validate-swaggerdbdb.load-db-dumpdb.backup-local-dbk8sk8s.logink8s.set-contextk8s.logsk8s.podsk8s.executek8s.python-shellk8s.health-checkk8s.download-filedb-k8sdb-k8s.create-dumpdb-k8s.get-dumpcruftcruft.check-for-cruft-filescruft.create_projectpoetrypoetry.installpoetry.updatepoetry.update-to-latestpippip.install-dependenciespip.compilemypymypypytestpytestsecretssecrets.setup-env-credentialsInstallationpipinstallsaritasa-invocationsor if you are usingpoetrypoetryaddsaritasa-invocationsConfigurationConfiguration can be set intasks.pyfile.Below is an example of config:importinvokeimportsaritasa_invocationsns=invoke.Collection(saritasa_invocations.docker,saritasa_invocations.git,saritasa_invocations.github_actions,saritasa_invocations.pre_commit,saritasa_invocations.system,)# Configurations for run commandns.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",),# Default K8S Settings shared between envsk8s_defaults=saritasa_invocations.K8SDefaultSettings(proxy="teleport.company.com",db_config=saritasa_invocations.K8SDBSettings(namespace="db",pod_selector="app=pod-selector-db",),)),},)# 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",)saritasa_invocations.K8SSettings(name="prod",cluster="teleport.client.somewhere.com",namespace="project_name",proxy="teleport.client.com",)ModulesprintingWhile this module doesn't contain any invocations, it's used to print message
viarich.panel.Panel. There are three types:print_success- print message in green panelprint_warning- print message in yellow panelprint_error- print message in red panelsystemsystem.copy-local-settingsCopies local template for settings into specified fileSettings:settings_templatepath to settings template (Default:config/settings/local.template.py)save_settings_from_template_topath to where save settings (Default:config/settings/local.py)system.copy-vscode-settingsCopies local template for vscode settings into.vscodefolderSettings:vs_code_settings_templatepath to settings template (Default:.vscode/recommended_settings.json)system.chownChange 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-folderCreate folder for temporary files(.tmp).gitgit.set-git-settingSet git setting in configgit.setupPreform setup of git:Install pre-commit hooksSet merge.ffSet pull.ffSettings:merge_ffsetting value formerge.ff(Default:false)pull_ffsetting value forpull.ff(Default:only)git.clone-repoClone repo or pull latest changes to specified repogit.blame-copyCommand for creating copies of a file with git blame history saving.Original script written in bash:https://dev.to/deckstar/how-to-git-copy-copying-files-while-keeping-git-history-1c9jUsage:invgit.blame-copy<pathtooriginalfile><pathtocopy>,<pathtocopy>...If<path to copy>is file, then data will be copied in it.If<path to copy>is directory, then data will be copied in provided
directory with original name.Algorithm:Remember current HEAD stateFor each copy path:
move file to copy path, restore file usingcheckout,
remember result commitsRestore state of branchMove file to temp fileMerge copy commits to branchMove file to it's original path from temp fileSettings:copy_commit_templatetemplate for commits created during command workflowcopy_init_message_templatetemplate for init message printed at command startTemplate variables:action- The copy algorithm consists of several intermediate actions
(creating temporary files, merging commits, etc.)
Theactionvariable stores the header of the intermediate action.original_path- Contains value of first argument of the command
(path of original file that will be copied)destination_paths- Sequence of paths to which the original file will be copiedproject_task- project task that will be parsed from current git branch.
If no task found in branch, then will be emptyDefault values for templates:copy_commit_template:"[automated-commit]:{action}\n\n""copy:{original_path}\n""to:\n*{destination_paths}\n\n""{project_task}"copy_init_message_template:"Copy{original_path}to:\n""*{destination_paths}\n\n""Count of created commits:{commits_count}"pre-commitpre-commit.installInstall git hooks via pre-commit.Settings:hookslist of hooks to install (Default:["pre-commit", "pre-push", "commit-msg"])pre-commit.run-hooksRun all hooks against all files.pre-commit.updateUpdate pre-commit dependencies.dockerdocker.build-serviceBuild service image from docker composedocker.buildpackBuild project viapack-cliSettings:buildpack_builderimage tag of builder (Default:paketobuildpacks/builder:base)buildpack_runnerimage tag of runner (Default:paketobuildpacks/run:base)build_image_tagimage tag of builder (Default: Name of project fromproject_name)buildpack_requirements_pathpath to folder with requirements (Default:requirements)docker.stop-all-containersShortcut for stopping ALL running docker containersdocker.upBring up main containers and start them.Settings:main_containersimage tag of builder (Default:["postgres", "redis"])docker.stopStop main containers.Settings:main_containersimage tag of builder (Default:["postgres", "redis"])docker.clearStop and remove all containers defined in docker-compose. Also remove images.github-actionsgithub-actions.set-up-hostsAdd hosts to/etc/hosts.Settings:hostsimage tag of builder (Default: seedocker-main-containers)pythonAs of now we support two environments for pythonlocalanddocker.localis a python that is located in your current virtualenvdockeris 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 usagePYTHON_ENV=dockerinvpython.run--command="--version"python.runRun python command depending onPYTHON_ENVvariable(dockerorlocal).Settings:entrypython entry command (Default:python)docker_servicepython service name (Default:web)docker_service_paramsparams for docker (Default:--rm)djangodjango.manageRunmanage.pywith specified command.This command also handle starting of required services and waiting DB to
be ready.Requiresdjango_probesSettings:manage_file_pathpath tomanage.pyfile (Default:./manage.py)django.makemigrationsRunmakemigrationscommand and chown created migrations (only for docker env).django.check_new_migrationsCheck if there is new migrations or not. Result should be check via exit code.django.migrateRunmigratecommand.Settings:migrate_commandmigrate command (Default:migrate)django.resetdbReset database to initial state (including test DB).Requiresdjango-extensionsSettings:settings_pathdefault django settings (Default:config.settings.local)django.createsuperuserCreate superuser.Settings:default_superuser_emaildefault email of superuser (Default:root@localhost)default_superuser_usernamedefault username of superuser (Default:root)default_superuser_passworddefault password of superuser (Default:root)verbose_email_nameverbose name foremailfield (Default:Email address)verbose_username_nameverbose name forusernamefield (Default:Username)verbose_password_nameverbose name forpasswordfield (Default:Password)Note:Values forverbose_email_name,verbose_username_name,verbose_password_nameshould match with verbose names of model that usedthis settingdjango.runRun development web-server.Settings:runserver_docker_paramsparams for docker (Default:--rm --service-ports)runserver_commandrunserver command (Default:runserver_plus)runserver_hosthost of server (Default:0.0.0.0)runserver_portport of server (Default:8000)runserver_paramsparams for runserver command (Default:"")django.shellShortcut for manage.py shell command.Settings:shell_commandcommand to start python shell (Default:shell_plus --ipython)django.dbshellOpen database shell with credentials from current django settings.django.recompile-messagesGenerate and recompile translation messages.RequiresgettextSettings:makemessages_paramsparams for makemessages command (Default:--all --ignore venv)compilemessages_paramsparams for compilemessages command (Default:"")django.load-db-dumpReset db and load db dump.Usesresetdbandload-db-dumpSettings:django_settings_pathdefault django settings (Default:config.settings.local)django.backup-local-dbBack up local db.Usesbackup_local_dbSettings:settings_pathdefault django settings (Default:config.settings.local)django.backup-remote-dbMake dump of remote db and download it.Usescreate_dumpandget-dumpSettings:settings_pathdefault django settings (Default:config.settings.local)remote_db_config_mappingMapping of db config
Default:{"dbname":"RDS_DB_NAME","host":"RDS_DB_HOST","port":"RDS_DB_PORT","username":"RDS_DB_USER","password":"RDS_DB_PASSWORD",}django.load-remote-dbMake dump of remote db and download it and apply to local db.Usescreate_dumpandget-dumpandload-db-dumpSettings:settings_pathdefault django settings (Default:config.settings.local)django.startappCreate django app from a template using cookiecutter.Settings:app_boilerplate_linklink to app templateapp_template_directorypath to app template in project template (Default:.)apps_pathpath to apps folder in project (Default:apps)fastapifastapi.runRun development web-server.Settings:docker_paramsparams for docker (Default:--rm --service-ports)uvicorn_commanduvicorn command (Default:-m uvicorn)apppath to fastapi app (Default:config:fastapi_app)hosthost of server (Default:0.0.0.0)portport of server (Default:8000)paramsparams for uvicorn (Default:--reload)alembicalembic.runRun alembic commandSettings:commandalembic command (Default:-m alembic)connect_attemptsnumbers of attempts to connect to database (Default:10)alembic.autogenerateGenerate migrationsSettings:migrations_foldermigrations files location (Default:db/migrations/versions)alembic.upgradeUpgrade databasealembic.downgradeDowngrade databasealembic.check-for-migrationsCheck if there any missing migrations to be generatedalembic.check-for-adjust-messagesCheck migration files for adjust messagesSettings:migrations_foldermigrations files location (Default:db/migrations/versions)adjust_messageslist of alembic adjust messages (Default:# ### commands auto generated by Alembic - please adjust! ###,# ### end Alembic commands ###)alembic.load-db-dumpReset db and load db dump.Usesdowngradeandload-db-dumpRequirespython-decoupleInstalled with[env_settings]Settings:db_config_mappingMapping of db configDefault:{"dbname":"rds_db_name","host":"rds_db_host","port":"rds_db_port","username":"rds_db_user","password":"rds_db_password",}alembic.backup-local-dbBack up local db.Usesbackup_local_dbRequirespython-decoupleInstalled with[env_settings]Settings:db_config_mappingMapping of db configDefault:{"dbname":"rds_db_name","host":"rds_db_host","port":"rds_db_port","username":"rds_db_user","password":"rds_db_password",}alembic.backup-remote-dbMake dump of remote db and download it.Usescreate_dumpandget-dumpRequirespython-decoupleInstalled with[env_settings]Settings:db_config_mappingMapping of db configDefault:{"dbname":"rds_db_name","host":"rds_db_host","port":"rds_db_port","username":"rds_db_user","password":"rds_db_password",}alembic.load-remote-dbMake dump of remote db and download it and apply to local db.Usescreate-dumpandget-dumpandload-db-dumpRequirespython-decoupleInstalled with[env_settings]Settings:db_config_mappingMapping of db configDefault:{"dbname":"rds_db_name","host":"rds_db_host","port":"rds_db_port","username":"rds_db_user","password":"rds_db_password",}celerycelery.runStart celery worker.Settings:apppath to app  (Default:config.celery.app)schedulerscheduler (Default:django)loglevellog level for celery (Default:info)extra_paramsextra params for worker (Default:("--beat",))local_cmdcommand for celery (Default:celery --app {app} worker --scheduler={scheduler} --loglevel={info} {extra_params})service_namename of celery service (Default:celery)celery.send-taskSend task to celery worker.Settings:apppath to app  (Default:config.celery.app)open-apiopen-api.validate-swaggerCheck that generated open_api spec is valid. This command usesdrf-spectacularand
it's default validator. It creates spec file in ./tmp folder and then validates it.dbdb.load-db-dumpLoad db dump to local db.Settings:load_dump_commandtemplate for load command(Default located in_config.pp > dbSettings)dump_filenamefilename for dump (Default:local_db_dump)load_additional_paramsadditional params for load command (Default:--quite)db.backup-local-dbBack up local db.Settings:dump_commandtemplate for dump command (Default located in_config.pp > dbSettings)dump_filenamefilename for dump (Default:local_db_dump)dump_additional_paramsadditional params for dump command (Default:--no-owner)k8sFor K8S settings you just need to create a instances ofK8SSettingsfor each
environnement. It'll be all collected automatically.k8s.loginLogin into k8s via teleport.Settings:proxyteleport proxy (REQUIRED)portteleport port (Default:443)authteleport auth method (Default:github)k8s.set-contextSet k8s context to current projectSettings:namespacenamespace for k8s (Default: Name of project fromproject_name)k8s.logsGet logs for k8s podSettings:default_componentdefault component (Default:backend)k8s.podsGet pods from k8s.k8s.executeExecute command inside k8s pod.Settings:default_componentdefault component (Default:backend)default_entrydefault entry cmd (Default:/cnb/lifecycle/launcher bash)k8s.python-shellEnter python shell inside k8s pod.Settings:default_componentdefault component (Default:backend)python_shellshell cmd (Default:shell_plus)k8s.health-checkCheck health of component.Settings:default_componentdefault component (Default:backend)health_checkhealth check cmd (Default:health_check)k8s.download-fileDownload file from pod.default_componentdefault component (Default:backend)db-k8sWhile 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_namespacedb namespace (REQUIRED)pod_selectorpod selector for db (REQUIRED)db-k8s.create-dumpExecute dump command in db pod.Settings:pod_namespacedb namespace (REQUIRED)pod_selectorpod selector for db (REQUIRED)get_pod_name_commandtemplate for fetching db pod (Default located in_config.pp > K8SdbSettings)dump_filenamedefault dump filename (Default: Name of project fromproject_nameplus_db_dump)dump_commanddump command template (Default located in_config.pp > K8SDBSettings)dump_additional_paramsadditional dump commands (Default:--no-owner)db-k8s.get-dumpDownload db data from db pod if it presentSettings:pod_namespacedb namespace (REQUIRED)pod_selectorpod selector for db (REQUIRED)get_pod_name_commandtemplate for fetching db pod (Default located in_config.pp > K8SDBSettings)dump_filenamedefault dump filename (Default: Name of project fromproject_nameplus_db_dump)cruftCruftis a tool used to synchronize changes
with cookiecutter based boilerplates.cruft.check-for-cruft-filesCheck that there are no cruft files (*.rej).cruft.create_projectNot invocation, but a shortcut for creating cruft projects for testing
boilerplatespoetrypoetry.installInstall dependencies via poetry.poetry.updateUpdate dependencies with respect toversion constraintsusingpoetry up plugin.Fallbacks topoetry updatein case of an error.poetry.update-to-latestUpdate dependencies to latest versions usingpoetry up plugin.By default fallbacks toupdatetask in case of an error.
Use--no-fallbackto stop on error.pippip.install-dependenciesInstall dependencies via pip.Settings:dependencies_folderpath to folder with dependencies files (Default:requirements)pip.compile-dependenciesCompile dependencies viapip-compile.Settings:dependencies_folderpath to folder with dependencies files (Default:requirements)in_filessequence of.infiles (Default:"production.in","development.in")mypymypy.runRun mypy inpathwithparams.Settings:mypy_entrypython entry command (Default:-m mypy)pytestpytest.runRun pytest inpathwithparams.Settings:pytest_entrypython entry command (Default:-m pytest)secretssecrets.setup-env-credentialsFill specified credentials in your file from k8s.
This invocations downloads.envfile from pod in k8s.
It will replace specified credentials(--credentials) in
specified file.envfile (--env_file_pathor.envas default)Requirespython-decoupleSettings for k8s:secret_file_path_in_podpath to secret in pod (REQUIRED)temp_secret_file_pathpath for temporary file (Default:.env.to_delete)