Skip to main content

Poetry plugin for working with Yandex Cloud Functions

Project description

Poetry Yandex Cloud Functions Plugin

Poetry plugin to set package version based on git tag.

PyPI PyPI - Python Version GitLab last commit Docs

Test coverage Downloads GitLab stars

Functionality

  • One-command deploy.
  • Configure target files and dependency groups via pyproject
  • Using only authorized_key.json for authentication.
  • Deploy via ZIP and S3. Details.
  • Setting up an entrypoint and memory

Quick start

Install poetry and get authorized_key.json

poetry self add poetry-ycf-plugin
poetry ycf-deploy

Permissions

You need to create a service account and give it the following roles on the cloud / folder / target resources.

  • functions.admin
  • iam.serviceAccounts.accessKeyAdmin
  • iam.serviceAccounts.user
  • storage.admin

Configs

List of variables and brief description.

Supported configuration sources: .env files (prefixed with YCF_), environment variables (prefixed with YCF_), and pyproject.toml (under the [tool.poetry-ycf-plugin] section).

export YCF_ENTRYPOINT='test_project.entrypoint.index_entrypoint' 
# same as
echo "YCF_ENTRYPOINT=test_project.entrypoint.index_entrypoint" >> .env
# same as
[tool.poetry-ycf-plugin]
entrypoint = 'test_project.entrypoint.index_entrypoint'

YCF Authorized Key

tool.poetry-ycf-plugin.authorized_key or YCF_AUTHORIZED_KEY

Required. String. Default: Path('./authorized_key.json')

The path to the authorized_key.json file.

YCF Service Account ID

tool.poetry-ycf-plugin.service_account_id or YCF_SERVICE_ACCOUNT_ID

Required. String.

The ID of the service account used to perform operations in the cloud. The account must have access to the S3 bucket YCF s3_bucket_name and permissions to modify function versions YCF id.

YCF Build Dependencies Groups

tool.poetry-ycf-plugin.build_dependencies_groups or YCF_BUILD_DEPENDENCIES_GROUPS

Optional. List of strings.

Specifies which Poetry dependency groups from pyproject.toml, in addition to the main group, are required for the function. All selected dependencies will be converted into requirements.txt and included in the build.

YCF Build Include

tool.poetry-ycf-plugin.build_include or YCF_BUILD_INCLUDE

Optional. List of strings. Default: ['\*.py', '\*\*/\*.py', 'assess/\*']

Specifies the file patterns that should be included in the build.

YCF Build Exclude

tool.poetry-ycf-plugin.build_exclude or YCF_BUILD_EXCLUDE

Optional. List of strings. Default: ['\*\*/\_\_pycache\_\_/\*\*', 'tests/\*']

Specifies the file patterns that should be excluded from build_include and therefore not included in the build.

For example, if build_include contains the pattern *.py and build_exclude contains the pattern .*, the file .old_realization.py will not be included in the build.

YCF S3 Bucket Name

tool.poetry-ycf-plugin.s3_bucket_name or YCF_S3_BUCKET_NAME

Required. String.

The name of the S3 bucket where releases will be saved as .zip archives.

YCF S3 Bucket Path

tool.poetry-ycf-plugin.s3_bucket_path or YCF_S3_BUCKET_PATH

Optional. String. Default: ycf-releases

The directory in the S3 bucket where releases will be saved as .zip archives.

YCF ID

tool.poetry-ycf-plugin.id or YCF_ID

Required. String.

The identifier of the target function.

YCF Entrypoint

tool.poetry-ycf-plugin.entrypoint or YCF_ENTRYPOINT

Optional. String. Default: main.handler

The entry point for the Yandex Cloud function. This variable should contain a string reference to the function that will receive the input data.

YCF Memory

tool.poetry-ycf-plugin.memory or YCF_MEMORY

Optional. Number. Default: 134217728

Specifies the amount of memory that Yandex Cloud should allocate for the function.

YCF Runtime

tool.poetry-ycf-plugin.runtime or YCF_RUNTIME

Optional. String. Default: python312

Specifies the runtime environment.

YCF Environment

tool.poetry-ycf-plugin.environment or YCF_ENVIRONMENT

Optional. Dict[str, str]. Default: {}

An array of environment variables that will be accessible from the function.

Commands

poetry ycf-deploy

The deployment command initiates the deployment process, which is divided into several stages. Progress updates are displayed in the console.

$ poetry ycf-deploy
poetry-ycf-plugin: Launched deploying YCF "d4e0jp3jpnbrct06fogq": new release "poetry-ycf-plugin 0.0.0"
poetry-ycf-plugin: Authorization
poetry-ycf-plugin: Building
poetry-ycf-plugin: Uploading
poetry-ycf-plugin: Releasing
poetry-ycf-plugin: Cleaning

VERBOSE

$ poetry ycf-deploy
poetry-ycf-plugin: Launched deploying YCF "d4e0jp3jpnbrct06fogq": new release "poetry-ycf-plugin 0.0.0"
poetry-ycf-plugin: Authorization
poetry-ycf-plugin: Authorization | Created temporary AWSAccessKey: ajero9nn021apdpgn452
poetry-ycf-plugin: Building
poetry-ycf-plugin: Building | File added: poetry_ycf_plugin/deploy_manager.py
poetry-ycf-plugin: Building | File added: poetry_ycf_plugin/responses.py
poetry-ycf-plugin: Building | File added: poetry_ycf_plugin/plugins.py
poetry-ycf-plugin: Building | File added: poetry_ycf_plugin/commands.py
poetry-ycf-plugin: Building | File added: poetry_ycf_plugin/utils.py
poetry-ycf-plugin: Building | File added: poetry_ycf_plugin/__init__.py
poetry-ycf-plugin: Building | File added: poetry_ycf_plugin/config.py
poetry-ycf-plugin: Building | File added: poetry_ycf_plugin/exceptions.py
poetry-ycf-plugin: Building | File added: temporary requirements.txt
poetry-ycf-plugin: Building | Builded zip for uploading: /{full_path}}/dist/YC/ycf-releases/d4e0jp3jpnbrct06fogq-poetry-ycf-plugin-0-0-0.zip
poetry-ycf-plugin: Uploading
poetry-ycf-plugin: Uploading | Release uploaded to S3: releases-ycf -> ycf-releases/d4e0jp3jpnbrct06fogq-poetry-ycf-plugin-0-0-0.zip
poetry-ycf-plugin: Releasing
poetry-ycf-plugin: Cleaning
poetry-ycf-plugin: Cleaning | Deleted temporary AWSAccessKey: ajero9nn021apdpgn452

Use cases

Deploying a Python Yandex Cloud Function with GitLab CI/CD

In the CI/CD settings of your repository, create a variable named YCF_AUTHORIZED_KEY with the type set to File. You can obtain this file from the service account settings in Yandex Cloud: https://yandex.cloud/docs/iam/concepts/authorization/key.

.gitlab-ci.yml:

pypi:
  stage: publishing
  image: rocshers/python-poetry:3.12.4-slim-1.8.3
  tags:
    - docker
  script:
    - poetry self add poetry-ycf-plugin
    - poetry ycf-deploy
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Contribute

Issue Tracker: https://gitlab.com/rocshers/python/poetry-ycf-plugin/-/issues
Source Code: https://gitlab.com/rocshers/python/poetry-ycf-plugin

Before adding changes:

make install-dev

After changes:

make format test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

poetry_ycf_plugin-0.2.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

poetry_ycf_plugin-0.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file poetry_ycf_plugin-0.2.0.tar.gz.

File metadata

  • Download URL: poetry_ycf_plugin-0.2.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.10

File hashes

Hashes for poetry_ycf_plugin-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0ed4ee3578d5eae7556de15550eecf67175927c047b68a3f67823fa405500ce4
MD5 11f4c506281cd478ef0beb541411c1b6
BLAKE2b-256 5ed43aba84dfd593d1ec5e40895f0e712394575d6c8b671be54831caebea059e

See more details on using hashes here.

File details

Details for the file poetry_ycf_plugin-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for poetry_ycf_plugin-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 526bead4cf59fb35280b23a3ac624e5f4cfa54c7ecbba5afd26298bde4f8ced3
MD5 a1ea90e33bfd7924a4d32ea50862898f
BLAKE2b-256 0cb96be9c9c80a22d8d72e3c32af849ef1ba1fa6e85dc546f2fb7f98d591ccb9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page