From 9d6b6738320d7c4f7e23862bab74dca81c2882b2 Mon Sep 17 00:00:00 2001 From: Cyril Diagne Date: Fri, 4 Oct 2019 13:21:55 +0200 Subject: [PATCH] First commit --- .circleci/config.yml | 30 ++++ .gitbook.yaml | 5 + .gitignore | 3 + .goreleaser.yml | 35 +++++ LICENSE | 202 ++++++++++++++++++++++++++ Makefile | 8 + README.md | 50 +++++++ cmd/app-delete.go | 71 +++++++++ cmd/app-deploy.go | 71 +++++++++ cmd/app.go | 33 +++++ cmd/delete.go | 63 ++++++++ cmd/dev-start.go | 80 ++++++++++ cmd/dev-stop.go | 50 +++++++ cmd/dev.go | 33 +++++ cmd/get.go | 62 ++++++++ cmd/root.go | 83 +++++++++++ cmd/setup-gcp.go | 78 ++++++++++ cmd/setup.go | 73 ++++++++++ cmd/utils.go | 44 ++++++ docs/contribute/development.md | 44 ++++++ docs/images/logo.png | Bin 0 -> 7269 bytes docs/kuda/cli.md | 64 ++++++++ docs/kuda/getting_started.md | 86 +++++++++++ docs/kuda/install.md | 15 ++ docs/kuda/remote_development.md | 68 +++++++++ docs/summary.md | 19 +++ examples/hello-world/Dockerfile | 25 ++++ examples/hello-world/README.md | 3 + examples/hello-world/app.py | 15 ++ examples/hello-world/requirements.txt | 2 + go.mod | 9 ++ go.sum | 153 +++++++++++++++++++ images/dev/Dockerfile | 3 + images/dev/README.md | 8 + images/providers/gcp/.config.sh | 42 ++++++ images/providers/gcp/Dockerfile | 46 ++++++ images/providers/gcp/README.md | 9 ++ images/providers/gcp/app_delete.sh | 19 +++ images/providers/gcp/app_deploy.sh | 33 +++++ images/providers/gcp/delete.sh | 56 +++++++ images/providers/gcp/dev_start.sh | 184 +++++++++++++++++++++++ images/providers/gcp/dev_stop.sh | 23 +++ images/providers/gcp/get.sh | 16 ++ images/providers/gcp/setup.sh | 146 +++++++++++++++++++ main.go | 22 +++ pkg/docker/run.go | 77 ++++++++++ 46 files changed, 2261 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 .gitbook.yaml create mode 100644 .gitignore create mode 100644 .goreleaser.yml create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 cmd/app-delete.go create mode 100644 cmd/app-deploy.go create mode 100644 cmd/app.go create mode 100644 cmd/delete.go create mode 100644 cmd/dev-start.go create mode 100644 cmd/dev-stop.go create mode 100644 cmd/dev.go create mode 100644 cmd/get.go create mode 100644 cmd/root.go create mode 100644 cmd/setup-gcp.go create mode 100644 cmd/setup.go create mode 100644 cmd/utils.go create mode 100644 docs/contribute/development.md create mode 100644 docs/images/logo.png create mode 100644 docs/kuda/cli.md create mode 100644 docs/kuda/getting_started.md create mode 100644 docs/kuda/install.md create mode 100644 docs/kuda/remote_development.md create mode 100644 docs/summary.md create mode 100644 examples/hello-world/Dockerfile create mode 100644 examples/hello-world/README.md create mode 100644 examples/hello-world/app.py create mode 100644 examples/hello-world/requirements.txt create mode 100644 go.mod create mode 100644 go.sum create mode 100644 images/dev/Dockerfile create mode 100644 images/dev/README.md create mode 100644 images/providers/gcp/.config.sh create mode 100644 images/providers/gcp/Dockerfile create mode 100644 images/providers/gcp/README.md create mode 100644 images/providers/gcp/app_delete.sh create mode 100755 images/providers/gcp/app_deploy.sh create mode 100755 images/providers/gcp/delete.sh create mode 100755 images/providers/gcp/dev_start.sh create mode 100755 images/providers/gcp/dev_stop.sh create mode 100644 images/providers/gcp/get.sh create mode 100755 images/providers/gcp/setup.sh create mode 100644 main.go create mode 100644 pkg/docker/run.go diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..20ecc17 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,30 @@ +version: 2 +jobs: + build-cli: + docker: + - image: circleci/golang:1.13 + steps: + - checkout + - run: go build main.go + release: + docker: + - image: circleci/golang:1.13 + steps: + - checkout + - run: curl -sL https://git.io/goreleaser | bash +workflows: + version: 2 + any-commit: + jobs: + - build-cli: + filters: + tags: + ignore: /.*/ + release: + jobs: + - release: + filters: + branches: + ignore: /.*/ + tags: + only: /v[0-9]+(\.[0-9]+)*(-.*)*/ diff --git a/.gitbook.yaml b/.gitbook.yaml new file mode 100644 index 0000000..c236f9e --- /dev/null +++ b/.gitbook.yaml @@ -0,0 +1,5 @@ +root: ./docs/ + +structure: + readme: ../README.md + summary: summary.md \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e65aa5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +.vscode +dist \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..514f2af --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,35 @@ +release: + prerelease: auto +before: + hooks: + - go mod tidy +builds: + - # Env + env: + - CGO_ENABLED=0 + ldflags: + - -X github.com/cyrildiagne/kuda/cmd.version={{.Version}} +archives: + - replacements: + darwin: Darwin + linux: Linux + windows: Windows + 386: i386 + amd64: x86_64 +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ .Tag }}-next" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" +# brews: +# - # Tap +# github: +# owner: tredfield +# name: homebrew-tap +# homepage: "https://github.com/cyrildiagne/kuda" +# description: "Build & deploy serverless applications on remote GPUs." diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1628ff1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2019 Cyril Diagne + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..511c5da --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +SHELL := /bin/bash + +kuda_root := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + +build-provider-and-run: + docker build $(kuda_root)images/providers/$(provider) \ + -t gcr.io/kuda-project/provider-$(provider) + go run $(kuda_root) $(cmd) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b5ef3a4 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# ![](https://github.com/cyrildiagne/kuda/raw/master/docs/images/logo.png) + +[![](https://circleci.com/gh/cyrildiagne/kuda/tree/master.svg?style=shield&circle-token=b14f5838ae2acabe21a8255070507f7e36ba510b)](https://circleci.com/gh/cyrildiagne/kuda) +[![](https://goreportcard.com/badge/github.com/cyrildiagne/kuda)](https://goreportcard.com/report/github.com/cyrildiagne/kuda) +[![](https://img.shields.io/github/v/release/cyrildiagne/kuda)](https://github.com/cyrildiagne/kuda/releases) + +**Develop & deploy serverless applications on remote GPUs.** + +[Kuda](https://kuda.dev) is a small util that consolidates the workflow of prototyping and deploying serverless [CUDA](https://developer.nvidia.com/cuda-zone)-based applications on [Kubernetes](http://kubernetes.io). + +## Disclaimer + +🧪 This is a **very early** and **experimental** work in progress: + +- Don't use it in production environments. +- The API will change. + +## Key Features + +**Serverless GPU applications** + +- Remote GPUs can be expensive for individuals and small teams. For prototypes and projects that receive traffic only occasionally, it's hard to justify the cost of running an expensive GPU server permanently. +- Kuda uses [Knative](https://knative.dev) to consume billable GPUs only when there is traffic, and scales down to zero when there's no traffic. + +**Easy to use** + +- `kuda setup ` : Setup a new cluster will all the requirements on the provider's managed Kubernetes, or upgrade an existing cluster. +- `kuda app deploy` : Builds & deploy an application as a serverless container. + +**Language/Framework agnostic** + +- Built and deployed with [Docker](https://docker.io), applications can be written in any language and use any framework. +- Applications deployed with Kuda are not required to import any specific library, keeping the code 100% portable. + +**Remote development** + +- The `kuda dev` command lets you spawn a remote development session with GPU inside the cluster. +- It uses [Ksync](https://github.com/vapor-ware/ksync) to synchronise your working directory with the remote session so you can code from your workstation while running the app on the remote session. + +**Compatibility** + +- [GCP](https://cloud.google.com) provider is already implemented. +- [AWS](https://aws.amazon.com) and [Azure](https://azure.microsoft.com) should follow soon. + +## Ready? + +- [Install](https://docs.kuda.dev/kuda/install) +- [Getting Started](https://docs.kuda.dev/kuda/getting_started) +- [Examples](https://github.com/cyrildiagne/kuda/tree/master/examples) +- [Reference](https://docs.kuda.dev/kuda/cli) diff --git a/cmd/app-delete.go b/cmd/app-delete.go new file mode 100644 index 0000000..c912fbd --- /dev/null +++ b/cmd/app-delete.go @@ -0,0 +1,71 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + "os" + + "github.com/cyrildiagne/kuda/pkg/docker" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// appDeleteCmd represents the `app delete` command +var appDeleteCmd = &cobra.Command{ + Use: "delete [app-name:app-version]", + Short: "Deploy an app.", + Long: "Deploy an app.", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + if err := delete(args[0]); err != nil { + fmt.Println("ERROR:", err) + } + }, +} + +func init() { + appCmd.AddCommand(appDeleteCmd) +} + +func delete(app string) error { + fmt.Println("→ Deleting app...") + // Image to run. + image := viper.GetString("image") + // Command to run. + command := []string{"kuda_app_delete", app} + + // Add the CWD to the volumes mounted in Docker. + dir, err := os.Getwd() + if err != nil { + panic(err) + } + volumes := []string{dir + ":/app_home"} + + // Run the command. + dockerErr := RunDockerWithProviderEnvs(docker.CommandOption{ + Image: image, + Command: command, + AppendVolumes: volumes, + }) + if dockerErr != nil { + fmt.Println(dockerErr) + } + + return nil +} diff --git a/cmd/app-deploy.go b/cmd/app-deploy.go new file mode 100644 index 0000000..250c92f --- /dev/null +++ b/cmd/app-deploy.go @@ -0,0 +1,71 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + "os" + + "github.com/cyrildiagne/kuda/pkg/docker" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// deployCmd represents the `app deploy` command +var deployCmd = &cobra.Command{ + Use: "deploy [app-name:app-version]", + Short: "Deploy an app.", + Long: "Deploy an app.", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + if err := deploy(args[0]); err != nil { + fmt.Println("ERROR:", err) + } + }, +} + +func init() { + appCmd.AddCommand(deployCmd) +} + +func deploy(app string) error { + fmt.Println("→ Deploying app...") + // Image to run. + image := viper.GetString("image") + // Command to run. + command := []string{"kuda_app_deploy", app} + + // Add the CWD to the volumes mounted in Docker. + dir, err := os.Getwd() + if err != nil { + panic(err) + } + volumes := []string{dir + ":/app_home"} + + // Run the command. + dockerErr := RunDockerWithProviderEnvs(docker.CommandOption{ + Image: image, + Command: command, + AppendVolumes: volumes, + }) + if dockerErr != nil { + fmt.Println(dockerErr) + } + + return nil +} diff --git a/cmd/app.go b/cmd/app.go new file mode 100644 index 0000000..5e34a32 --- /dev/null +++ b/cmd/app.go @@ -0,0 +1,33 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "github.com/spf13/cobra" +) + +// appCmd represents the app command +var appCmd = &cobra.Command{ + Use: "app", + Short: "Apps management.", + Long: "Apps management.", +} + +func init() { + RootCmd.AddCommand(appCmd) +} diff --git a/cmd/delete.go b/cmd/delete.go new file mode 100644 index 0000000..d8697b0 --- /dev/null +++ b/cmd/delete.go @@ -0,0 +1,63 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "bufio" + "fmt" + "os" + + "github.com/cyrildiagne/kuda/pkg/docker" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// deleteCmd represents the `delete` command +var deleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete the remote clusters.", + Long: "Delete the remote clusters.", + Run: func(cmd *cobra.Command, args []string) { + Delete() + }, +} + +func init() { + RootCmd.AddCommand(deleteCmd) +} + +// Delete a cluster. +func Delete() error { + + // Ask if we should delete the cluster. + fmt.Print("Warning: This will delete the current cluster. Continue? (y/n) ") + scanner := bufio.NewScanner(os.Stdin) + scanner.Scan() + txt := scanner.Text() + if txt == "n" { + return nil + } + + // Image to run. + image := viper.GetString("image") + // Command to run. + command := []string{"kuda_delete"} + // Run. + err := RunDockerWithProviderEnvs(docker.CommandOption{Image: image, Command: command}) + return err +} diff --git a/cmd/dev-start.go b/cmd/dev-start.go new file mode 100644 index 0000000..43fb50a --- /dev/null +++ b/cmd/dev-start.go @@ -0,0 +1,80 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "bufio" + "fmt" + "os" + + "github.com/cyrildiagne/kuda/pkg/docker" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// startCmd represents the `dev start` command +var startCmd = &cobra.Command{ + Use: "start", + Short: "Start a dev session.", + Long: "Start a dev session.", + Run: func(cmd *cobra.Command, args []string) { + if err := start(); err != nil { + fmt.Println("ERROR:", err) + } + }, +} + +func init() { + devCmd.AddCommand(startCmd) +} + +func start() error { + fmt.Println("→ Starting a remote session...") + // Image to run. + image := viper.GetString("image") + // Command to run. + command := []string{"kuda_dev_start"} + + // Add the CWD to the volumes mounted in Docker. + dir, err := os.Getwd() + if err != nil { + panic(err) + } + volumes := []string{dir + ":/app_home"} + + // Run the command. + dockerErr := RunDockerWithProviderEnvs(docker.CommandOption{ + Image: image, + Command: command, + AppendVolumes: volumes, + }) + if dockerErr != nil { + fmt.Println(dockerErr) + } + + // Ask if we should stop the session. + fmt.Print("Do you want to delete the remote session? (y/n) ") + scanner := bufio.NewScanner(os.Stdin) + scanner.Scan() + txt := scanner.Text() + if txt == "y" { + Stop() + } + + return nil +} diff --git a/cmd/dev-stop.go b/cmd/dev-stop.go new file mode 100644 index 0000000..7f255d3 --- /dev/null +++ b/cmd/dev-stop.go @@ -0,0 +1,50 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "github.com/cyrildiagne/kuda/pkg/docker" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// stopCmd represents the `dev stop` command +var stopCmd = &cobra.Command{ + Use: "stop", + Short: "Stop a dev session.", + Long: "Stop a dev session.", + Run: func(cmd *cobra.Command, args []string) { + Stop() + }, +} + +func init() { + devCmd.AddCommand(stopCmd) +} + +// Stop the remote session. +func Stop() error { + // color.Cyan("→ Stopping the remote session...") + // Image to run. + image := viper.GetString("image") + // Command to run. + command := []string{"kuda_dev_stop"} + // Run + err := RunDockerWithProviderEnvs(docker.CommandOption{Image: image, Command: command}) + return err +} diff --git a/cmd/dev.go b/cmd/dev.go new file mode 100644 index 0000000..ee55787 --- /dev/null +++ b/cmd/dev.go @@ -0,0 +1,33 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "github.com/spf13/cobra" +) + +// devCmd represents the dev command +var devCmd = &cobra.Command{ + Use: "dev", + Short: "Manage dev sessions.", + Long: "Manage dev sessions.", +} + +func init() { + RootCmd.AddCommand(devCmd) +} diff --git a/cmd/get.go b/cmd/get.go new file mode 100644 index 0000000..faa81ca --- /dev/null +++ b/cmd/get.go @@ -0,0 +1,62 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + + "github.com/cyrildiagne/kuda/pkg/docker" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// getCmd represents the `get` command +var getCmd = &cobra.Command{ + Use: "get [property]", + Short: "Get information about the remote cluster.", + Long: "Get information about the remote cluster.", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + if err := get(args[0]); err != nil { + fmt.Println("ERROR:", err) + } + }, +} + +func init() { + RootCmd.AddCommand(getCmd) +} + +func get(property string) error { + fmt.Printf("→ Getting %s...\n", property) + // Image to run. + image := viper.GetString("image") + // Command to run. + command := []string{"kuda_get", property} + + // Run the command. + dockerErr := RunDockerWithProviderEnvs(docker.CommandOption{ + Image: image, + Command: command, + }) + if dockerErr != nil { + fmt.Println(dockerErr) + } + + return nil +} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..c9173b6 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,83 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + "os" + "strings" + + homedir "github.com/mitchellh/go-homedir" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var version = "dev" +var cfgFile string + +// RootCmd is the main command. +var RootCmd = &cobra.Command{ + Use: "kuda", + Short: "Develop & deploy serverless applications on remote GPUs", + Long: `Kuda consolidates the workflow of prototyping and deploying +serverless CUDA-based applications on Kubernetes from any workstation. +https://kuda.dev`, + Version: version, +} + +// Execute adds all child commands to the root command and sets flags appropriately. +// This is called by main.main(). It only needs to happen once to the RootCmd. +func Execute() { + RootCmd.Version = version + if err := RootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +func init() { + cobra.OnInitialize(initConfig) + RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kuda.yaml)") +} + +// initConfig reads in config file and ENV variables if set. +func initConfig() { + if cfgFile != "" { + // Use config file from the flag. + viper.SetConfigFile(cfgFile) + } else { + // Find home directory. + home, err := homedir.Dir() + if err != nil { + fmt.Println(err) + os.Exit(1) + } + + viper.AddConfigPath(home) + viper.SetConfigName(".kuda") + } + + viper.SetEnvPrefix("kuda") + viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) + viper.AutomaticEnv() // read in environment variables that match + + // If a config file is found, read it in. + if err := viper.ReadInConfig(); err == nil { + fmt.Println("Using config file:", viper.ConfigFileUsed()) + } +} diff --git a/cmd/setup-gcp.go b/cmd/setup-gcp.go new file mode 100644 index 0000000..cdacd2d --- /dev/null +++ b/cmd/setup-gcp.go @@ -0,0 +1,78 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + "path/filepath" + + "github.com/cyrildiagne/kuda/pkg/docker" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +var provider = "gcp" +var project string +var credentials string + +// gcpCmd represents the `setup gcp` command +var gcpCmd = &cobra.Command{ + Use: "gcp", + Short: "Setup Kuda on GCP.", + Long: "Setup Kuda on GCP.", + Run: func(cmd *cobra.Command, args []string) { + if err := setup(); err != nil { + fmt.Println("ERROR:", err) + } + }, +} + +func init() { + setupCmd.AddCommand(gcpCmd) + + gcpCmd.PersistentFlags().StringVarP(&project, "project", "p", "", + "GCP Project ID") + gcpCmd.MarkPersistentFlagRequired("project") + viper.BindPFlag("gcp_project_id", gcpCmd.PersistentFlags().Lookup("project")) + + gcpCmd.PersistentFlags().StringVarP(&credentials, "credentials", "c", "", + "Path to GCP credentials JSON") + gcpCmd.MarkPersistentFlagRequired("credentials") + viper.BindPFlag("gcp_credentials", gcpCmd.PersistentFlags().Lookup("credentials")) +} + +func setup() error { + // Set provider config. + viper.Set("provider", provider) + + // Setup the provider's image. + providerVersion := "1.1.0" + image := "gcr.io/kuda-project/provider-" + provider + ":" + providerVersion + viper.Set("image", image) + + // Setup the volume mounting for the credentials. + volumeSecret := docker.VolumeMapping{ + From: filepath.Dir(credentials), + To: "/secret", + } + viper.Set("volumes", []docker.VolumeMapping{volumeSecret}) + + Setup() + + return nil +} diff --git a/cmd/setup.go b/cmd/setup.go new file mode 100644 index 0000000..690438b --- /dev/null +++ b/cmd/setup.go @@ -0,0 +1,73 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "bufio" + "fmt" + "os" + "path/filepath" + + "github.com/cyrildiagne/kuda/pkg/docker" + homedir "github.com/mitchellh/go-homedir" + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +// setupCmd represents the `setup` command +var setupCmd = &cobra.Command{ + Use: "setup", + Short: "Setup a remote clusters", + Long: "Setup a remote clusters.", +} + +func init() { + RootCmd.AddCommand(setupCmd) +} + +// Setup is a unified setup function across all providers. +func Setup() error { + // Image to run. + image := viper.GetString("image") + // Command to run. + command := []string{"kuda_setup"} + // Run + err := RunDockerWithProviderEnvs(docker.CommandOption{Image: image, Command: command}) + if err != nil { + // Ask if we should delete the cluster. + fmt.Print("There was an error setting up the cluster. Do you want to delete it? (y/n) ") + scanner := bufio.NewScanner(os.Stdin) + scanner.Scan() + txt := scanner.Text() + if txt == "y" { + Delete() + } + } + + // Write new config to home directory. + home, err := homedir.Dir() + if err != nil { + return err + } + cfgFile := filepath.FromSlash(home + "/.kuda.yaml") + viper.SetConfigFile(cfgFile) + viper.WriteConfig() + fmt.Println("Config written in " + viper.ConfigFileUsed()) + + return nil +} diff --git a/cmd/utils.go b/cmd/utils.go new file mode 100644 index 0000000..271423d --- /dev/null +++ b/cmd/utils.go @@ -0,0 +1,44 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "fmt" + "strings" + + "github.com/cyrildiagne/kuda/pkg/docker" + "github.com/spf13/viper" +) + +// RunDockerWithProviderEnvs retrieves local environment variables +// that match a provider id and runs a docker image. +func RunDockerWithProviderEnvs(opts docker.CommandOption) error { + // Environment variables for the Docker image. + // We look for all the configs that start with the provider name + // "gcp" and convert them in the environment variable + // format KUDA_GCP_* + provider := viper.GetString("provider") + for k, e := range viper.AllSettings() { + if strings.HasPrefix(k, provider) { + key := "KUDA_" + strings.ToUpper(k) + value := fmt.Sprintf("%v", e) + opts.AppendEnv = append(opts.AppendEnv, key+"="+value) + } + } + return docker.RunDockerCommand(opts) +} diff --git a/docs/contribute/development.md b/docs/contribute/development.md new file mode 100644 index 0000000..c5e116a --- /dev/null +++ b/docs/contribute/development.md @@ -0,0 +1,44 @@ +# Development + +## Requirements + +- go v1.13 + +## Setup + +Clone the repository + +## Implement a provider + +A provider implementation should be a docker image tagged `gcr.io/kuda-project/provider-$KUDA_DEV_PROVIDER`. It should expose the following commands: + +```bash +# Cluster +kuda_setup +kuda_delete +kuda_get + +# Remote Dev Session +kuda_dev_start +kuda_dev_stop + +# App +kuda_app_deploy +kuda_app_delete +``` + +To build a provider implementation & run a command: + +Then: + +```bash +make provider= cmd="" build-provider-and-run +``` + +**Example:** + +```bash +export KUDA_GCP_PROJECT_ID=gpu-sh +export KUDA_GCP_CREDENTIALS=~/Perso/kuda/secret/gpu-sh-f6d27675cda2.json +make provider=gcp cmd="get status" build-provider-and-run +``` diff --git a/docs/images/logo.png b/docs/images/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..3fb1fb7784d22ec6d07d25fe31e3c7f92e5c7928 GIT binary patch literal 7269 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 zls +``` + +Example: `kuda app deploy my-app:1.0.0` + +Deploys the application as serverless API. diff --git a/docs/kuda/getting_started.md b/docs/kuda/getting_started.md new file mode 100644 index 0000000..e432e95 --- /dev/null +++ b/docs/kuda/getting_started.md @@ -0,0 +1,86 @@ +# Getting Started + +This guide gets you started with Kuda on GCP \(Google Cloud Platform\). + +Appart from the environment variables, the process should be identical for other providers. + +## 1 - Setup + +- [Install Kuda](https://docs.kuda.dev/kuda/install) on your local machine +- Make sure you have an existing GCP Project with at least [1 quota for "GPUs \(all regions\)"](https://console.cloud.google.com/iam-admin/quotas). +- Download an application service [credentials as JSON](https://console.cloud.google.com/apis/credentials/serviceaccountkey) +- Then setup a new remote cluster: + +```bash +kuda setup gcp --project --credentials +``` + +This process can take a while since it will create a remote cluster on GKE and install all the required addons. + +→ For more information on the `kuda setup` command, check the [reference](https://docs.kuda.dev/kuda/cli#setup). + +## 2 - Develop + +### • Initialize + +Retrieve an example application: + +```bash +git clone https://github.com/cyrildiagne/kuda +cd kuda/examples/hello-world +``` + +Install the example dependencies (feel free to create a virtualenv or a [remote dev session](https://docs.kuda.dev/kuda/remote_development)). + +```bash +pip install -r requirements.txt +``` + +### • Run and Test + +Then start the example in dev mode. It will reload automatically when you make changes from your local machine: + +```bash +export PORT=80 && python app.py +``` + +Open `http://localhost` in a web browser to visit the app. Try making changes to the code and reload the page. + +Press `Ctrl+C` to stop running the application. + +## • Deploy + +You can then deploy the app as a serverless API. This will create an endpoint that scales down the GPU nodes to 0 when not used. + +From your local terminal run: + +```bash +kuda app deploy hello-world:0.1.0 +``` + +→ For more information on the `kuda app deploy` command, check the [reference](https://docs.kuda.dev/kuda/cli#deploy). + +## 3 - Call your API + +You can then test your application by making a simple HTTP request to your cluster. +First retrieve the IP address of your cluster by running: `kuda get status` + +```bash +curl -H "Host: hello-world.example.com" http:// +``` + +The first call might need to spawn an instance which could take while. Subsequent calls should be a lot faster. + +## 4 - Cleanup + +### • Delete the cluster + +The GPU nodes are setup to autoscale down to 0 when they're not in use. However, the system node will still incur charges on GCP. + +To completely delete the cluster run: + +```bash +kuda delete +``` + +→ For more information on the `kuda cluster delete` command, check the [reference](https://docs.kuda.dev/kuda/cli#delete). diff --git a/docs/kuda/install.md b/docs/kuda/install.md new file mode 100644 index 0000000..e5c6ce5 --- /dev/null +++ b/docs/kuda/install.md @@ -0,0 +1,15 @@ +# Install + +## Requirements: + +- [Docker](https://docs.docker.com/install) + +## MacOS / Linux: + +Download the right binary from the [latest release](https://github.com/cyrildiagne/kuda/releases/latest). + +Then move the binary to you \$PATH: + +```bash +sudo mv kuda /usr/local/bin +``` diff --git a/docs/kuda/remote_development.md b/docs/kuda/remote_development.md new file mode 100644 index 0000000..6861895 --- /dev/null +++ b/docs/kuda/remote_development.md @@ -0,0 +1,68 @@ +# Remote Development + +This guide will walk you through the process of developping remotely on the Kubernetes cluster. + +Make sure you have a cluster running with Kuda's dependencies. + +## 1 - Introduction + +Remote dev sessions work like a virtual machine running in you kubernetes cluster that will use [Ksync](https://github.com/vapor-ware/ksync/) to synchronize the local folder on your workstation. So you can code from any machine with your favorite IDE while running the workloads on powerful remote GPUs. + +Developping on remote sessions offers many other advantages such as: + +- Elastic resources - Scale up and down the hardware for the current task. +- Datacenter-fast internet - Download large datasets _much_ faster. +- Contained environment per project - No more conflict between librairies, CUDA or python version..etc. + +## 2 - Start a Remote Dev Session + +Start a remote dev session that will be provisioned on your cluster. + +```bash +kuda dev start +``` + +This command will start the remote session and synchronize the CWD \(current working directory\) with the remote instance. + +Upon started, it will also print the cluster's IP address / port to use later on. Make not of that as we'll refer to it later as `` + +→ For more information on the `kuda dev start` command, check the [reference](https://docs.kuda.dev/kuda/cli#dev). + +## • Retrieve & initialize an example application + +From the remote shell that's started, clone the example: + +```bash +root@kuda-dev: git clone https://github.com/cyrildiagne/kuda +root@kuda-dev: cd kuda/examples/tf-hub-biggan +``` + +Install the example dependencies. Because the remote dev session is short lived, you don't need to create a virtualenv: + +```bash +root@kuda-dev: pip install -r requirements.txt +``` + +## • Run and Test the example + +Then start the example in dev mode. It will reload automatically when you make changes from your local machine: + +```bash +root@kuda-dev: python app.py +``` + +Open `http:///101` in a web browser, wait for the model to load and you should see an image generated by BigGAN. You can try to change the category `101` by any other integer between `0` and `1000` to change the category. + +You can make a change to the code of the example and the application will restart automatically. + +## 3 - Cleanup + +### • Stop the remote dev session + +From the remote shell that's opened after you've run `kuda dev start`, simply enter: + +```bash +root@kuda-dev: exit +``` + +This will automatically call `kuda dev stop` and shut down the remote session. diff --git a/docs/summary.md b/docs/summary.md new file mode 100644 index 0000000..acf97e2 --- /dev/null +++ b/docs/summary.md @@ -0,0 +1,19 @@ +# Table of contents + +- [Introduction](../README.md) + +## Kuda + +- [Install](kuda/install.md) +- [Getting Started](kuda/getting_started.md) +- [Remote Development](kuda/remote_development.md) +- [Reference](kuda/cli.md) +- [Examples](https://github.com/cyrildiagne/kuda/tree/master/examples) + +## Providers + +- [GCP](../images/providers/gcp.md) + +## Contribute + +- [Development](contribute/development.md) diff --git a/examples/hello-world/Dockerfile b/examples/hello-world/Dockerfile new file mode 100644 index 0000000..abcc421 --- /dev/null +++ b/examples/hello-world/Dockerfile @@ -0,0 +1,25 @@ +FROM nvidia/cuda:10.1-base + +RUN apt-get update +RUN apt-get install -y --no-install-recommends \ + python3.7 python3-pip \ + && \ + apt-get clean && \ + apt-get autoremove && \ + rm -rf /var/lib/apt/lists/* +RUN pip3 install setuptools + + +WORKDIR /app + +# Install production dependencies. +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt + +# Copy local code to the container image. +COPY . ./ + +ENV PORT 80 + +# Run the web service using gunicorn. +CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app \ No newline at end of file diff --git a/examples/hello-world/README.md b/examples/hello-world/README.md new file mode 100644 index 0000000..846954b --- /dev/null +++ b/examples/hello-world/README.md @@ -0,0 +1,3 @@ +# Hello World + +The simplest possible example that returns the result of the command `nvidia-smi` diff --git a/examples/hello-world/app.py b/examples/hello-world/app.py new file mode 100644 index 0000000..8d5424e --- /dev/null +++ b/examples/hello-world/app.py @@ -0,0 +1,15 @@ +import os +import flask + +app = flask.Flask(__name__) + + +@app.route('/') +def hello(): + return 'Hello World!\n' + os.popen('nvidia-smi').read() + + +if __name__ == '__main__': + os.environ['FLASK_ENV'] = 'development' + port = int(os.environ.get('PORT', 8080)) + app.run(debug=True, host='0.0.0.0', port=port) diff --git a/examples/hello-world/requirements.txt b/examples/hello-world/requirements.txt new file mode 100644 index 0000000..ada3219 --- /dev/null +++ b/examples/hello-world/requirements.txt @@ -0,0 +1,2 @@ +Flask==1.1.1 +gunicorn==19.9.0 \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..46ff3a6 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/cyrildiagne/kuda + +go 1.13 + +require ( + github.com/mitchellh/go-homedir v1.1.0 + github.com/spf13/cobra v0.0.5 + github.com/spf13/viper v1.4.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..85dc242 --- /dev/null +++ b/go.sum @@ -0,0 +1,153 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= +github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= +github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/images/dev/Dockerfile b/images/dev/Dockerfile new file mode 100644 index 0000000..4625b28 --- /dev/null +++ b/images/dev/Dockerfile @@ -0,0 +1,3 @@ +FROM gcr.io/deeplearning-platform-release/base-cu100 + +WORKDIR /app_home \ No newline at end of file diff --git a/images/dev/README.md b/images/dev/README.md new file mode 100644 index 0000000..8e9c095 --- /dev/null +++ b/images/dev/README.md @@ -0,0 +1,8 @@ +To build & deploy this image: + +```bash +cd $KUDA_DIR + +docker build -f images/dev/Dockerfile -t gcr.io/kuda-project/dev:1.0.0 . +docker push $KUDA_VERSION +``` \ No newline at end of file diff --git a/images/providers/gcp/.config.sh b/images/providers/gcp/.config.sh new file mode 100644 index 0000000..95d3297 --- /dev/null +++ b/images/providers/gcp/.config.sh @@ -0,0 +1,42 @@ +set -e + +if [ -z "$KUDA_GCP_PROJECT_ID" ]; then + echo "\$KUDA_GCP_PROJECT_ID is undefined." + exit 1 +fi + +if [ -z "$KUDA_GCP_CREDENTIALS" ]; then + echo "\$KUDA_GCP_CREDENTIALS is undefined." + exit 1 +fi + +echo +echo -e "\e[1m \e[34mKuda GCP provider \e[0m" +echo + +export KUDA_GCP_CREDENTIALS=/secret/$(basename $KUDA_GCP_CREDENTIALS) + +# Set default config. +export KUDA_GCP_CLUSTER_NAME="${KUDA_GCP_CLUSTER_NAME:-kuda}" +export KUDA_GCP_COMPUTE_ZONE="${KUDA_GCP_COMPUTE_ZONE:-us-central1-a}" +export KUDA_GCP_MACHINE_TYPE="${KUDA_GCP_MACHINE_TYPE:-n1-standard-2}" + +export KUDA_DEFAULT_POOL_NUM_NODES="${KUDA_DEFAULT_POOL_NUM_NODES:-1}" +export KUDA_DEFAULT_GPU="${KUDA_DEFAULT_GPU:-k80}" +export KUDA_DEFAULT_USE_PREEMPTIBLE="${KUDA_DEFAULT_USE_PREEMPTIBLE:-true}" + +export KUDA_DEV_APP_NAME="${KUDA_DEV_APP_NAME:-kuda-dev}" +export KUDA_DEV_APP_IMAGE_NAME="${KUDA_DEV_APP_IMAGE_NAME:-kuda-dev-base}" +export KUDA_DEV_APP_IMAGE="${KUDA_DEV_APP_IMAGE:-gcr.io/kuda-project/dev:1.0.0}" +export KUDA_DEV_SYNC_PATH="${KUDA_DEV_SYNC_PATH:-/app_home}" + +# Disable prompts. +gcloud config set survey/disable_prompts true + +# Apply to gcloud config. +gcloud config set project $KUDA_GCP_PROJECT_ID +gcloud config set compute/zone $KUDA_GCP_COMPUTE_ZONE + +# Enable service account from the credential json. +credentials_file=$(basename "$KUDA_GCP_CREDENTIALS") +gcloud auth activate-service-account --key-file /secret/$credentials_file diff --git a/images/providers/gcp/Dockerfile b/images/providers/gcp/Dockerfile new file mode 100644 index 0000000..a49507a --- /dev/null +++ b/images/providers/gcp/Dockerfile @@ -0,0 +1,46 @@ +FROM alpine:3.10 +ARG CLOUD_SDK_VERSION=260.0.0 + +# Google Cloud SDK. +ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION +ENV PATH /google-cloud-sdk/bin:$PATH +RUN apk --no-cache add \ + bash \ + curl \ + python \ + py-crcmod \ + libc6-compat \ + openssh-client \ + git \ + gnupg \ + && curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz && \ + tar xzf google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz && \ + rm google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz && \ + gcloud config set core/disable_usage_reporting true && \ + gcloud config set component_manager/disable_update_check true && \ + gcloud config set metrics/environment github_docker_image && \ + gcloud --version +VOLUME ["/root/.config"] + +# Install Kubectl. +RUN gcloud components install beta kubectl + +# Install Ksync. +RUN curl https://vapor-ware.github.io/gimme-that/gimme.sh | bash + +# Copy the provider's commands. +COPY . /kuda_cmd +ENV KUDA_CMD_DIR /kuda_cmd +RUN chmod +x /kuda_cmd/*.sh +RUN ln -s /kuda_cmd/app_deploy.sh /usr/local/bin/kuda_app_deploy && \ + ln -s /kuda_cmd/app_delete.sh /usr/local/bin/kuda_app_delete && \ + ln -s /kuda_cmd/setup.sh /usr/local/bin/kuda_setup && \ + ln -s /kuda_cmd/delete.sh /usr/local/bin/kuda_delete && \ + ln -s /kuda_cmd/dev_start.sh /usr/local/bin/kuda_dev_start && \ + ln -s /kuda_cmd/dev_stop.sh /usr/local/bin/kuda_dev_stop && \ + ln -s /kuda_cmd/get.sh /usr/local/bin/kuda_get + +# Go to the app home. +WORKDIR /app_home + +ENTRYPOINT ["/bin/bash"] \ No newline at end of file diff --git a/images/providers/gcp/README.md b/images/providers/gcp/README.md new file mode 100644 index 0000000..58438c0 --- /dev/null +++ b/images/providers/gcp/README.md @@ -0,0 +1,9 @@ +## Google Cloud Platform Provider + +Hacky & bare implementation with shell scripts. + +# Limitations + +- The "Compute Engine API - GPUs (all regions)" quota must be requested manually [here](https://console.cloud.google.com/iam-admin/quotas?metric=GPUs%20(all%20regions)) +- Currently the load balancer doesn't get deleted when you delete the cluster. Make sure to delete it manually [here](https://console.cloud.google.com/net-services/loadbalancing/loadBalancers/list) after deleting a cluster to avoid extra costs. +- You can find a list of parameters that you can override in `.config.sh` \ No newline at end of file diff --git a/images/providers/gcp/app_delete.sh b/images/providers/gcp/app_delete.sh new file mode 100644 index 0000000..9ab86f4 --- /dev/null +++ b/images/providers/gcp/app_delete.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +source $KUDA_CMD_DIR/.config.sh + +app_name=$(echo $1 | cut -f1 -d':') +app_version=$(echo $1 | cut -f2 -d':') +app_image="gcr.io/$KUDA_GCP_PROJECT_ID/$app_name:$app_version" +echo $app_image + +# Delete image from the repository. +# gcloud container images delete $app_image + +# Get cluster's credentials to use kubectl. +gcloud container clusters get-credentials $KUDA_GCP_CLUSTER_NAME + +# Launch. +kubectl delete ksvc $app_name \ No newline at end of file diff --git a/images/providers/gcp/app_deploy.sh b/images/providers/gcp/app_deploy.sh new file mode 100755 index 0000000..67205ce --- /dev/null +++ b/images/providers/gcp/app_deploy.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +source $KUDA_CMD_DIR/.config.sh + +app_name=$(echo $1 | cut -f1 -d':') +app_version=$(echo $1 | cut -f2 -d':') +app_image="gcr.io/$KUDA_GCP_PROJECT_ID/$app_name:$app_version" +echo $app_image + +# Build & push using cloud build. +gcloud builds submit --tag $app_image . + +# Get cluster's credentials to use kubectl. +gcloud container clusters get-credentials $KUDA_GCP_CLUSTER_NAME + +# Launch. +cat < Not mandatory +# since the autoscaler will automatically scale down to 0 after a while. +# gcloud container clusters resize $KUDA_GCP_CLUSTER_NAME \ +# --node-pool $KUDA_DEFAULT_GPU \ +# --num-nodes 0 \ +# --quiet \ No newline at end of file diff --git a/images/providers/gcp/get.sh b/images/providers/gcp/get.sh new file mode 100644 index 0000000..5cbfdda --- /dev/null +++ b/images/providers/gcp/get.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +source $KUDA_CMD_DIR/.config.sh + +# Get cluster's credentials to use kubectl. +gcloud container clusters get-credentials $KUDA_GCP_CLUSTER_NAME + +function prop() { + echo -e "\e[1m$1 : \e[34m $2 \e[0m" +} + +# Print the IP Adress of the cluster. +APP_IP_ADDRESS=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') +prop "IP" $APP_IP_ADDRESS diff --git a/images/providers/gcp/setup.sh b/images/providers/gcp/setup.sh new file mode 100755 index 0000000..42ed734 --- /dev/null +++ b/images/providers/gcp/setup.sh @@ -0,0 +1,146 @@ +#!/bin/bash + +set -e + +source $KUDA_CMD_DIR/.config.sh + +# required_addons="HorizontalPodAutoscaling,HttpLoadBalancing,Istio,CloudRun" +required_addons="HorizontalPodAutoscaling,HttpLoadBalancing,Istio" + +function create_main_cluster() { + # Create cluster with the system node pool. + gcloud beta container clusters create $KUDA_GCP_CLUSTER_NAME \ + --addons=$required_addons \ + --machine-type=n1-standard-4 \ + --cluster-version=latest \ + --zone=$KUDA_GCP_COMPUTE_ZONE \ + --scopes cloud-platform \ + --num-nodes $KUDA_DEFAULT_POOL_NUM_NODES \ + --enable-stackdriver-kubernetes \ + --issue-client-certificate \ + --enable-basic-auth \ + --enable-ip-alias \ + --enable-autoupgrade \ + --metadata disable-legacy-endpoints=false + + # Grant cluster-admin permissions to the current user. + kubectl create clusterrolebinding cluster-admin-binding \ + --clusterrole=cluster-admin \ + --user=$(gcloud config get-value core/account) +} + +function create_gpu_nodepools() { + preemptible_mode="" + if [ $KUDA_DEFAULT_USE_PREEMPTIBLE = true ]; then + preemptible_mode='--preemptible' + fi + # Create the default GPU Node pool. + gcloud container node-pools create $KUDA_DEFAULT_GPU \ + --machine-type=$KUDA_GCP_MACHINE_TYPE \ + --accelerator type=nvidia-tesla-$KUDA_DEFAULT_GPU,count=1 \ + --zone $KUDA_GCP_COMPUTE_ZONE \ + --cluster $KUDA_GCP_CLUSTER_NAME \ + --num-nodes 1 \ + --min-nodes 0 \ + --max-nodes 8 \ + --enable-autoupgrade \ + --enable-autoscaling \ + --metadata disable-legacy-endpoints=false \ + $preemptible_mode + + # Install Nvidia Drivers. + nvidia_driver_repo="https://raw.githubusercontent.com/GoogleCloudPlatform/container-engine-accelerators" + nvidia_driver_path="master/nvidia-driver-installer/cos/daemonset-preloaded.yaml" + kubectl apply -f "$nvidia_driver_repo/$nvidia_driver_path" +} + +function install_knative() { + # Apply crd twice as workaround to https://github.com/knative/serving/issues/5722 + kubectl apply --wait=true --selector knative.dev/crd-install=true \ + --filename https://github.com/knative/serving/releases/download/v0.9.0/serving.yaml \ + --filename https://github.com/knative/eventing/releases/download/v0.9.0/release.yaml \ + --filename https://github.com/knative/serving/releases/download/v0.9.0/monitoring.yaml || +   \ + kubectl apply --wait=true --selector knative.dev/crd-install=true \ + --filename https://github.com/knative/serving/releases/download/v0.9.0/serving.yaml \ + --filename https://github.com/knative/eventing/releases/download/v0.9.0/release.yaml \ + --filename https://github.com/knative/serving/releases/download/v0.9.0/monitoring.yaml + + kubectl apply \ + --filename https://github.com/knative/serving/releases/download/v0.9.0/serving.yaml \ + --filename https://github.com/knative/eventing/releases/download/v0.9.0/release.yaml \ + --filename https://github.com/knative/serving/releases/download/v0.9.0/monitoring.yaml +} + +function enable_gcloud_services() { + # Enable the required Gcloud services. + echo "Checking Gcloud services availability..." + gcloud_services=$(gcloud services list) + if [ -z "$(echo $gcloud_services | grep serviceusage)" ]; then + echo "Enabling serviceusage API" + gcloud services enable serviceusage.googleapis.com + fi + if [ -z "$(echo $gcloud_services | grep cloudapis)" ]; then + echo "Enabling serviceusage API" + gcloud services enable cloudapis.googleapis.com + fi + if [ -z "$(echo $gcloud_services | grep container)" ]; then + echo "Enabling container API" + gcloud services enable container.googleapis.com + fi + if [ -z "$(echo $gcloud_services | grep containerregistry)" ]; then + echo "Enabling container registry API" + gcloud services enable containerregistry.googleapis.com + fi + if [ -z "$(echo $gcloud_services | grep cloudbuild)" ]; then + echo "Enabling cloud build API" + gcloud services enable cloudbuild.googleapis.com + fi +} + +enable_gcloud_services + +# Check if cluster already exists otherwise create one. +if gcloud container clusters list | grep -q $KUDA_GCP_CLUSTER_NAME; then + echo "Cluster already exists." +else + echo "Creating new cluster $KUDA_GCP_CLUSTER_NAME" + create_main_cluster +fi + +# Get cluster's credentials to use kubectl. +gcloud container clusters get-credentials $KUDA_GCP_CLUSTER_NAME + +# Check if GPU cluster exists otherwise create one. +if gcloud container node-pools list \ + --zone $KUDA_GCP_COMPUTE_ZONE \ + --cluster $KUDA_GCP_CLUSTER_NAME | grep -q $KUDA_DEFAULT_GPU; then + echo "GPU node pool already exists." +else + echo "Creating new GPU node pool with default GPU $KUDA_DEFAULT_GPU" + create_gpu_nodepools +fi + +# Install Knative. +echo "Installing Knative 0.9.0..." +if kubectl get pods --namespace knative-serving --label-columns=serving.knative.dev/release | grep v0.9.0; then + echo "Knative v0.9.0 is already installed." +else + install_knative +fi + +# Create namespace. +if [ -z "$(kubectl get namespace kuda-app)" ]; then + kubectl create namespace kuda-app +fi + +# Enable Istio sidecar injection. +# kubectl label namespace kuda-app istio-injection=enabled --overwrite=true + +# Mount credentials. +if kubectl get secrets | grep -q $(basename $KUDA_GCP_CREDENTIALS); then + echo "Secret already exists." +else + kubectl create secret generic $(basename $KUDA_GCP_CREDENTIALS) \ + --from-file=$KUDA_GCP_CREDENTIALS +fi \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..686d897 --- /dev/null +++ b/main.go @@ -0,0 +1,22 @@ +/* +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package main + +import "github.com/cyrildiagne/kuda/cmd" + +func main() { + cmd.Execute() +} diff --git a/pkg/docker/run.go b/pkg/docker/run.go new file mode 100644 index 0000000..c4c8682 --- /dev/null +++ b/pkg/docker/run.go @@ -0,0 +1,77 @@ +/* +Package cmd - + +Copyright © 2019 Cyril Diagne . + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package docker + +import ( + "os" + "os/exec" + + "github.com/spf13/viper" +) + +// CommandOption Options to run the RunDockerCommand. +type CommandOption struct { + Image string + Command []string + // Extra values to be appended to viper's config. + AppendVolumes []string + AppendEnv []string +} + +// VolumeMapping maps local volumes to mount in Docker. +// type Volume map[string]string +type VolumeMapping struct { + From string + To string +} + +// RunDockerCommand runs a docker command +// using envs & volumes from viper's config. +func RunDockerCommand(opts CommandOption) error { + // Run docker commands in interactive mode and with TTY with -it. + // Also remove the container as soon as it's been ran with --rm. + args := []string{"run", "-it", "--rm"} + + // Environment Variables. + for _, e := range opts.AppendEnv { + args = append(args, "-e", e) + } + + // Volume mappings. + var configVols []VolumeMapping + viper.UnmarshalKey("volumes", &configVols) + for _, v := range configVols { + args = append(args, "-v", v.From+":"+v.To) + } + for _, v := range opts.AppendVolumes { + args = append(args, "-v", v) + } + + // Set image & command. + args = append(args, opts.Image) + args = append(args, opts.Command...) + + // Run command. + cmd := exec.Command("docker", args...) + cmd.Stdout = os.Stdout + cmd.Stdin = os.Stdin + cmd.Stderr = os.Stderr + err := cmd.Run() + + return err +}