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

feat(runs_on): permit using array of string to select specific runner #1740

Merged

Conversation

NikitaCOEUR
Copy link
Contributor

Check List

Permit using array of string to select GitHub runners on which run jobs.
Necessary to select self hosted runners.

@NikitaCOEUR NikitaCOEUR changed the title feat(runs_on): permit using array of string to select specific githug… feat(runs_on): permit using array of string to select specific runner Jul 8, 2024
@suzuki-shunsuke
Copy link
Owner

suzuki-shunsuke commented Jul 8, 2024

Your commits aren't singned.

[X ] All commits are signed
This repository enables Require signed commits, so all commits must be signed

image

The base branch requires all commits to be signed. Learn more about signing commits.

@NikitaCOEUR
Copy link
Contributor Author

Hi,

I saw that we could sign with our SSH key. I thought that since I was using my SSH key to clone the repo, the associated commits were automatically signed. But indeed, a bit of configuration was missing...

I have redone my commits as indicated in the procedure and force-pushed these two rebased commits with a signature.

I would like to ensure that all the changes I have made work correctly before merging them. It is quite complicated to test due to all the internal references to suzuki-shunsuke/tfaction@main. I saw that we could use a GitHub Action to create the PR and point to it in our workflows?

Copy link

github-actions bot commented Jul 8, 2024

🚀 Pull Request Branch was created or updated

Build link

The pull request branch pr/1740 was created or updated.

You can try this pull request in your workflows by changing tfaction version to pr/1740.

e.g.

- uses: suzuki-shunsuke/tfaction/setup@pr/1740

To update the pull request branch again, please run the workflow.

@suzuki-shunsuke
Copy link
Owner

@NikitaCOEUR You can test this pull request using the version pr/1740.

@NikitaCOEUR
Copy link
Contributor Author

@NikitaCOEUR You can test this pull request using the version pr/1740.

Yes thanks I saw that but I couldn't find any time for that now. Maybe next week!

@NikitaCOEUR
Copy link
Contributor Author

Hi,

I've added a new commit to fix an issue I introduced where the runs_on field was no longer optional in certain configurations. This should restore the previous behavior.

Additionally, I've retested everything, but I still encounter an error that I don't understand:
image

 bash: /home/runner/work/_actions/suzuki-shunsuke/github-action-terraform-init/71673ab29266f67c4470773675e087e9a4dda3c5/main.sh: No such file or directory

Despite this, the changes I've made seem to have the desired effect:

content of my tfaction-root.yaml :

target_groups:

# Target group 1 with specific self hosted runner (specified via array of strings)
- working_directory: terraform/env-TF-ACTION-TEST/
  target: TF-ACTION-TEST/
  environment: TF-ACTION-TEST
  runs_on:
    - self-hosted
    - runners
  secrets: # GitHub Secrets
  - env_name: AWS_ACCESS_KEY_ID # Environment variable name
    secret_name: BACKEND_ACCESS_KEY_ID
  - env_name: AWS_SECRET_ACCESS_KEY # Environment variable name
    secret_name: BACKEND_SECRET_KEY
  - env_name: SOPS_AGE_KEY
    secret_name: SOPS_AGE_KEY

# Target group 2 with specified runners (with string)
- working_directory: terraform/env-TF-ACTION-TEST2/
  target: TF-ACTION-TEST2/
  environment: TF-ACTION-TEST
  runs_on: ubuntu-latest
  secrets: # GitHub Secrets
  - env_name: AWS_ACCESS_KEY_ID # Environment variable name
    secret_name: BACKEND_ACCESS_KEY_ID
  - env_name: AWS_SECRET_ACCESS_KEY # Environment variable name
    secret_name: BACKEND_SECRET_KEY
  - env_name: SOPS_AGE_KEY
    secret_name: SOPS_AGE_KEY

# Target group 3 without any runs_on specified
- working_directory: terraform/env-TF-ACTION-TEST3/
  target: TF-ACTION-TEST3/
  environment: TF-ACTION-TEST
  secrets: # GitHub Secrets
  - env_name: AWS_ACCESS_KEY_ID # Environment variable name
    secret_name: BACKEND_ACCESS_KEY_ID
  - env_name: AWS_SECRET_ACCESS_KEY # Environment  variable name
    secret_name: BACKEND_SECRET_KEY
  - env_name: SOPS_AGE_KEY
    secret_name: SOPS_AGE_KEY

Target group 1 with specific self hosted runner (specified via array of strings)

image

Target group 2 with specified runners (with string)

image

Target group 3 without any runs_on specified

image

Could you please help me with this issue?

Thanks!

Copy link

🚀 Pull Request Branch was created or updated

Build link

The pull request branch pr/1740 was created or updated.

You can try this pull request in your workflows by changing tfaction version to pr/1740.

e.g.

- uses: suzuki-shunsuke/tfaction/setup@pr/1740

To update the pull request branch again, please run the workflow.

@suzuki-shunsuke
Copy link
Owner

suzuki-shunsuke commented Jul 15, 2024

 bash: /home/runner/work/_actions/suzuki-shunsuke/github-action-terraform-init/71673ab29266f67c4470773675e087e9a4dda3c5/main.sh: No such file or directory

I'm not sure why this error occurred. main.sh should exist.

    - run: bash ${{ github.action_path }}/main.sh

https://github.com/suzuki-shunsuke/github-action-terraform-init/blob/71673ab29266f67c4470773675e087e9a4dda3c5/action.yaml#L28

This error may occur if you run this action in a container, but I guess you didn't do that.

@NikitaCOEUR
Copy link
Contributor Author

Hmm ..
Indeed, I am using containers to run my GitHub actions.
That seems to be the problem.

I just saw a workaround suggested by someone: actions/runner#716 (comment)

I'm not sure if that would make sense here?

@suzuki-shunsuke
Copy link
Owner

suzuki-shunsuke commented Jul 15, 2024

Could you allow me to push commits to the feature branch?

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork

e.g. aquaproj/aqua-registry#24089

Maintainers are allowed to edit this pull request.
image

@NikitaCOEUR
Copy link
Contributor Author

So, I had to transfer the ownership of the fork to my user account to be able to activate this option.

@suzuki-shunsuke
Copy link
Owner

So, I had to transfer the ownership of the fork to my user account to be able to activate this option.

Oh, really. I didn't know that.
The document seems not to refer that.

Anyway, thank you for your update.

Copy link

🚀 Pull Request Branch was created or updated

Build link

The pull request branch pr/1740 was created or updated.

You can try this pull request in your workflows by changing tfaction version to pr/1740.

e.g.

- uses: suzuki-shunsuke/tfaction/setup@pr/1740

To update the pull request branch again, please run the workflow.

@NikitaCOEUR
Copy link
Contributor Author

NikitaCOEUR commented Jul 16, 2024

The purpose of this pull request seems fine.

However, I have issues with the Taskfile combined with the execution of my GitHub Actions in a container.

I use a Taskfile at the root of my project as a wrapper for Terraform commands. This is used when a task command is executed from the root or in one of the subfolders. But they have implemented a safeguard based on directory ownership; task ascends through parent directories and stops if it does not find a Taskfile or as soon as the owner of the current directory changes compared to the previous one(https://github.com/go-task/task/blob/573949573968cc7056b98e0fdbee1d145ad869a9/taskfile/taskfile.go#L149) ... And this is the case since the containers on GitHub Actions are executed with the root user...

Also, the repo is cloned on the runner, and the volume is mounted in the container. When accessing the repo's folders, the root folder of the repo belongs to the user running Docker, but the subfolders belong to the user of the container (root).

@NikitaCOEUR
Copy link
Contributor Author

It seems that a workaround exists : actions/checkout#47 (comment)

I'll test that tomorrow.

@suzuki-shunsuke
Copy link
Owner

The purpose of this pull request seems fine.

Thank you for testing. It looks good.
Seems like your issue has nothing to do with tfaction.

@NikitaCOEUR
Copy link
Contributor Author

It seems that a workaround exists : actions/checkout#47 (comment)

I'll test that tomorrow.
Doesn't work )=

But I have a workaround for my problem with Taskfile, which I posted in an issue: go-task/task#1683 (comment)

However, this problem appears again with the git command. I just opened an issue here: suzuki-shunsuke/github-action-terraform-init#19

@suzuki-shunsuke
Copy link
Owner

However, this problem appears again with the git command. I just opened an issue here: suzuki-shunsuke/github-action-terraform-init#19

The issue was solved.

So everything is fine, right?

@NikitaCOEUR
Copy link
Contributor Author

Do you have some doc to update for this feature ?

@suzuki-shunsuke
Copy link
Owner

Do you have some doc to update for this feature ?

~/repos/src/github.com/suzuki-shunsuke/tfaction-docs main                                                                             07:49:57
$ git grep runs_on
docs/config/tfaction-root-yaml.md:  runs_on: ubuntu-latest # default is "ubuntu-latest". This is useful to use GitHub Actions Self Hosted Runner for the specific provider

https://github.com/suzuki-shunsuke/tfaction-docs/blob/bfc28814d4acfaf8d535de76509affe052a34d8e/docs/config/tfaction-root-yaml.md?plain=1#L177

@suzuki-shunsuke
Copy link
Owner

suzuki-shunsuke commented Jul 18, 2024

✅ I'll update the document.

@NikitaCOEUR
Copy link
Contributor Author

I can't ensure non-regression without running within a container. I have an issue; I don't know if it's caused by the transition from ${{GitHub.action_path}} to $GITHUB_ACTION or if it's on my end.

@suzuki-shunsuke
Copy link
Owner

I have an issue

Could you explain the detail of your issue?

@suzuki-shunsuke
Copy link
Owner

I can't ensure non-regression without running within a container.

I've already confirmed this pr worked fine without a container.

@NikitaCOEUR
Copy link
Contributor Author

I have an issue

Could you explain the detail of your issue?

No, it's on my end then; the problem only occurs when I run without a container. I get an exit code 2 when running Terraform through my wrapper. But it must be due to the context change. I use the action within a container anyway, so there's no problem for me.

}
}
},
"Envs": {
"type": "object",
"description": "environment variables"
},
"RunsOn": {
"type": ["string", "array"],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with JSON Schema, so I'm not sure if this is correct.
I'll look into.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 type can accept an array.

https://json-schema.org/draft/2020-12/json-schema-core

"type": ["object", "boolean"],

But I think array is ambiguous because the type of elements is unknown. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is better :

"RunsOn": {
  "oneOf": [
    {
      "type": "string"
    },
    {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    {
      "type": "null"
    }
  ],
  "description": "The type of runner that the job will run on"
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://json-schema.org/understanding-json-schema/reference/combining#anyOf

Should we use anyOf?

    "RunsOn": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      ],
      "description": "The type of runner that the job will run on"
    }

Copy link
Contributor Author

@NikitaCOEUR NikitaCOEUR Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading more, Anyof seems more appropriate. It's more like a OR and not a XOR. So yes definitely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But null type is necessary because we can let empty the property no?

Copy link
Owner

@suzuki-shunsuke suzuki-shunsuke Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If runs_on is not set, the type definition is unrelated. So I don't think we need to add null.
If we want to support the setting which sets null explictly, we need to add null.
But I don't think we need to support null explicitly.

runs_on: null

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. 7290811

@suzuki-shunsuke suzuki-shunsuke merged commit 41b5167 into suzuki-shunsuke:main Jul 19, 2024
12 checks passed
@suzuki-shunsuke suzuki-shunsuke added the bug Something isn't working label Jul 19, 2024
@suzuki-shunsuke suzuki-shunsuke added this to the v1.5.2 milestone Jul 19, 2024
@suzuki-shunsuke
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Use array of tags to select specific self hosted github runners as "runs-on"
2 participants