nektos / act

Run your GitHub Actions locally 🚀
https://nektosact.com
MIT License
54.81k stars 1.37k forks source link

act fails where GitHub CI succeeds #2095

Open dabrahams opened 11 months ago

dabrahams commented 11 months ago

Bug report info

% act --bug-report
act version:            0.2.54
GOOS:                   darwin
GOARCH:                 arm64
NumCPU:                 10
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
    $HOME/.docker/run/docker.sock
Config files:
    /Users/dave/.actrc:
        -P ubuntu-latest=catthehacker/ubuntu:act-latest
        -P ubuntu-22.04=catthehacker/ubuntu:act-22.04
        -P ubuntu-20.04=catthehacker/ubuntu:act-20.04
        -P ubuntu-18.04=catthehacker/ubuntu:act-18.04
Build info:
    Go version:            go1.21.4
    Module path:           command-line-arguments
    Main version:
    Main path:
    Main checksum:
    Build settings:
        -buildmode:           exe
        -compiler:            gc
        -ldflags:             -X main.version=0.2.54
        DefaultGODEBUG:       panicnil=1
        CGO_ENABLED:          1
        CGO_CFLAGS:
        CGO_CPPFLAGS:
        CGO_CXXFLAGS:
        CGO_LDFLAGS:
        GOARCH:               arm64
        GOOS:                 darwin

Error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Command used with act

act --container-architecture linux/amd64 -v

Describe issue

Note that Docker IS in fact running

act fails on my local machine but the workflow succeeds in Github Linux CI

See attached act.log

Link to GitHub repository

https://github.com/dabrahams/SPMBuildToolSupport/actions/runs/6901849884

Workflow content

---
name: Build and test

"on":
  push:
    branches: [main, rewrite]
    paths-ignore:
      - "Docs/**"
      - "**.md"
      - "README.md"
      - "LICENSE"
      - ".gitignore"
  pull_request:
    branches: ["**"]
    paths-ignore:
      - "Docs/**"
      - "**.md"
      - "README.md"
      - "LICENSE"
      - ".gitignore"

jobs:

  devcontainer:
    name: "Devcontainer: ${{ matrix.os }}/${{ matrix.configuration }}"
    strategy:
      matrix:
        os: [ubuntu-latest]
        configuration: [debug]

    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3

      - name: Build and Test
        uses: devcontainers/ci@v0.3
        with:
          runCmd: swift test -c ${{ matrix.configuration }}

  native:
    name: "Native: ${{ matrix.os }}/${{ matrix.configuration }}"
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, ubuntu-latest, windows-latest]

        configuration: [debug]

        include:
          # Default values to add
          - shell: 'bash -eo pipefail {0}'

          # Overrides for the defaults
          - shell: pwsh
            os: windows-latest

    runs-on: ${{ matrix.os }}

    defaults:
      run:
        shell: ${{ matrix.shell }}

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

      - name: Setup Swift (Unices)
        if: ${{ matrix.os != 'windows-latest' }}
        uses: 'swift-actions/setup-swift@v1'
        with:
          version: 5.8

      - name: Setup Swift (Windows)
        if: ${{ matrix.os == 'windows-latest' }}
        uses: 'compnerd/gha-setup-swift@main'
        with:
          github-repo: thebrowsercompany/swift-build
          release-asset-name: installer-amd64.exe
          release-tag-name: 20231010.3
          github-token: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and Test (${{ matrix.configuration }})
        run: swift test -c ${{ matrix.configuration }}

Relevant log output

(too long; please see attached file)

Additional information

No response

SyntaxSugarNet commented 7 months ago

Facing the same issue using act and devcontainers/ci.

The problem is that the mounted workspace in the devcontainers/ci docker container is from the host file system.

act is creating its own docker container with the workspace copied into its container's file system. devcontainers/ci docker container is not created inside act's container (no docker-in-docker), but besides it. Therefore devcontainers/ci's workspace mount is not pointing to act's workspace copy, but to the original workspace on the host file system.

This is why the devcontainer cannot start. Path /var/run/act/workflow/ exists in act's container but not on your host system:

| [2023-11-17T09:14:55.111Z] Start: Run: docker run 
...
--mount type=bind,src=/var/run/act/workflow/outputcmd.txt,dst=/mnt/github/output
...
| [2023-11-17T09:14:55.386Z] docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /var/run/act/workflow/outputcmd.txt.

This can be worked around by creating the files under /var/run/act/workflow/ on the host filesystem, so the devcontainer can start, BUT as the devcontainers/ci step will work on a different file system from all the other steps in the job, running it with act will be possibly pointless.

Not sure how act should handle these kind of scenarios, but maybe if instead of copying the workspace into its container it could create a temporary copy of the workspace and the necessary files (like /var/run/act/workflow/) on the host file system. Then could bind mount this copy into all of the containers created for the given job run and all the steps of the job would work on the same copied workspace on the host file system.

gund commented 4 months ago

I've hit the same issue as @SyntaxSugarNet while trying to run devcontainers/ci action with act on WSL:

| [2024-06-18T16:01:17.833Z] docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /var/run/act/workflow/outputcmd.txt.
zanettea commented 2 months ago

A workaround I found is to use custom a image that adds the dockerd daemon and then adding a step before devcontainer/ci to start docker-in-docker:

[...]

      - name: optionally start DinD for act (local testing)
        if: env.ACT
        run: |
          dockerd -H unix:///var/run/dind.sock & sleep 5;
          echo "DOCKER_HOST=unix:///var/run/dind.sock" >>${GITHUB_ENV}

[....]

The command line: act -s GITHUB_TOKEN="$(gh auth token)" --container-options --privileged -P ubuntu-latest=ghcr.io/corvina-r-d/ubuntu:act-22.04

However it would be nice if docker-in-docker were a native options of act (act --dind ... )