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

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/\*', 'dist/\*']

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.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

poetry_ycf_plugin-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: poetry_ycf_plugin-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.8.0-35-generic

File hashes

Hashes for poetry_ycf_plugin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6bfa5094f306102447810c3b6e6ea3727c1608389fbc8ea30e426e527fb23895
MD5 5f48fe270283578b255409d1141b0632
BLAKE2b-256 ae51e975fb04ed8ce068e164aebc6bc5c77f42ce5caff7580e504ef5d0dea546

See more details on using hashes here.

File details

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

File metadata

  • Download URL: poetry_ycf_plugin-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.8.0-35-generic

File hashes

Hashes for poetry_ycf_plugin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a78266c9f6d154ee5a1219520989fc1472ef279f4a3f37b1bf06be3115e426d
MD5 a901b921c301d81252a2aeea8810b0b7
BLAKE2b-256 321212b145f258c3ded9a2f8345539e261aeffdaf45bba3d8ece18fcb5b7474a

See more details on using hashes here.

Supported by

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