Skip to content

Destroy expired environments#84

Closed
leightjohnson93 wants to merge 1 commit into
pullpreview:masterfrom
leightjohnson93:patch-1
Closed

Destroy expired environments#84
leightjohnson93 wants to merge 1 commit into
pullpreview:masterfrom
leightjohnson93:patch-1

Conversation

@leightjohnson93

@leightjohnson93 leightjohnson93 commented Jul 17, 2024

Copy link
Copy Markdown
Contributor

The scheduled job doesn't seem to actually be cleaning up the expired environments instances. It just logs a message.

#83

@crohr

crohr commented Jul 17, 2024

Copy link
Copy Markdown
Member

@leightjohnson93 this is because the GitHub Token cannot perform the environment deletion. It can only delete deployments. There is a comment in the code about that:

# This requires repository permission, which the GitHub Action token cannot get, so cannot delete the environment unfortunately

@leightjohnson93

leightjohnson93 commented Jul 17, 2024

Copy link
Copy Markdown
Contributor Author

@crohr So I don't understand, what's the point of having ttl if it doesn't work? I really just want to delete the instance so we aren't wasting money.

I think I meant to say instances and deployments instead.

Could we just like, remove the label after ttl?

@leightjohnson93

Copy link
Copy Markdown
Contributor Author

@leightjohnson93 this is because the GitHub Token cannot perform the environment deletion. It can only delete deployments. There is a comment in the code about that:

# This requires repository permission, which the GitHub Action token cannot get, so cannot delete the environment unfortunately

What about the option to pass in our own github token with administrator permissions?

@Alanoll

Alanoll commented Aug 23, 2024

Copy link
Copy Markdown
Contributor

Could we add a new YAML option to attempt the deletion of the environment because we provided our own Github Token?

So:

  • Merge these changes
  • Additional change to signify "yes, we do have a token with permission"
  • Uncomment the commented line so environments are deleted

There's already a YAML parameter github_token to provide a custom token.

This actions has steps to get a suitable token:
https://github.com/marketplace/actions/delete-deployment-environment

environment = PullPreview.octokit.list_environments(repo, per_page: 100).environments.find { |env| env.name.includes("gh-pr-#{pr.number}") }
if pr_issue.state == "closed"
PullPreview.logger.warn "[clear_dangling_deployments] Found dangling #{label} label for PR##{pr.number}. Cleaning up..."
destroy_environment(repo, environment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this will already be called when setting the GitHub status to destroyed -

self.class.destroy_environment(repo, instance_name)

@crohr

crohr commented Aug 24, 2024

Copy link
Copy Markdown
Member

@crohr So I don't understand, what's the point of having ttl if it doesn't work? I really just want to delete the instance so we aren't wasting money.

I think I meant to say instances and deployments instead.

Could we just like, remove the label after ttl?

Instances are destroyed with the TTL, but the GitHub environment object is not, since it requires permissions the GitHub context cannot have.

Could we add a new YAML option to attempt the deletion of the environment because we provided our own Github Token?

Yes, I will open a separate PR for that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants