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

Dynamically Provision GitHub Environments, Deployments, and Deployment Statuses #12

Open
axisofentropy opened this issue Aug 11, 2022 · 4 comments

Comments

@axisofentropy
Copy link
Member

We can enhance our customers' experiences on GitHub by specifying Environments and Deployments on GitHub from within our reusable workflow and/or GitHub Actions. Read about them here https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment

Because we want to provision these dynamically, we probably cannot use the easy YAML syntax within GitHub Actions. We can talk to GitHub's REST API directly, either using curl or the gh CLI api command. I wasn't able to find an action in the Marketplace for this, but search for one before implementing!

Design:
We should consider whether we want to create a single "Uffizzi" Environment and separate Deployments within it, or create Environments for each Uffizzi Deployment. Test both cases and explore the UX within GitHub.

GitHub Environments and Deployments should broadly follow the lifecycle of the Uffizzi Environments and Deployments they represent. Status updates should be posted before and after each uffizzi CLI invocation action. It's very important to include the URL of each environment everywhere possible.

Slack thread: https://uffizzi-internal.slack.com/archives/C85U32F3M/p1660238762177499

@axisofentropy axisofentropy added this to New Issues / Investigating in Working Project Board Aug 11, 2022
@axisofentropy
Copy link
Member Author

REST API documentation:

Note that Statuses are immutable and immortal; they may only be created. Usually only the most recent Status is displayed in the GitHub UI.

@axisofentropy
Copy link
Member Author

Example Environment Creation

adam@ephemeron:~/src/preview-action$ gh api --method PUT -H "Accept: application/vnd.github+json" /repos/UffizziCloud/example-voting-app/environments/deployment-333
{
  "id": 588408369,
  "node_id": "EN_kwDOHe4BRM4jEmYx",
  "name": "deployment-333",
  "url": "https://api.github.com/repos/UffizziCloud/example-voting-app/environments/deployment-333",
  "html_url": "https://github.com/UffizziCloud/example-voting-app/deployments/activity_log?environments_filter=deployment-333",
  "created_at": "2022-08-11T18:14:19Z",
  "updated_at": "2022-08-11T18:14:19Z",
  "protection_rules": [],
  "deployment_branch_policy": null
}```

@axisofentropy
Copy link
Member Author

Example Deployment creation that failed for some unknown reason.

adam@ephemeron:~/src/preview-action$ gh api --method POST -H "Accept: application/vnd.github+json" /repos/UffizziCloud/example-voting-app/deployments -f ref='main' -f environment='deployment-333'
{
  "message": "Conflict: Commit status checks failed for main.",
  "errors": [
    {
      "contexts": [
        {
          "context": "Build and Push `vote`",
          "state": "success"
        },
        {
          "context": "Build and Push `worker`",
          "state": "success"
        },
        {
          "context": "Use Remote Workflow to Delete an Existing Preview",
          "state": "skipped"
        },
        {
          "context": "Build and Push `loadbalancer`",
          "state": "success"
        },
        {
          "context": "Build and Push `result`",
          "state": "success"
        },
        {
          "context": "Render Docker Compose File",
          "state": "success"
        },
        {
          "context": "Use Remote Workflow to Preview on Uffizzi",
          "state": "skipped"
        }
      ],
      "resource": "Deployment",
      "field": "required_contexts",
      "code": "invalid"
    }
  ],
  "documentation_url": "https://docs.github.com/rest/reference/repos#create-a-deployment"
}
gh: Conflict: Commit status checks failed for main. (HTTP 409)

@axisofentropy
Copy link
Member Author

Note that some additional permissions may be required for our reusable workflow (or wherever we end up implementing this.) The workflow permission is probably deployments: write.

Also see this important note about "inactive" and "transient" deployments https://docs.github.com/en/rest/deployments/deployments#inactive-deployments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Working Project Board
New Issues / Investigating
Development

No branches or pull requests

1 participant