gpt4 book ai didi

circleci - 更改 CircleCI 上的用户

转载 作者:行者123 更新时间:2023-12-02 19:08:08 26 4
gpt4 key购买 nike

这简直要了我的命,找不到答案...我只想将当前用户从 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

但我相信 node:9 图像带有预先创建的用户,所以这可能很简单:

 USER node
WORKDIR /home/node/app

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

这里有一些文档: https://circleci.com/docs/2.0/configuration-reference/

最佳答案

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

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

关于circleci - 更改 CircleCI 上的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50320263/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com