Circle Ci、无服务器框架、无服务器 python 要求

问题描述 投票:0回答:2

我正在尝试通过

circleci CI/CD
将我的Python项目上传到AWS帐户,但是当我部署代码时,它总是停止并删除日志中的docker“docker run --rm -v”

我正在使用 ORBs 就像

aws-cli: circleci/[email protected]

serverless-framework: circleci/[email protected]

有什么帮助吗?

这是.circleci/config.yml

version: 2.1
orbs:
  aws-cli: circleci/[email protected]
  serverless-framework: circleci/[email protected]
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

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)}

这是提供的错误日志

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
aws-cli serverless-framework circleci cicd
2个回答
0
投票

当您使用 orbs

aws-cli
serverless-framework

时,Docker 不会运行

所以解决方案是自己构建它。

这是.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

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)}

0
投票

要解决在 CircleCI 作业中运行 Docker 的问题,您需要将

setup_remote_docker
添加到您的
config.yml
文件中。

https://circleci.com/docs/building-docker-images/

您可能遇到的下一个问题可能是它找不到 docker 映像(因为它具有 x86_64 架构,这可能不是您的 CircleCI 作业正在使用的架构)。为了避免这种情况,请将其添加到

serverless-pipeline-plugin
选项中(这会从图像名称中删除架构):

    dockerImage: public.ecr.aws/sam/build-python3.11:latest
© www.soinside.com 2019 - 2024. All rights reserved.