简体   繁体   English

Circle Ci, serverless-framework, serverless-python-requirements

[英]Circle Ci, serverless-framework, serverless-python-requirements

I am trying to upload my Python project to an AWS account via circleci CI/CD but when I deploy the code it always stops and remove docker "docker run --rm -v" in logs我正在尝试通过circleci CI/CD将我的 Python 项目上传到 AWS 帐户但是当我部署代码时它总是停止并删除日志中的 docker“docker run --rm -v”

I'm using ORBs like我正在使用ORB 之类的

aws-cli: circleci/aws-cli@3.1.3

serverless-framework: circleci/serverless-framework@2.0.0

any help?有帮助吗?

this is.circleci/config.yml这是.circleci/config.yml

version: 2.1
orbs:
  aws-cli: circleci/aws-cli@3.1.3
  serverless-framework: circleci/serverless-framework@2.0.0
jobs:
  deploy:
    executor: serverless-framework/default
    docker: # run the steps with Docker
      - image: cimg/python:3.8.0
    steps:
      - checkout
      - aws-cli/setup
      - serverless-framework/setup
      - run:
          name: Install plugins
          command: |
            serverless plugin install -n serverless-python-requirements
      - run: python --version
      - run:
          name: deploy
          command: |
            sls deploy --stage dev --verbose
            sls doctor
workflows:
  deploy:
    jobs:
      - deploy

And serverless.yml file is serverless.yml 文件是

service: myapp-api

frameworkVersion: "3"

package:
  patterns:
    - '!node_modules/**'
    - '!.vscode'
    - '!.circleci'
    - '!temp.txt'
    - '!README.md'
    - '!env/**'
    - '!package.json'
    - '!package-lock.json'
    - '!others/*.yml'
    - '!resources'

provider:
  name: aws
  stage: dev
  endpointType: REGIONAL
  runtime: python3.8
  region: us-east-2

plugins:
  - serverless-python-requirements

custom:
  pythonRequirements:
    dockerizePip: true
    slim: true
    zip: true

functions:
  # others & publics
  - ${file(./others/TestGet.yml)}
  - ${file(./others/DownloadFactsPost.yml)}
  - ${file(./others/DownloadTagsPost.yml)}

resources:
  # api gateway
  - ${file(./resources/api-gateway-request-validator.yml)}

this is the provided error log这是提供的错误日志

Running "serverless" from node_modules

Deploying myapp-api to stage dev (*********)

Adding Python requirements helper
Generated requirements from /home/circleci/project/requirements.txt in /home/circleci/project/.serverless/requirements.txt
Installing requirements from "/home/circleci/.cache/serverless-python-requirements/6b1b8e5bcb3893228e019bffa40e9c7db43bac76b8b7f2766f061ca751e722ce_x86_64_slspyc/requirements.txt"
Docker Image: public.ecr.aws/sam/build-python3.8:latest-x86_64
Using download cache directory /home/circleci/.cache/serverless-python-requirements/downloadCacheslspyc
Running docker run --rm -v /home/circleci/.cache/serverless-python-requirements/6b1b8e5bcb3893228e019bffa40e9c7db43bac76b8b7f2766f061ca751e722ce_x86_64_slspyc\:/var/task\:z -v /home/circleci/.cache/serverless-python-requirements/downloadCacheslspyc\:/var/useDownloadCache\:z public.ecr.aws/sam/build-python3.8\:latest-x86_64 /bin/sh -c 'chown -R 0\\:0 /var/useDownloadCache && python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache && chown -R 3434\\:3434 /var/task && chown -R 3434\\:3434 /var/useDownloadCache && find /var/task -name \\*.so -exec strip \\{\\} \\;'...

× Stack myapp-api-dev failed to deploy (0s)
Environment: linux, node 16.16.0, framework 3.25.1 (local) 3.25.1v (global), plugin 6.2.2, SDK 4.3.2
Credentials: Local, environment variables
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Running "docker run --rm -v /home/circleci/.cache/serverless-python-requirements/6b1b8e5bcb3893228e019bffa40e9c7db43bac76b8b7f2766f061ca751e722ce_x86_64_slspyc:/var/task:z -v /home/circleci/.cache/serverless-python-requirements/downloadCacheslspyc:/var/useDownloadCache:z public.ecr.aws/sam/build-python3.8:latest-x86_64 /bin/sh -c chown -R 0\:0 /var/useDownloadCache && python3.8 -m pip install -t /var/task/ -r /var/task/requirements.txt --cache-dir /var/useDownloadCache && chown -R 3434\:3434 /var/task && chown -R 3434\:3434 /var/useDownloadCache && find /var/task -name \*.so -exec strip \{\} \;" failed with: "docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'."

Exited with code exit status 1

The Docker doesn't running while you are using orbs aws-cli and serverless-framework当您使用 orbs aws-cliserverless-framework时,Docker 没有运行

So the solution will be to build it by your own.所以解决方案是自己构建它。

this is.circleci/config.yml这是.circleci/config.yml

version: 2.1

jobs:

  deploy:

    docker: # run the steps with Docker
      # Specify the version you desire here https://circleci.com/developer/images
      - image: cimg/python:3.8-node

    steps: # a set of executable commands
      - checkout

      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "requirements.txt" }}
          - v1-dependencies-

      - run:
          name: install dependencies
          command: |
            python3 -m venv env
            . env/bin/activate
            pip install -r requirements.txt

      - save_cache:
          key: v1-dependencies-{{ checksum "requirements.txt" }}
          paths:
            - env

      - run:
          name: Update NPM
          command: |
            npm install -g npm

      - run:
          name: Install serverless framework
          command: |
            npm install -g serverless

      - run:
          name: Install serverless plugins
          command: |
            sls plugin install -n serverless-python-requirements

      - run:
          name: deploy
          command: |
            sls deploy --stage dev --verbose
            sls doctor
workflows:
  deploy:
    jobs:
      - deploy

And serverless.yml file is serverless.yml 文件是

service: myapp-api

frameworkVersion: "3"

package:
  patterns:
    - '!node_modules/**'
    - '!.vscode'
    - '!.circleci'
    - '!temp.txt'
    - '!README.md'
    - '!env/**'
    - '!package.json'
    - '!package-lock.json'
    - '!others/*.yml'
    - '!resources'

provider:
  name: aws
  stage: dev
  endpointType: REGIONAL
  runtime: python3.8
  region: us-east-2

plugins:
  - serverless-python-requirements
#   - serverless-reqvalidator-plugin
#   - serverless-aws-documentation

custom:
  pythonRequirements:
    noDeploy:
      - boto3
      - botocore
      - docutils
      - autopep8
      - pycodestyle
      - six
      - tomli

functions:
  # others & publics
  - ${file(./others/TestGet.yml)}
  - ${file(./others/DownloadFactsPost.yml)}
  - ${file(./others/DownloadTagsPost.yml)}

resources:
  # api gateway
  - ${file(./resources/api-gateway-request-validator.yml)}

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

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