Git Product home page Git Product logo

yandex-serverless-action's Introduction

Yandex serverless action

yandex-serverless-action

This action uploads code to object storage and update Serverless function in Yandex cloud.

Usage

  1. Create serverless function in Yandex Cloud and copy function id
  2. Create s3 bucket (optional, if you want to upload code to bucket or if it's bigger than 5Mb)
  3. Add workflow to your repo

workflow.yml Example

Place in a .yml|.yaml file such as this one in your .github/workflows folder. Refer to the documentation on workflow YAML syntax here.

name: Push and Deploy Serverless function
on: push

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: goodsmileduck/yandex-serverless-action@v2
      with:
        token: ${{ secrets.TOKEN }}
        bucket: ${{ secrets.BUCKET }}
        accessKeyId: ${{ secrets.ACCESS_KEY_ID }}
        secretAccessKey: ${{ secrets.SECRET_ACCESS_KEY }}
        function_id: '234awefq12345g24f'
        runtime: 'python37'
        memory: '256'
        entrypoint: 'main.handler'
        environment: DEBUG=True,COUNT=1
        source: '.'
        exclude: 'src/'

Configuration

The following settings must be passed as variables as shown in the example. Sensitive information, especially token should be set as encrypted secrets — otherwise, they'll be public to anyone browsing your repository.

Key Value Suggested Type Required
token Token for access to yc cli. To get token visit link secret Yes
function_id The ID of function in Yandex Cloud env Yes
runtime Runtime for function in Yandex Cloud. To get the list of allowed args visit link env Yes
entrypoint Entry point of function env Yes
description Description for version of function env No
environment Comma-separated list with env variables env No
memory Memory limit in megabytes for function in Yandex Cloud Default value is 128 env No
execution_timeout Execution timeout in seconds for function in Yandex Cloud. Default value is 5 env No
service_account Service account id. secret No
bucket The name of the bucket you're syncing to. For example, bucket. If wasn't set action will try to upload code directly. Required if code bigger than 5Mb secret No
accessKeyId Yandex AWS Access Key Id when s3 bucket used. Required if code bigger than 5Mb secret No
secretAccessKey Yandex AWS Access Key Id when s3 bucket used. Required if code bigger than 5Mb secret No
source The local directory you wish to upload. For example, ./public. Defaults to the root of your repository (.) if not provided. env No
exclude Explicitly exclude the specified files. Defaults empty if not provided. env No

Scenarios

Zip and and deploy folder

- uses: goodsmileduck/yandex-serverless-action@v1
  with:
    token: ${{ secrets.TOKEN }}
    function_id: 'my_function_id'
    runtime: 'python37'
    memory: '256'
    entrypoint: 'main.handler'
    environment: DEBUG=True,COUNT=1
    source: '.'

Zip and upload to bucket and deploy

- uses: goodsmileduck/yandex-serverless-action@v1
  with:
    description: "Function without bucket"
    token: ${{ secrets.TOKEN }}
    bucket: ${{ secrets.BUCKET }}
    accessKeyId: ${{ secrets.ACCESS_KEY_ID }}
    secretAccessKey: ${{ secrets.SECRET_ACCESS_KEY }}
    function_id: 'my_function_id'
    runtime: 'python37'
    memory: '256'
    entrypoint: 'main.handler'
    environment: DEBUG=True,COUNT=1
    source: './src'
    description: "Version: v0.1.1"

Exclude pattern from archive

- uses: goodsmileduck/yandex-serverless-action@v1
  with:
    token: ${{ secrets.TOKEN }}
    function_id: 'my_function_id'
    runtime: 'python37'
    memory: '256'
    entrypoint: 'main.handler'
    environment: DEBUG=True,COUNT=2
    source: './public'
    exclude: '*.txt'

Set service account id

- uses: goodsmileduck/yandex-serverless-action@v1
  with:
    token: ${{ secrets.TOKEN }}
    function_id: 'my_function_id'
    runtime: 'python37'
    memory: '256'
    entrypoint: 'main.handler'
    environment: DEBUG=True,COUNT=2
    source: './public'
    service_account: ${{ secrets.SERVICE_ACCOUNT }}

License

This project is distributed under the MIT license.

yandex-serverless-action's People

Contributors

batformat avatar dependabot[bot] avatar goodsmileduck avatar konclave avatar scrabyq avatar sergeyzwezdin avatar vermilion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yandex-serverless-action's Issues

Deployment doesn't work

Trying to setup YF deployment. Here is how my workflow definition looks:

CleanShot 2019-11-25 at 05 23 52@2x

But when I run it, I'm getting an error:

CleanShot 2019-11-25 at 05 24 47@2x

The action doesn't cleanup after deployment

If I deploy more than one YF in a single GH workflow, files from the first deployed function appear in second function. Probably need to clean up SOURCE_DIR before zipping/deployment.

Feature request: Add ignore pattern

It would be very nice to have ability to add ignore filter for files that should be packed into the archive. For now, we need to explicitly copy the result to another folder that could be time-consuming.

Error INVALID_ARGUMENT: Исходный архив не является валидным ZIP архивом

Не получается задеплоить функцию на go

Ошибка из YC

INVALID_ARGUMENT: Исходный архив не является валидным ZIP архивом

Yml файл

name: Push and Deploy Serverless function
on: push

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: goodsmileduck/yandex-serverless-action@v2
        with:
          token: ${{ secrets.TOKEN }}
          function_id: "***"
          runtime: "golang121"
          entrypoint: "index.Handler"
          exclude: "main.go"
          environment: YDB_METADATA_CREDENTIALS=1

Файл логов github action

logs_10.zip

[Feature Request] возможность не "exclude файлы из сборки", а наоборот "include только нужное"

Пишу этот issue в 3 часа ночи, поэтому pr не сделал. Я предлагаю 2 простых изменения в коде, которые позволят сделать загружаемые на сервера яндекса архивы с функциями более чистыми

  1. Добавить условие на строку 53, чтобы можно было загружать архивы напрямую
// Было
const fileContents = await zipDirectory(inputs);

// Стало
import { promises as fs } from "fs"

const fileContents = await (
  inputs.source.endsWith('.zip') 
    ? fs.readFile(inputs.source) 
    : zipDirectory(inputs)
)
  1. Выбор только нужных файлов (строка 184-190)
await archive
            // TODO: Добавить files в inputs и actions.yml
            .glob(inputs.files  ?? "**", {
                cwd: inputs.source,
                dot: true,
                ignore: parseIgnoreGlobPatterns(inputs.sourceIgnore)
            })
            .finalize();

Удачи в развитии экшена

Feature request: add service account option

The requested feature: add parameter service-account-id to the action.

Generally, it is expected that all the parameters described by yc serverless function version create --help can be passed to the action.

Why it is important: when a service account is added to a function, it can receive IAM-tokens on each call and use them to call other APIs of Yandex.Cloud (e.g. translate API). This is very convenient e.g. for Alice skills using these APIs.

More info about exclude

Please, add more information about exclude patterns in README. I found out from code, that several patterns could be written comma separated. Also it would be nice, if you say something about pattern syntax - Is it regex or something simplier?

Fail during initialization

I use the latest version from master:

    - name: Deploy YF
      uses: goodsmileduck/yandex-serverless-action@0cd492301916f9cbcbaeb68393f0a658a741ec44
      env:

Build started failing today:

 ---> Using cache
 ---> 0917ee5e5cb1
Step 3/12 : RUN go get -u -v github.com/a8m/envsubst/cmd/envsubst
 ---> Using cache
 ---> 400461e63b09
Step 4/12 : FROM plugins/base:linux-amd64
 ---> 8c692aac9d91
Step 5/12 : LABEL maintainer="Serebrennikov Stanislav <[email protected]>"   org.label-schema.name="Yandex Cloud function deploy"   org.label-schema.vendor="Serebrennikov Stanislav"   org.label-schema.schema-version="1.0"
 ---> Using cache
 ---> 8ce40c9424a0
Step 6/12 : ENV ZONE=ru-central1-a   MEMORY=128m   TIMEOUT=5s
 ---> Using cache
 ---> 3dc188637f23
Step 7/12 : COPY --from=builder /go/bin/envsubst /bin/envsubst
 ---> Using cache
 ---> 524dfdb0ae28
Step 8/12 : RUN apk add curl bash python py-pip zip &&   curl https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bash &&   pip install awscli &&   ln -s /root/yandex-cloud/bin/yc /bin/yc
 ---> Running in b054555413e5
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  python (missing):
    required by: world[python]
The command '/bin/sh -c apk add curl bash python py-pip zip &&   curl https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bash &&   pip install awscli &&   ln -s /root/yandex-cloud/bin/yc /bin/yc' returned a non-zero code: 1
##[error]Docker build failed with exit code 1

ERROR: zip archive content exceeds the maximum size 3.5 MB, use object storage to upload the content

aws --endpoint-url=https://storage.yandexcloud.net s3 cp ${GITHUB_SHA}.zip s3://${BUCKET}/${FUNCTION_NAME}/${GITHUB_SHA}.zip

Hi!

Function version uploaded into the cloud storage is being afterwards "created" with --source-path, which is wrong. Instead it should be created with --package-bucket-name and --package-object-name.

Would you be able to fix it? For my part, I could offer to make a pull request.

Thank you for such a great tool!

Error if environment not passed

In configuration section indicated that the parameter environment not required. But if it is not passed, then there will be an error:

##[error]3 INVALID_ARGUMENT: Validation failed:
  - environment[]: Field does not match the pattern /[a-zA-Z][a-zA-Z0-9_]*/

[BUG] action v2 has no effect on the cloud

Hi there!
I appreciate your work; it helps me run a lot of lambdas and works like a charm!

However, yandex-serverless-action@v2 doesn't seem to work.

This is my action:

      - uses: goodsmileduck/yandex-serverless-action@v2
        with:
          token: ${{ secrets.YC_TOKEN }}
          function_id: ${{ secrets.YC_FUNCTION_ID }}
          service_account: ${{ secrets.YC_SERVICE_ACCOUNT }}
          bucket: ${{ secrets.YC_BUCKET }}
          accessKeyId: ${{ secrets.ACCESS_KEY_ID }}
          secretAccessKey: ${{ secrets.SECRET_ACCESS_KEY }}
          runtime: 'python311'
          memory: '1024'
          execution_timeout: '15'
          entrypoint: 'ycloud.handler'
          environment: VAR1=${{ secrets.VAR1 }},VAR2=${{ secrets.VAR2 }},VAR3=${{ secrets.VAR3 }}
          source: 'app'

This is success log of execution (in 2 seconds):

Run goodsmileduck/yandex-serverless-action@v2
  with:
    token: ***
    function_id: ***
    service_account: ***
    bucket: ***
    accessKeyId: ***
    secretAccessKey: ***
    runtime: python311
    memory: 1024
    execution_timeout: 15
    entrypoint: ycloud.handler
    environment: VAR1=***,VAR2=***,VAR3=***
    source: app
Function inputs set
::group::ZipDirectory
ZipDirectory
  Archive initialize
  Source ignore pattern: "[]"

When I looked at the developer console, I saw no new version of lambda deployed. I didn't see any new archive in Object Storage either.

But if I change v2 to v1 - it works as expected. Here is the success log (31 seconds):

Warning: Unexpected input(s) 'accessKeyId', 'secretAccessKey', valid inputs are ['description', 'token', 'function_id', 'bucket', 'runtime', 'entrypoint', 'source', 'exclude', 'memory', 'environment', 'execution_timeout', 'service_account']
Run goodsmileduck/yandex-serverless-action@v1
Function inputs set
::group::ZipDirectory
ZipDirectory
Buffer size: 59809425b
Upload to bucket: "***/***/***.zip"
::group::Get function by ID: "***"
Get function by ID: "***"
::group::Create function version
Create function version
::set-output name=time::09:54:35 GMT+0000 (Coordinated Universal Time)
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

I know that it's not the best bug description, but that's all I have. It's not a blocker for me as well - I continue using v1 and it's cover 100% of my requirements.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.