node.js - Gitlab-ci.yml Docker 执行器无法运行 shell 命令

标签 node.js gitlab-ci gitlab-ci-runner

我有一个 ubuntu 18.04 服务器,其中安装了 Gitlab-EE。我可以访问我的运行者和许多其他东西。我想使用 GitLab 设置 CI/CD。 那么让我们开始吧:

错误:

enter image description here

我的gitlab-ci.yml

image: docker:latest

services:
- docker:dind

stages:
  - build
  - deploy


build:
  image: node:latest
  stage: build
  tags:
  - api
  before_script:
  - apt-get update -qq
  - apt-get install -y
  script:
    - npm install


deploy:
  services:
    - node:latest
  image: node:latest
  stage: deploy
  tags:
    - api
  script:
    - sudo apt install python-pip
    - sudo pip install docker-compose
    - npm run dc:up ( this makes docker-composer build )

构建阶段成功完成 部署阶段出现错误。

我的 Gitlab 运行器:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Api-Runner"
  url = "XX"
  token = "XXX"
  executor = "docker"
  [runners.docker]
    tls_verify = false
    image = "node:latest"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]

我想安装 docker-composer 来运行我的项目。 如果我删除“sudo”命令,输出将如下所示

enter image description here

最佳答案

看起来您正在使用的镜像 (node:latest) 不包含命令 sudo。它看起来也默认为 root 用户,所以也许你可以完全避免使用 sudo

您可以通过从该镜像启动您自己的容器来探索作业将在其中运行的环境/容器:docker run --rm -ti node:latest bash

如果您可以使用这样的容器手动计算出来,那么您可以在 gitlab-ci.yml 文件中使用该配方。

但请特别记住,gitlab 将为每个作业启动一个新容器,因此您可能还想将 apt-get update -qq 添加到您的 deploy 作业中。

关于node.js - Gitlab-ci.yml Docker 执行器无法运行 shell 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55178245/

相关文章:

docker - Jenkins & GitLab & Docker 集成失败

node.js - 宇宙数据库/nodejs : Entity with the specified id does not exist in the system

javascript - 如何获取进程nodejs的局部范围内的所有变量

gitlab-ci - gitlab CI docker 在 2 分钟后停止

Gitlab 公共(public)运行程序不会运行 Bower,因为在 sudo 中运行

docker - 以 shell 执行器和 docker 镜像为基础的 Gitlab CI

javascript - 带 SSL 的 Azure 辅助角色上的 Node.js 会导致 ERR_SSL_PROTOCOL_ERROR

mysql - 是否可以使用:bind (oracle style) in MYSQL query with Node?

raspberry-pi - 覆盆子pi上kubernetes上的gitlab-runner-找不到容器 “helper”

git - Gitlab CI运行程序无法在docker executor上共享构建源