Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

act does not create separate containers for matrix builds with reusable workflows #2003

Closed
Andy4495 opened this issue Sep 11, 2023 · 1 comment · Fixed by #2015
Closed

act does not create separate containers for matrix builds with reusable workflows #2003

Andy4495 opened this issue Sep 11, 2023 · 1 comment · Fixed by #2015
Labels
kind/bug Something isn't working

Comments

@Andy4495
Copy link
Contributor

Bug report info

act version:            0.2.50
GOOS:                   darwin
GOARCH:                 amd64
NumCPU:                 8
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
	/var/run/docker.sock
	$HOME/.docker/run/docker.sock
Config files:           
	/Users/andy/.actrc:
		-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest
		-P ubuntu-20.04=ghcr.io/catthehacker/ubuntu:act-20.04
		-P ubuntu-18.04=ghcr.io/catthehacker/ubuntu:act-18.04
Build info:
	Go version:            go1.21.0
	Module path:           command-line-arguments
	Main version:          
	Main path:             
	Main checksum:         
	Build settings:
		-buildmode:           exe
		-compiler:            gc
		-ldflags:             -X main.version=0.2.50
		DefaultGODEBUG:       panicnil=1
		CGO_ENABLED:          1
		CGO_CFLAGS:           
		CGO_CPPFLAGS:         
		CGO_CXXFLAGS:         
		CGO_LDFLAGS:          
		GOARCH:               amd64
		GOOS:                 darwin
		GOAMD64:              v1
Docker Engine:
	Engine version:        24.0.5
	Engine runtime:        runc
	Cgroup version:        2
	Cgroup driver:         cgroupfs
	Storage driver:        overlay2
	Registry URI:          https://index.docker.io/v1/
	OS:                    Docker Desktop
	OS type:               linux
	OS version:            
	OS arch:               x86_64
	OS kernel:             5.15.49-linuxkit-pr
	OS CPU:                4
	OS memory:             7859 MB
	Security options:
		name=seccomp,profile=unconfined
		name=cgroupns

Command used with act

act -j call-reusable-workflow

Describe issue

When using act with reusable workflows called with a matrix strategy, act does not create separate docker containers for each matrix combination; it tries to run them all in the same container which generates an error (see log output below).

If I run the same matrix strategy in a standalone workflow, act creates a separate docker container for each matrix combination and the workflow runs successfully.

Link to GitHub repository

https://github.com/Andy4495/act-workflow-test

Workflow content

# The "caller" workflow
name: Call Reusable Workflow

on: 
  push:
  workflow_dispatch:

jobs:
  call-reusable-workflow: 
    strategy:
      matrix:
        include:
          - message: test1
          - message: test2
          - message: test3
          - message: test4
 
    name: call-reusable-workflow
    uses: Andy4495/act-workflow-test/.github/workflows/reusable-flow.yml@main
    with:
      message: ${{ matrix.message }}

---

# The "called" (reusable) workflow
name: reusable-workflow

on: 
  workflow_call:
    inputs:
      message:
        description: Message to display
        required: true
        type: string

jobs:
  reusable-workflow: 
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Print the message
        run: |
          echo Test reusable workflow ${{ inputs.message }}

Relevant log output

Error: failed to create container: 'Error response from daemon: Conflict. The container name "/act-call-reusable-workflow-reusable-workflow-reusable-workflow-c7535ef5a84abfd1f2412cceca72bd226072ccb44b16a59787972320d9cb1a2d" is already in use by container "d0baad951ea56daf6bd3097af098d08b22d726733e0e4a54120fe40c357874a0". You have to remove (or rename) that container to be able to reuse that name.'

Additional information

As mentioned above, this works fine with standalone workflows.

@Andy4495 Andy4495 added the kind/bug Something isn't working label Sep 11, 2023
@Andy4495
Copy link
Contributor Author

I found the problem and it looks like the fix is pretty simple.

The container name generated for reusable workflows is not unique, so each matrix run was trying to use the same container. The code was using the non-unique caller job name instead of the unique name (with the -1, -2, ... appended).

So the fix should be in runner/run_context.go function String().

Change this:

name = fmt.Sprintf("%s/%s", rc.caller.runContext.Run.JobID, name)

To this:

name = fmt.Sprintf("%s/%s", rc.caller.runContext.Name, name)

I'll open a pull request after I run a few more tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant