小编Lea*_*ner的帖子

ansible 返回“无法导入所需的 Python 库(用于 Python 的 Docker SDK:docker (Python >= 2.7) 或 docker-py (Python 2.6))

我在 ubuntu 中运行我的服务器:

+ sudo cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.6 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.6 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
Run Code Online (Sandbox Code Playgroud)

我使用ansible,当我运行它时,出现以下错误:

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on dd63315fad06's Python /usr/bin/python. Please read module documentation and install in the appropriate location, for example via `pip install docker` or `pip install docker-py` (Python 2.6). The error was: No …
Run Code Online (Sandbox Code Playgroud)

ansible ansible-2.x ansible-facts ansible-inventory

20
推荐指数
3
解决办法
3万
查看次数

docker-compose healthcheck 无法按照预期先运行容器然后运行容器 B 的方式工作

我正在使用 docker compose 来运行几个相互依赖的服务。这是 docker-compose 的一部分:

  backend:
    build: .
    command: bash -c "npm run build && npm start"
    ports: 
      - "3015:3015"
    depends_on:
      - couchdb
      - redis
      - uds-mock-server
    volumes:
      - /app/node_modules
      - .:/app
    user: root
  api-test:
    restart: always 
    build: .
    depends_on:
      - backend
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3015/readiness"]
      interval: 200s
      timeout: 200s
      retries: 5
    user: root
Run Code Online (Sandbox Code Playgroud)

如你所见,我在那里有两个服务,后端应该首先运行,服务器需要准备好然后 api-test 可以启动。后端有一个端点: localhost:2015/readiness 并且只要它返回 200 就可以开始 api 测试。当我在构建订单时运行,所以后端首先是 api-mock,但是当 docker compose 开始运行它们时,api-test 运行得更快,因为它依赖于后端准备好它失败。

基于以下几点:

Docker Compose 在启动 Y 之前等待容器 X

Composer …

docker docker-compose

14
推荐指数
3
解决办法
2万
查看次数

docker compose 命令:服务中“命令”选项的插值格式无效

在我的 docker compose 中,我有以下命令:

command: bash -c 'while [[ "$(curl --connect-timeout 2 -s -o /dev/null -w ''%{http_code}'' https://mock-server:4000/readiness)" != "200" ]]; do echo ..; sleep 5; done; echo backend is up; npm start'
Run Code Online (Sandbox Code Playgroud)

等待模拟服务器启动,然后为后端运行启动命令:

  backend:
    build: 
        context: ./test
        dockerfile: Dockerfile
    command: bash -c 'while [[ "$(curl --connect-timeout 2 -s -o /dev/null -w ''%{http_code}'' https://mock-server:4000/readiness)" != "200" ]]; do echo ..; sleep 5; done; echo backend is up; npm start'
    ports: 
      - "3015:3015"
    depends_on:
      - couchdb
      - redis
      - mock-server
    user: …
Run Code Online (Sandbox Code Playgroud)

bash docker docker-compose

11
推荐指数
1
解决办法
3391
查看次数

如何检查docker容器中是否存在文件然后复制它

我正在使用 docker cp 将正在运行的容器中的文件复制到主机服务器(其中包含正在运行的 docker 容器),如下所示:

docker cp $containerId:/tmp/allure-results $WORKSPACE/allure
Run Code Online (Sandbox Code Playgroud)

这显然仅在文件存在时才有效,但有时在创建文件之前会有延迟。我如何确定文件是否存在然后复制它,如果不等到它存在并且应该发生 cp 。类似的东西:

if allure exits then 
 docker cp $containerId:/tmp/allure-results $WORKSPACE/allure
else
 wait for 5 second and check again
Run Code Online (Sandbox Code Playgroud)

是否可以?

docker

5
推荐指数
1
解决办法
5344
查看次数

npm 审核返回 400 错误请求

当我运行 npm 审计时我得到

npm audit
npm ERR! code ENOAUDIT
npm ERR! audit Your configured registry (http://registry.npmjs.org/) may not support audit requests, or the audit endpoint may be temporarily unavailable.
npm ERR! audit The server said: <html>
npm ERR! audit <head><title>400 Bad Request</title></head>
npm ERR! audit <body>
npm ERR! audit <center><h1>400 Bad Request</h1></center>
npm ERR! audit <hr><center>cloudflare</center>
npm ERR! audit </body>
npm ERR! audit </html>
npm ERR! audit
Run Code Online (Sandbox Code Playgroud)

我尝试了以下方法

delete pack lock
npm update
npm i
Run Code Online (Sandbox Code Playgroud)

但它仍然发生,我的 npm 版本是 6.14.11,我的节点版本是 v14.16.0 …

npm npm-install npm-audit

5
推荐指数
1
解决办法
6772
查看次数

process.hrtime 返回不匹配的秒和毫秒

我使用 process.hrtime() 来计算进程花费的时间(以秒和毫秒为单位),如下所示:

router.post(
  "/api/result-store/v1/indexing-analyzer/:searchID/:id",
  async (req, res) => {

    var hrstart = process.hrtime();

    //some code which takes time

    hrend = process.hrtime(hrstart);
    console.info("Execution time (hr): %ds %dms", hrend[0], hrend[1] / 1000000);

  }
);
Run Code Online (Sandbox Code Playgroud)

我遵循以下代码:

https://blog.abelotech.com/posts/measure-execution-time-nodejs-javascript/

所以我希望得到以毫秒和秒为单位的匹配时间,但这是我得到的:

Execution time (hr): 54s 105.970357ms
Run Code Online (Sandbox Code Playgroud)

所以这很奇怪,因为当我将 54 秒转换为毫秒时,我得到了 54000,所以我不知道这个“105.970357ms”来自哪里。我的代码有什么问题吗?为什么我会看到这种不匹配?

node.js

2
推荐指数
1
解决办法
2368
查看次数

es6中使用map过滤并返回一个新对象

我有以下代码:

      allDesignDocs.rows.forEach((row: any) => {
        if (!designDocsName.includes(row.id.replace("_design/", ""))) {
          toBeRemoved = [{ _id: row.id, _rev: row.value.rev, "_deleted": true }, ...toBeRemoved];
        }

      });
Run Code Online (Sandbox Code Playgroud)

效果很好。不过我想使用就地更新方法。所以我选择了map而不是foreach:

  var test = allDesignDocs.rows.map((row: any) => {
    if (!designDocsName.includes(row.id.replace("_design/", ""))) {
      return { _id: row.id, _rev: row.value.rev, "_deleted": true };
    }

  });
Run Code Online (Sandbox Code Playgroud)

因此,当条件不满足时,上面会返回包含 undefined 的数组。我只希望数组包含从 if 内部返回的值并忽略所有未定义的值。我知道我可以循环遍历结果并清理它,但这不是一个干净的方法。es6有没有函数可以提供上述功能?

javascript ecmascript-6

2
推荐指数
1
解决办法
1555
查看次数

检查字符串是否存在于 bash 的字符串数组中

我知道如何在 bash 中比较两个字符串:

if [ "$build_type" = "devite" ]; then
  echo "building'"
fi
Run Code Online (Sandbox Code Playgroud)

但我需要的是检查“$build_type”是否在 [“devite”, “relite”] 中

所以类似这样的事情:

if [ "$build_type" in ["devite", "relite"] ]; then
  echo "building'"
fi
Run Code Online (Sandbox Code Playgroud)

任何人都可以阐明这一点吗?

bash

2
推荐指数
2
解决办法
4143
查看次数

使用 chai 检查 typescript/nodejs 中的异常不起作用

我在打字稿代码中使用 chai 断言测试我的简单函数时遇到问题

我有:

    public async test1(){
     throw (new Error(COUCH_CONNECTION_ERROR.message));
    }
Run Code Online (Sandbox Code Playgroud)

其中沙发连接错误是这样定义的:

export const COUCH_CONNECTION_ERROR: IErrorModel = {
  code: "couch_connection_error",
  message: "Unable to connect to Couchdb.",
};
Run Code Online (Sandbox Code Playgroud)

现在我这样写了一个测试:

    it("test", ()=>{

    console.log(obj.test1());
    expect(obj.test1()).to.throw(Error, COUCH_CONNECTION_ERROR.message)
    console.log(`ccccccccccccccccc`);
})
Run Code Online (Sandbox Code Playgroud)

所以当我运行测试时我得到

AssertionError: expected {} to be a function
Run Code Online (Sandbox Code Playgroud)

谁能帮助理解我的测试出了什么问题?

unit-testing node.js chai typescript

2
推荐指数
1
解决办法
2253
查看次数

模板语言和掌舵

我是 kubernetes 和 helm 的新手。我开始使用 helm 并且我有以下代码段:

{{- $image := printf "%s/%s:%s" $.Values.global.repository $.Values.global.images.xxx.image $.Values.global.images.xxx.tag -}}
apiVersion: v1
kind: Pod
metadata:
  name: xxxx-test-ready
  labels:
    app: xxxxx-test
    app.kubernetes.io/name: xxxxx-test
    helm.sh/chart: authsvc
    release: {{ $.Release.Name }}
    app.kubernetes.io/instance: {{ $.Release.Name }}
    app.kubernetes.io/managed-by: {{ $.Release.Service }}
Run Code Online (Sandbox Code Playgroud)

我的问题在这里:

  {{- $image := printf "%s/%s:%s" $.Values.global.repository $.Values.global.images.xxx.image $.Values.global.images.xxx.tag -}}
Run Code Online (Sandbox Code Playgroud)

我想我明白它的作用:基本上它创建图像规范并将其添加到名为 image 的 var 以供以后使用。但是我对这种模板语言感到不舒服,我什至不确定它是 erlang 还是 golang。对这种模板语言充满信心的最佳起点是什么?我应该学习golang吗?

kubernetes kubernetes-helm

1
推荐指数
1
解决办法
1711
查看次数

当我尝试 python3 版本时,它不能作为命令使用

我有以下泊坞窗文件:

FROM ubuntu:latest

RUN apt-get update \
  && apt-get install -y python3-pip python3-dev \
  && cd /usr/local/bin \
  && ln -s /usr/bin/python3 python3 \
  && pip3 install --upgrade pip
USER root
COPY scripts scripts
RUN ls
RUN pwd
RUN chmod +x ./scripts/functional_test_cli/baft.py
COPY tests tests
RUN pip3 install Pytest
RUN pip3 install pytest-json-report
RUN pip3 install Tavern
RUN pip3 install allure-pytest
RUN pip3 install pytest-pythonpath
RUN pip install --upgrade setuptools
RUN which python

RUN python3 version
CMD ["python3", "./scripts/functional_test_cli/baft.py"]
Run Code Online (Sandbox Code Playgroud)

因此,当涉及到这一行 …

python python-3.x docker

0
推荐指数
1
解决办法
2146
查看次数