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

[docs, API] control api + swagger ui for http api #3158

Merged
merged 16 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
599 changes: 599 additions & 0 deletions docs/content/en/api/skaffold.swagger.json

Large diffs are not rendered by default.

83 changes: 73 additions & 10 deletions docs/content/en/docs/design/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pipeline** and for **controlling the phases in the pipeline**.

To retrieve information about the Skaffold pipeline, the Skaffold API provides two main functionalities:

* A [streaming event log]({{< relref "/docs/design/api#events-api">}}) created from the different phases in a pipeline run and
* A [streaming event log]({{< relref "#events-api">}}) created from the different phases in a pipeline run and
balopat marked this conversation as resolved.
Show resolved Hide resolved

* A snapshot of the [overall state]({{< relref "/docs/design/api#state-api" >}}) of the pipeline at any given time during the run.
* A snapshot of the [overall state]({{< relref "#state-api" >}}) of the pipeline at any given time during the run.

To control the individual phases of the Skaffold, the Skaffold API provides [fine grained control over]({{< relref "/docs/design/api#controlling-build-sync-deploy" >}})
To control the individual phases of the Skaffold, the Skaffold API provides [fine grained control over]({{< relref "#controlling-build-sync-deploy" >}})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To control the individual phases of the Skaffold, the Skaffold API provides [fine grained control over]({{< relref "#controlling-build-sync-deploy" >}})
To control the individual phases of the Skaffold, the Skaffold API provides [fine grained control]({{< relref "#controlling-build-sync-deploy" >}}) over

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't get this change

Copy link
Contributor

Choose a reason for hiding this comment

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

this is very small nit. i am going to approve and merge

the individual phases of the pipeline (build, deploy and sync).


Expand All @@ -27,7 +27,7 @@ The Skaffold API is `gRPC` based, and it is also exposed via the gRPC gateway as
The server is hosted locally on the same host where the skaffold process is running, and will serve by default on ports 50051 and 50052.
These ports can be configured through the `--rpc-port` and `--rpc-http-port` flags.

The server's gRPC service definitions and message protos can be found [here]({{< relref "/docs/references/api" >}}).
We generate the server's [gRPC service definitions and message protos]({{< relref "/docs/references/api/grpc" >}}) as well as the [Swagger based HTTP API Spec]({{< relref "/docs/references/api/swagger" >}}).
balopat marked this conversation as resolved.
Show resolved Hide resolved


### HTTP server
Expand Down Expand Up @@ -123,15 +123,15 @@ Using `curl` and `HTTP_RPC_PORT=50052`, an example output of a `skaffold dev` ex
```
{{% /tab %}}
{{% tab "gRPC API" %}}
To get events from the `gRPC` server, first create [`gRPC` client]({{< relref "/docs/design/api#creating-a-grpc-client" >}})
To get events from the `gRPC` server, first create [`gRPC` client]({{< relref "#creating-a-grpc-client" >}})
balopat marked this conversation as resolved.
Show resolved Hide resolved

```golang
func main() {
ctx, ctxCancel := context.WithCancel(context.Background())
defer ctxCancel()
// `client` is the gRPC client with connection to localhost:50051.
// See code above to create it
logStream, err := client.Events(ctx)
logStream, err := client.EventLog(ctx, &empty.Empty{})
balopat marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Fatalf("could not get events: %v", err)
}
Expand All @@ -150,7 +150,7 @@ func main() {
{{% /tab %}}
{{% /tabs %}}

Each [Entry log]({{<relref "/docs/references/api#proto.LogEntry" >}}) contains an [Event]({{< relref "/docs/references/api#proto.Event" >}}) in the `LogEntry.Event` field and
Each [Entry log]({{<relref "/docs/references/api/grpc#proto.LogEntry" >}}) contains an [Event]({{< relref "/docs/references/api/grpc#proto.Event" >}}) in the `LogEntry.Event` field and
balopat marked this conversation as resolved.
Show resolved Hide resolved
a string description of the event in `LogEntry.entry` field.


Expand All @@ -169,7 +169,7 @@ The State API provides a snapshot of the current state of the following componen
| protocol | endpoint | encoding |
| ---- | --- | --- |
| HTTP | `http://localhost:{HTTP_RPC_PORT}/v1/state` | newline separated JSON using chunk transfer encoding over HTTP|
| gRPC | `client.GetState(ctx)` method on the [`SkaffoldService`]({{< relref "/docs/references/api#skaffoldservice">}}) | protobuf 3 over HTTP |
| gRPC | `client.GetState(ctx)` method on the [`SkaffoldService`]({{< relref "/docs/references/api/grpc#skaffoldservice">}}) | protobuf 3 over HTTP |


**Examples**
Expand Down Expand Up @@ -214,7 +214,7 @@ Using `curl` and `HTTP_RPC_PORT=50052`, an example output of a `skaffold dev` ex
```
{{% /tab %}}
{{% tab "gRPC API" %}}
To get events over `gRPC` server, first create [`gRPC` client]({{< relref "/docs/design/api#creating-a-grpc-client" >}})
To get events over `gRPC` server, first create [`gRPC` client]({{< relref "#creating-a-grpc-client" >}})
balopat marked this conversation as resolved.
Show resolved Hide resolved
```code
func main() {
// Create a gRPC client connection to localhost:50051.
Expand All @@ -230,4 +230,67 @@ func main() {

### Control API

TODO: https://github.com/GoogleContainerTools/skaffold/issues/3143
By default, [`skaffold dev`]({{< relref "/docs/workflows/dev" >}}) automatically builds artifacts, deploys manifests and syncs files on every source code change.
The automation can be turned off with `--auto-build=false` flag for building, `--auto-deploy=false` flag for deploys, and the `--auto-sync=false` flag for file sync.
If automation is turned off for a phase, Skaffold will wait for a call to the Control API before executing the given phase.

One call to the Control API allows for one execution of the phases specified in the request.
This means that _even if there are new file changes_, Skaffold will wait for another execution request before executing the given phase again.
The Control API mode is best to think about as "semaphores" for build / sync / deploy, that get lifted once per every request.

**Control API contract**

| protocol | endpoint |
| ---- | ---- | ---- |
| HTTP, method: POST | `http://localhost:{HTTP_RPC_PORT}/v1/execute`, the [Execution Service]({{<relref "/docs/references/api/swagger#/SkaffoldService/Execute">}}) |
| gRPC | `client.Execute(ctx)` method on the [`SkaffoldService`]({{< relref "/docs/references/api/grpc#skaffoldservice">}}) |


**Examples**

{{% tabs %}}
{{% tab "HTTP API" %}}

Using our [Quickstart example]({{< relref "/docs/quickstart" >}}) we can start skaffold with `skaffold dev --auto-build=false`.
When we change `main.go`, Skaffold will notice file changes but it won't rebuild the image until it receives a call to the Control API with `"build":true`:

```bash
curl -X POST http://localhost:50052/v1/execute -d '{"build": true}'
```

At this point, Skaffold will wait to deploy the newly built image until we invoke the Control API with `"deploy":true`:

```bash
curl -X POST http://localhost:50052/v1/execute -d '{"deploy": true}'
```

Note that you can also combine these steps into one call:

```bash
curl -X POST http://localhost:50052/v1/execute -d '{"build": true, "deploy": true}'
```

{{% /tab %}}
{{% tab "gRPC API" %}}
To get events from the `gRPC` server, first create [`gRPC` client]({{< relref "#creating-a-grpc-client" >}})

```golang
func main() {
ctx, ctxCancel := context.WithCancel(context.Background())
defer ctxCancel()
// `client` is the gRPC client with connection to localhost:50051.
// See code above to create it
_, err = client.Execute(ctx, &pb.UserIntentRequest{
Intent: &pb.Intent{
Build: true,
Sync: true,
Deploy: true,
},
})
if err != nil {
log.Fatalf("error when trying to execute phases: %v", err)
}
}
```
{{% /tab %}}
{{% /tabs %}}
5 changes: 3 additions & 2 deletions docs/content/en/docs/references/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ weight: 100
|----------|
| [CLI]({{< relref "/docs/references/cli" >}}) |
| [skaffold.yaml]({{< relref "/docs/references/yaml" >}}) |
| [Deprecation Policy]({{< relref "/docs/references/deprecation" >}}) |
| [gRPC API]({{< relref "/docs/references/api/grpc" >}}) |
| [HTTP API]({{< relref "/docs/references/api/swagger" >}}) |
| [Privacy Settings] ({{< relref "/docs/references/privacy" >}}) |
| [API Reference]({{< relref "/docs/references/api" >}}) |
| [Deprecation Policy]({{< relref "/docs/references/deprecation" >}}) |

Loading