简体   繁体   English

(GitHub 操作,上传工件)尽管授予了完全权限,但访问被拒绝尝试上传文件

[英](GitHub Actions, Upload artifact) Access denied trying to upload a file despite giving it full permissions

Describe the problem描述问题

I am making an action that runs API tests from a docker container, which generates a report.html.我正在执行一个从 docker 容器运行 API 测试的操作,该容器生成一个 report.html。 This report is saved into a docker volume.此报告保存到 docker 卷中。 Within the action, after the report is created, I attempt to use actions/upload-artifact on report.html, using the path to its place in the volume on the host machine.在操作中,创建报告后,我尝试在 report.html 上使用 actions/upload-artifact,使用其在主机卷中的位置的路径。

The problem is I get Error: EACCES: permission denied, lstat /path/to/report.html when the action attempts to do this.问题是当操作尝试执行此操作时Error: EACCES: permission denied, lstat /path/to/report.html我收到Error: EACCES: permission denied, lstat /path/to/report.html

I've tried to solve this by doing sudo chmod ugo+rwx /path/to/report.html before using the action but it changed nothing.我试图通过在使用该操作之前执行sudo chmod ugo+rwx /path/to/report.html来解决此问题,但它没有任何改变。 I think running the action with sudo would work but that doesn't seem to be supported.我认为使用 sudo 运行该操作会起作用,但这似乎不受支持。

How to reproduce如何繁殖

Reproducing an analogous example where I just create a test.txt file in the volume.重现一个类似的例子,我只是在卷中创建一个 test.txt 文件。 github action looks like this: github 操作如下所示:

name: Action
on:
  push:
    
jobs:
  example:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Compose Containers and Run 
        run: |
          docker-compose up --abort-on-container-exit
      
      - name: Fix permissions 
        run: |
          sudo chmod ugo+rwx /var/lib/docker/volumes/example_reports/_data/test.txt
        
      - name: Upload report.html
        uses: actions/upload-artifact@v2
        with:
          name: test.txt
          path: /var/lib/docker/volumes/example_reports/_data/test.txt

Dockerfile is simply: Dockerfile 很简单:

FROM ubuntu

ENTRYPOINT [ "/bin/bash", "-c" ]

And doker compose:和 doker 组成:

version: "3.7"

services:
  example:
    build:
      context: .
    volumes:
      - reports:/home/reports
    command: ["touch /home/reports/test.txt"]

volumes:
  reports:

Your docker container is running as root and therefore creating the file as root.您的 docker 容器以 root 身份运行,因此以 root 身份创建文件。

You can change that by specifying您可以通过指定来更改它

    user: '1000:1000'

for your service in your docker-compose file.为您的 docker-compose 文件中的服务。

Turns out I was thinking about this too hard.原来我想得太难了。 All I needed to do to get upload-artifact to work was copy the file out of the volume directory first.为了让上传工件工作,我需要做的就是首先将文件从卷目录中复制出来。

In the action file, instead of trying to fix permissions, simply do this after composing up the containers:在操作文件中,不要尝试修复权限,只需在组合容器后执行此操作:

 - name: Copy out file from volume
   run: |
     sudo cp /var/lib/docker/volumes/example_reports/_data/test.txt /home/
  
  - name: Upload report.html
    uses: actions/upload-artifact@v2
    with:
      name: test.txt
      path: /home/test.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 github 操作运行时 Docker 守护程序访问被拒绝 - Docker daemon access denied while running from github actions 为什么 Docker 文件系统权限在 GitHub 操作上表现不同(服务器上的权限被拒绝) - Why are Docker filesystem permissions behaving differently on GitHub Actions (Permission denied on server) GitHub 操作工作流程错误:权限被拒绝 - GitHub Actions workflow error: Permission denied 尝试自动上传文件时出现 Curl 错误 - http 没有此类文件 - Curl error while trying to automate file upload - http no such file 上传到github后的docker卷? - docker volume after upload to github? 在具有 root 权限的 Docker 中,错误“EACCES:权限被拒绝,打开“/root/.config/configstore/bower-github.json”,尽管该文件可以访问 - In Docker with root, error `EACCES: permission denied, open '/root/.config/configstore/bower-github.json'` despite that file being accessible 权限被拒绝:Github 操作上的共享卷写入和读取失败 - Permission denied: Shared volume write and Read failing on Github Actions Selenium 如何访问 Github Actions 上的 capybara 服务器? - How selenium access capybara server on Github Actions? 如何将文件上传到kubernetes集群以供我的Apps访问? - How to upload a file to kubernetes cluster for my Apps to access it? Docker 推送给出“blob 上传未知” - Docker push giving “blob upload unknown”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM