简体   繁体   English

使用 gitlab-ci 部署无服务器时出现问题

[英]Problem while deploying serverless with gitlab-ci

I get the following error when I try to deploy my flask app as a lambda function with serverless on gitlab-ci.当我尝试在 gitlab-ci 上使用无服务器将我的 flask 应用程序部署为 lambda function 时出现以下错误。

Error: spawn python3.8 ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19)
    at onErrorNT (internal/child_process.js:470:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 1

However when I run command sls deploy locally it works.但是,当我在本地运行命令sls deploy时,它会起作用。

Here is my serverless.yml :这是我的serverless.yml

service: serverless-flask

plugins:
  - serverless-python-requirements
  - serverless-wsgi

custom:
  wsgi:
    app: app.app
    packRequirements: false
  pythonRequirements:
    dockerizePip: non-linux

provider:
  name: aws
  runtime: python3.8
  region: eu-west-3
  memorySize: 256
  timeout: 15

functions:
  app:
    handler: wsgi_handler.handler
    environment: ${file(env.${opt:stage, self:provider.stage}.json)}
    events:
      - http: ANY /
      - http: ANY /{proxy+}

And here is my gitlab-ci.yml :这是我的gitlab-ci.yml

image: ubuntu:latest

stages:
  - deploy

dev:
  only:
    - develop
  stage: deploy
  before_script:
    - apt-get update
    - ARG DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common && add-apt-repository ppa:deadsnakes/ppa && apt-get update && apt-get install -y python3.8 python3-pip && rm -rf /var/lib/apt/lists/*
    - apt update
    - apt install -y nodejs npm
    - npm install -g serverless
    - npm install
  script:
    - serverless deploy --stage dev
  environment: dev

I tried with differents docker images like python, node, ubuntu but I can't make it work.我尝试使用不同的 docker 图像,如 python、节点、ubuntu,但我无法使其工作。

I am doing a serverless deploy through github actions and ran into the same error message.我正在通过 github 操作进行无服务器部署并遇到相同的错误消息。 Hopefully this will help you and if not, I think it will help others.希望这会对您有所帮助,如果没有,我认为它会对其他人有所帮助。

It looks like the serverless-python-requirements plugin will attempt to spawn whatever is in provider.runtime, so in your case (and mine) python3.8看起来 serverless-python-requirements 插件将尝试生成 provider.runtime 中的任何内容,所以在你的情况下(和我的)python3.8

You can override this in your serverless.yml as such:您可以在您的 serverless.yml 中覆盖它:

custom:
  pythonRequirements:
    pythonBin: python

If your image has a 'python' executable, it will use this and it should work.如果您的图像有一个“python”可执行文件,它将使用它并且它应该可以工作。 I realised that despite the fact I had installed the correct target python version (in my case with actions/setup-python), the plugin would not find it so I am thinking it is running somewhere separate?我意识到尽管我已经安装了正确的目标 python 版本(在我的情况下是 actions/setup-python),插件找不到它所以我认为它在单独的地方运行?

Some people on SO/github issues say that they fixed the issue by modifying their provider.runtime to python3.7 or python3.9 which makes sense if their image has the corresponding executable.一些关于 SO/github 问题的人说他们通过将 provider.runtime 修改为 python3.7 或 python3.9 来解决这个问题,如果他们的图像具有相应的可执行文件,这就有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM