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

Creating a buildx fails when using matrix strategy on self hosted runners #47

Closed
malkam03 opened this issue Dec 30, 2020 · 6 comments · Fixed by #48 or #49
Closed

Creating a buildx fails when using matrix strategy on self hosted runners #47

malkam03 opened this issue Dec 30, 2020 · 6 comments · Fixed by #48 or #49
Labels

Comments

@malkam03
Copy link

Behavior

When creating a builder instance using GitHub's matrix strategy to build multiple images in parallel the Creating a new builder instance action step fails with an error that looks related to the naming strategy used to create new builders:

📣 Buildx version: 0.4.2
🔨 Creating a new builder instance
  /usr/bin/docker buildx create --name builder-build-linux-images-2 --driver docker-container --driver-opt env.http_proxy=***** --driver-opt env.https_proxy=***** --driver-opt image=******* --buildkitd-flags --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host --use
  existing instance for builder-build-linux-images-2 but no append mode, specify --node to make changes for existing instances
  Error: The process '/usr/bin/docker' failed with exit code 1

Probably related to this line?

Steps to reproduce this issue

  1. Set a workflow with whichever trigger you want
  2. Add a setup-buildx-action to the workflow
  3. Parallelize your job with the matrix strategy
  4. Run on multiple self-hosted runners on the same server

Expected behavior

The action should assign unique names for the builders

Actual behavior

If the builder is being instantiated with the matrix strategy some of the builders will have the same name

Configuration

  • Repository URL (if public): Private repo
  • Build URL (if public): Private repo
name: Main-CI

on:
  push:
    branches: [main]
jobs:
  build-linux-images:
    runs-on: [self-hosted, linux]
    strategy:
      matrix:
        include:
          - package: package1
            directory: docker/linux/package1
          - package: package2
            directory: docker/linux/package2
          - package: package3
            directory: docker/linux/package3
          - package: package4
            directory: docker/linux/package4
    steps:
      -
        uses: actions/checkout@v2
      -
        name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
@malkam03
Copy link
Author

malkam03 commented Dec 30, 2020

Hi @crazy-max, how about changing the name generation from this line and this line to be a random generated number and then verify if the builder exists already with the ls?

Something like:

On main.ts:

    const builderName: string =
      inputs.driver == 'docker' ? 'default' : `${(await buildx.generateNewName(builder-${process.env.GITHUB_JOB}))}`;
    core.setOutput('name', builderName);
    stateHelper.setBuilderName(builderName);

On buildx.ts:

export async  function nameExists(name: string): Promise<boolean> {
  return await exec.exec(`docker`, ['buildx', 'ls'], true).then(res => {
    if (res.stderr != '' && !res.success) {
      throw new Error(`Cannot list builders: ${res.stderr}`);
    }
    for (const line in res.stdout.trim().split(`\n`)) {
      if (line.split(` `)[0] == name) {
        return true;
      }
    }
    return false;
  });
}

function getRandomInt() {
  return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);
}

export async function generateNewName(namePrefix: string): Promise<string> {
  let name = "";
  do {
    name = namePrefix+getRandomInt()
  }  while (await nameExists(name)) ;
  return name;
}

Do you think that this could impact other things?

Note: My javascript is very basic and I hadn't used it in a long time so this probably has a lot of errors but that's the idea.

@crazy-max
Copy link
Member

@malkam03 #48 should fix your issue. You can try with uses: docker/setup-buildx-action@master.

@malkam03
Copy link
Author

malkam03 commented Jan 4, 2021

Hi @crazy-max thanks for the quick fix but it's actually still failing:

Run docker/setup-buildx-action@master
📣 Buildx version: 0.4.2
🔨 Creating a new builder instance
  /usr/bin/docker buildx create --name builder-9a16fd94-0a46-4ecf-af1f-27535a96757c --driver docker-container --buildkitd-flags --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host --use
  builder-9a16fd94-0a46-4ecf-af1f-27535a96757c
🏃 Booting builder
  /usr/bin/docker buildx inspect --bootstrap
  Name:   builder-13419f9d-7e44-4650-bfda-7ac2f90b2ff9
  Driver: docker-container
  
  Nodes:
  Name:      builder-13419f9d-7e44-4650-bfda-7ac2f90b2ff90
  Endpoint:  unix:///var/run/docker.sock
  Status:    running
  Flags:     --allow-insecure-entitlement security.insecure --allow-insecure-entitlement network.host
  Platforms: linux/amd64, linux/386
🛒 Extracting available platforms

So the new naming is correct, but when booting up the builder a different (already existing) name is logged, and doing a docker ps after shows that this specific builder (the first name showed) is not running(it doesn't appear).
Should I report this as a new bug(open a new ticket)?

@crazy-max
Copy link
Member

@malkam03 I will make some changes about this one. Thanks for your feedback.

@crazy-max
Copy link
Member

@malkam03 Ok can you try again with uses: docker/setup-buildx-action@master?

@malkam03
Copy link
Author

malkam03 commented Jan 4, 2021

This works perfect! Thank you @crazy-max 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants