deploy_feedback icon indicating copy to clipboard operation
deploy_feedback copied to clipboard

API for deploying by URL

Open lewisl9029 opened this issue 3 years ago • 4 comments

Hi deno team!

I really, really love the fact that you've built the ability to deploy through a script hosted on the web!

As much as I love git, I don't think it's necessarily the right primitive for deploying web applications, since git clones take a non-trivial amount of time and serves as a minimum latency floor for our iteration cycles. Static assets, on the other hand, feels like a much better primitive since it is the de-facto primitive of the web, and has minimal latency overhead for propagating updates.

That said, one thing I would love to see is the ability to hook into deno deploy's ability to create deployments using a script, through some kind of unofficial API. I see that right now, this is done through the following API call:

await fetch("https://dash.deno.com/api/projects/_redacted_/deployments_stream", {
    "headers": {
        "authorization": "Bearer _redacted_",
        "content-type": "application/json",
    },
    "body": "{\"url\":\"https://_redacted_\",\"production\":true}",
    "method": "POST",
});

I can already call this API outside of the Deno deploy dashboard, but the fact that there's no way to get issued a persistent authorization token makes the usage rather awkward, as I'd have to deal with the fact that my dashboard token can expire, and manually refresh it from time to time.

Would you please consider the ability to issue an API token from the dashboard to allow other tools to leverage Deno deploy more conveniently? No need to offer any guarantee of API stability, given the early experimental state of the service itself. This could totally stay a use-at-your-own-risk type of thing for the foreseeable future.

Thanks!

lewisl9029 avatar May 08 '21 03:05 lewisl9029

Suggestion which would work for one use-case I have:

As a user of a collaborative ES module editing app, I want Deno Deploy to provide a "Webhook URL" (a la Discord) which triggers a refresh/re-deployment of the provided module URL, so that the latest rough draft of the service is re-deployed when my colleague or I click a button in the editor.

My example does not include the ability to provide a new URL; only to refresh the one provided on the dashboard. I imagine the webhook URL should include a randomized string to prevent unauthorized interruptions, while being more flexible to work with than authorization tokens, just as in Discord's webhook URLs for sending a message.

ewired avatar May 08 '21 08:05 ewired

Persistent API tokens are being worked on, it's something we've known about for a while, it just hasn't been released yet. The API endpoint you found is indeed the correct one, though you can also use POST /api/projects/:project_id/deployments instead which doesn't stream the response body -- the streaming part is meant to stream back the output of the dependency downloads step which happen on Deploy's side, it's really meant to be exposed on the front-end (though if you want to stream that back to stdout, knock yourself out!)

That being said, it should be noted that the GitHub integration is not cloning the entire repository. The webhook is used to send a request to Deploy that there is a new commit on the default branch. From there, the process is very similar to deploying from a URL, we simply take the raw.githubusercontent.com version of the entrypoint at the new commit and use that as the source URL. It's really just a way to automate the update the source URL.

If you're interested in scripting your updates, you can also check out the unstable Terraform provider which includes a client SDK (written in Go) for the API.

wperron avatar May 10 '21 12:05 wperron

We have static tokens now (create them via your account page). The API is not documented and subject to change, but for now you can use POST https://dash.deno.com/api/projects/:project_id/deployments to create new deployments. As William said this is not a streaming endpoint - it completes with the response only once the deployment has been completed.

lucacasonato avatar Jun 17 '21 10:06 lucacasonato

Does POST https://dash.deno.com/api/projects/:project_id/deployments endpoint still works?

It replies with 404, and GET works fine. POST to deployment_with_assets also works.

tchief avatar Jul 26 '22 16:07 tchief