我想要实现的目标:
通过我自己定义的 Github Runner对 React App 进行完全自动化部署,在分支上进行任何提交live
,该 Runner 正在运行Ubuntu Server 20.04
,npm 6.14.8
我目前拥有的:
autodeploy.yml
name: AutoDeploy
on:
push:
branches: [live]
jobs:
build:
name: Deploy Client App
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12'
- name: Fetch latest version
uses: actions/checkout@v1
- name: Install Dependencies
run: npm install
working-directory: ./Code/client-app-react
- name: Build project
run: npm run build
working-directory: ./Code/client-app-react
- name: Copy build to webserver
run: sudo cp -r ./ /var/www/domains/react.app.public
working-directory: ./Code/client-app-react/build
- name: Copy .htaccess to webserver
run: sudo cp .htaccess /var/www/domains/react.app.public/.htaccess
working-directory: ./Media/Server
一切似乎都正常,直到我进入复制/粘贴步骤
sudo cp -r ./ /var/www/domains/react.app.public
我收到的信息是:
sudo: no tty present and no askpass program specified
Error: Process completed with exit code 1.
我不知道 AskPass 是什么,也不知道如何打开 TTY。我期望它能按照这篇文章的方式工作:
https://stackoverflow.com/questions/57830375/github-actions-workflow-error-permission-denied
如何从 Github Action 配置文件执行特权或提升的命令autodeploy.yml
?
答案1
对此,有两种可能的解决方案:
更改
/var/www/domains/react.app.public
目录的权限,以便用户可以写入目录。然后您可以sudo
从命令中删除。配置
sudo
执行命令时不询问密码。这可以通过以下行来实现/etc/sudoers.d/autodeploy
user ALL = (root) NOPASSWD: /usr/bin/cp -r ./ /var/www/domains/react.app.public
user ALL = (root) NOPASSWD: /usr/bin/cp .htaccess /var/www/domains/react.app.public/.htaccess
这里user
是运行部署过程的用户的名称。