更改CircleCI上的USER

时间:2018-05-13 20:15:40

标签: 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"

以下是使用Docker执行此操作的方法:

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

但我相信节点:9个图像带有预先创建的用户,因此可能只是:

 USER node
 WORKDIR /home/node/app

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

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

1 个答案:

答案 0 :(得分:2)

您可以使用user部分的image参数选择在泊坞窗图片中运行的可用用户。

docker:
  - image: circleci/node:9
    user: node