From 1a6650b9d51286279f8f8ff69eeb93c3abef8b2f Mon Sep 17 00:00:00 2001 From: Erno Aapa Date: Sat, 29 Dec 2018 20:14:22 +0200 Subject: [PATCH] Added nodejs example --- README.md | 7 +++++-- examples/nodejs/.gitignore | 1 + examples/nodejs/README.md | 18 ++++++++++++++++++ examples/nodejs/index.js | 6 ++++++ examples/nodejs/package.json | 30 ++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 examples/nodejs/.gitignore create mode 100644 examples/nodejs/README.md create mode 100644 examples/nodejs/index.js create mode 100644 examples/nodejs/package.json diff --git a/README.md b/README.md index fd3ac0a..f84a339 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ kubectl (Kubernetes CLI) plugin to syncronize local files to _Pod_ and executing This can be used for example to build and run your local project in Kubernetes while using your prefed editor locally. ## Install -## MacOS with Brew +### MacOS with Brew ```shell brew install ernoaapa/kubectl-plugins/warp ``` -## Linux / MacOS without Brew +### Linux / MacOS without Brew 1. Download binary from [releases](https://github.com/ernoaapa/kubectl-warp/releases) 2. Add it to your `PATH` @@ -19,6 +19,9 @@ When the plugin binary is found from `PATH` you can just execute it through `kub kubectl warp --help ``` +### Examples +There's some examples with different languages in [examples directory](examples/) + ## Development ### Prerequisites - Golang v1.11 diff --git a/examples/nodejs/.gitignore b/examples/nodejs/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/examples/nodejs/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/examples/nodejs/README.md b/examples/nodejs/README.md new file mode 100644 index 0000000..5d04fb4 --- /dev/null +++ b/examples/nodejs/README.md @@ -0,0 +1,18 @@ +# kubectl warp NodeJS example +This is an example of using `kubectl warp` for developing NodeJS app "real-time" in Kubernetes cluster. + +`kubectl warp` start temporary _Pod_ and keep your local files insync so that you can make changes to files locally, but run the actual code in the Kubernetes cluster. + +## Prerequisites +- Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) +- Install [kubectl warp](https://github.com/ernoaapa/kubectl-warp#install) + +Here we +1. start official `node` Docker image in Kubernetes +2. sync current directory to the container +3. run `npm install` +4. start watching changes with `npm run watch` command + +```shell +kubectl warp -i -t --image node nodejs-example -- npm install && npm run watch +``` diff --git a/examples/nodejs/index.js b/examples/nodejs/index.js new file mode 100644 index 0000000..dff10ca --- /dev/null +++ b/examples/nodejs/index.js @@ -0,0 +1,6 @@ + +var startTime = new Date(); + +setInterval(function () { + console.log('Hello world! (started at ' + startTime.toISOString() + ')') +}, 1000); diff --git a/examples/nodejs/package.json b/examples/nodejs/package.json new file mode 100644 index 0000000..41960ac --- /dev/null +++ b/examples/nodejs/package.json @@ -0,0 +1,30 @@ +{ + "name": "kubectl-warp-example", + "version": "1.0.0", + "description": "Example NodeJS project for demostrating kubectl warp command", + "main": "index.js", + "scripts": { + "start": "node index.js", + "watch": "nodemon index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ernoaapa/kubectl-warp.git" + }, + "keywords": [ + "kubernetes", + "kubectl", + "warp", + "rsync" + ], + "author": "Erno Aapa ", + "license": "MIT", + "bugs": { + "url": "https://github.com/ernoaapa/kubectl-warp/issues" + }, + "homepage": "https://github.com/ernoaapa/kubectl-warp#readme", + "dependencies": { + "nodemon": "^1.18.9" + } +}