首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在gitlab-ci的本地堆栈中运行lambdas

在gitlab-ci的本地堆栈中运行lambdas
EN

Stack Overflow用户
提问于 2021-02-19 16:14:50
回答 1查看 1.3K关注 0票数 3

因此,我可以在本地运行本地堆栈(在我的笔记本上),并可以在其上部署无服务器应用程序,然后调用Lambda。

然而,我真的很难在gitlab-ci做同样的事情。

这是..gitlab ci.yml的相关部分:

代码语言:javascript
复制
integration-test:
  stage: integration-test
  image: node:14-alpine3.12
  tags:
    - docker
  services:
    - name: localstack/localstack
      alias: localstack
  variables:
    LAMBDA_EXECUTOR: docker
    HOSTNAME_EXTERNAL: localstack
    DEFAULT_REGION: eu-west-1
    USE_SSL: "false"
    DEBUG: "1"
    AWS_ACCESS_KEY_ID: test
    AWS_SECRET_ACCESS_KEY: test
    AWS_DEFAULT_REGION: eu-west-1
  script:
    - npm ci
    - npx sls deploy --stage local
    - npx jest --testMatch='**/*.integration.js'
  only:
    - merge_requests

本地堆栈启动,部署工作正常。但是,一旦调用lambda (在集成测试中),local堆栈就会尝试创建一个容器,让lambda在其中运行,这时它就会失败,如下所示:

代码语言:javascript
复制
Lambda process returned error status code: 1. Result: . Output:\\nCannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?\\nmust specify at least one container source (.....)

我试图将DOCKER_HOST设置为tcp://docker:2375,但随后它失败了:

代码语言:javascript
复制
Lambda process returned error status code: 1. Result: . Output:\\nerror during connect: Post http://docker:2375/v1.29/containers/create: dial tcp: lookup docker on 169.254.169.254:53: no such host\

DOCKER_HOST设置为tcp://localhost:2375也会抱怨:

代码语言:javascript
复制
Lambda process returned error status code: 1. Result: . Output:\\nCannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?\\nmust specify at least one container source

有没有人让lambda在共享gitlab运行程序的本地堆栈中运行?

(谢谢你的帮助:)

EN

回答 1

Stack Overflow用户

发布于 2021-02-26 09:29:24

在码头上运行码头通常是个坏主意,因为这是一个很大的安全漏洞。授予对本地docker守护进程的访问等于对运行程序授予根权限。

如果您仍然希望使用安装在主机上的对接器来生成容器,请参阅正式文档- https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#use-docker-socket-binding

这归结为添加

代码语言:javascript
复制
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]

到运行程序配置中的[runners.docker]部分。

问题是,你为什么需要码头?根据https://github.com/localstack/localstack,将LAMBDA_EXECUTOR设置为local

在本地机器上的临时目录中运行Lambda函数

这应该是解决问题的最佳方法,不会影响运行主机的安全性。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66281146

复制
相关文章

相似问题

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