在CircleCI上更改USER

3 circleci circleci-2.0

这让我丧命,找不到答案...我只是想将当前用户从root更改为预先创建的名为“ node”的用户,给定的是“ node:9”基本映像。

这是我现在拥有的.circleci / config.yml文件:

# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/node:9

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/mongo:3.4.4

    working_directory: ~/repo

    steps:
      - checkout
      - restore_cache:  # Download and cache dependencies
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: sudo npm install --loglevel=warn

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      # run tests!
      - run: echo "here are the tests"
Run Code Online (Sandbox Code Playgroud)

使用Docker的方法如下:

RUN echo "newuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN useradd -ms /bin/bash newuser
USER newuser
Run Code Online (Sandbox Code Playgroud)

但我相信node:9图像带有一个预先创建的用户,因此可以很简单:

 USER node
 WORKDIR /home/node/app
Run Code Online (Sandbox Code Playgroud)

但是我找不到任何有关如何从CircleCI的root用户更改为非root用户的文档。

以下是一些文档:https : //circleci.com/docs/2.0/configuration-reference/

Edd*_*die 5

您可以使用userimage部分的参数选择要在docker映像中运行的可用用户。

docker:
  - image: circleci/node:9
    user: node
Run Code Online (Sandbox Code Playgroud)