首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Github-Actions中为无服务器部署正确设置pythonBin

如何在Github-Actions中为无服务器部署正确设置pythonBin
EN

Stack Overflow用户
提问于 2021-03-30 04:30:04
回答 1查看 192关注 0票数 0

我正在尝试通过github操作部署一个简单的python lambda脚本。我一直在尝试弄清楚如何让github actions & serverless找到python3.6 (或python3.7)进行部署。

这是我的main.yml:

代码语言:javascript
复制
name: Deploy Lambda

# Controls when the action will run.  on:   # Triggers the workflow on push or pull request events but only for the master branch   push:
    branches: [ master ]

# Allows you to run this workflow manually from the Actions tab   workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs:   # This workflow contains a single job called "deploy"   deploy:
# The type of runner that the job will run on
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.6]
    env: #Setup environmental variables for serverless deployment
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      
      - name: Set up Python 3.6
        uses: actions/setup-python@v2
        with:
          python-version: 3.6
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
          echo "which python: `which python`"
          echo "which python3.6: `which python3.6`"
      
      - name: npm install dependencies
        run: npm install
        
      - name: Serverless
        uses: serverless/github-action@master
        with:
          args: deploy

这是我的serverless.yml

代码语言:javascript
复制
service: utilitybot 

provider:
  name: aws
  runtime: python3.6
  stage: prod
  region: us-east-1
  memorySize: 128

plugins:
  - serverless-wsgi
  - serverless-python-requirements
custom:
  wsgi:
    app: app.app
    packRequirements: false
    pythonRequirements:
      pythonBin: /opt/hostedtoolcache/Python/3.6.13/x64/bin/python3.6

functions:
  app:
    handler: wsgi_handler.handler
    events:
      - http: ANY /

下面是我尝试部署时的相关输出:

代码语言:javascript
复制
Successfully installed Flask-1.1.2 Jinja2-2.11.3 MarkupSafe-1.1.1 Werkzeug-1.0.1 aiohttp-3.7.4.post0 async-timeout-3.0.1 attrs-20.3.0 chardet-4.0.0 click-7.1.2 idna-3.1 idna-ssl-1.1.0 itsdangerous-1.1.0 multidict-5.1.0 pyee-7.0.4 slackclient-2.9.3 slackeventsapi-2.2.1 typing-extensions-3.7.4.3 urllib3-1.26.4 yarl-1.6.3
which python: /opt/hostedtoolcache/Python/3.6.13/x64/bin/python
which python3.6: /opt/hostedtoolcache/Python/3.6.13/x64/bin/python3.6
. . .
Serverless: Python executable not found for "runtime": python3.6
Serverless: Using default Python executable: python
Serverless: Packaging Python WSGI handler...
Serverless: Generated requirements from /github/workspace/requirements.txt in /github/workspace/.serverless/requirements.txt...
Serverless: Installing requirements from /github/home/.cache/serverless-python-requirements/1fc06bc3bc8373bb92e534c979ef8012825c2f0cf279b582a4c7d4a567c48e2d_slspyc/requirements.txt ...
Serverless: Using download cache directory /github/home/.cache/serverless-python-requirements/downloadCacheslspyc
 
 Error ---------------------------------------------------
 
  Error: python3.6 not found! Try the pythonBin option.
      at pipAcceptsSystem (/github/workspace/node_modules/serverless-python-requirements/lib/pip.js:100:13)

我尝试过没有pythonBin,各种版本的pythonBin,不同版本的python...我无法克服这个错误。当我执行哪个python3.6时,它会在路径中找到二进制文件,所以我搞不懂它在执行部署时为什么没有出现。

EN

回答 1

Stack Overflow用户

发布于 2021-04-15 03:09:48

终于让它工作了。

我将运行时更改为3.7我从pythonBin中删除了python可执行文件(因此它只是/opt/hostedtoolcache/Python/3.6.13/x64/bin/ )我将矩阵策略保留在3.6,但有serverless安装3.7

最重要的是,我找到了一个运行得更好的公共镜像: mirrorhanyu/serverless-github-action-python@master

所以main.yml的末尾变成了

代码语言:javascript
复制
      - name: Serverless
        uses: mirrorhanyu/serverless-github-action-python@master
        with:
          args: deploy
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66861241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档