GithubHelp home page GithubHelp logo

kubesail / deploy-node-app Goto Github PK

View Code? Open in Web Editor NEW
399.0 10.0 17.0 2.34 MB

Deploy your node.js app to Kubernetes with a single command. No config required.

License: MIT License

JavaScript 91.35% Shell 0.69% Dockerfile 0.80% HTML 2.04% CSS 1.07% Python 1.65% Ruby 2.41%
nodejs deployments tools javascript kubernetes docker

deploy-node-app's Introduction

deploy-node-app

npm version

Deploy apps to Kubernetes, with zero config!

deploy-node-app will prompt you with a minimal set of questions required to deploy your app to any Kubernetes cluster. If zero-config with no lock-in sounds too good to be true - remember this project is in beta 😉. However, it mostly works, and deploy-node-app also supports more than just Node.js projects! Try it on a Python or Ruby project or a static site project!

Once you've run deploy-node-app in your project, you can commit your .dna.json file and use deploy-node-app with no prompts in the future (works great for CI too!).

Instructions

Just run npx deploy-node-app in your node project.

Example

What does this tool do?

deploy-node-app is a project bootstrapper, powered by Skaffold. After answering a few questions about your app, this tool can:

  1. Create a Dockerfile, skaffold.yaml and all the Kubernetes YAML you need!
  2. Automatically provision common dependencies (like redis and postgres)!
  3. Develop and deploy your app on any Kubernetes cluster

Essentially, deploy-node-app supercharges any web applications with awesome tools and best practices.

Usage and examples

Usage: deploy-node-app [env] [action]

Options:
  -V, --version                        output the version number
  -w, --write                          Write files to project (writes out Dockerfile, skaffold.yaml, etc)
  -u, --update                         Update existing files (default: false)
  -f, --force                          Dont prompt if possible (default: false)
  -l, --label [foo=bar,tier=service]   Add labels to created Kubernetes resources
  -t, --target <path/to/project>       Target project directory (default: ".")
  -c, --config <path/to/kubeconfig>    Kubernetes configuration file (default: "~/.kube/config")
  -m, --modules <redis,postgres>       Explicitly add modules

By default, deploy-node-app will write a few files to your directory, and by default files won't be touched if they've been modified. deploy-node-app by itself is the same as deploy-node-app production deploy

Simply run npx deploy-node-app in your repository. The tool will attempt to prompt you when it needs answers to questions, and do it's best to bootstrap your application. Take a look at supported languages - we're always looking to add more!

Tests-as-examples

Take a look at /test for a growing list of examples!

Dependencies

deploy-node-app knows about dependencies! For example, if you install a redis or postgres driver for Node.js, Python, Ruby and more, deploy-node-app will automatically create Redis or Postgres deployments that work with your app!

Suggested tools:

  • kubectl - required for creating your deployment, and recommended for managing your deployment after created
  • Skaffold - Kubernetes workflow utility

deploy-node-app is created and maintained by

Kubesail
KubeSail - Kubernetes for Human Beings


Contributing

If you feel that this tool can be improved in any way, feel free to open an issue or pull request!

deploy-node-app's People

Contributors

dependabot[bot] avatar erulabs avatar pastudan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deploy-node-app's Issues

Subdirectory support?

Hi!

I'm just getting set up with BYOC mode, and building images in my cluster with a private registry is just streets ahead of anything else I've found - SO much nicer than the typical AWS ECR auth song and dance.

However, my project is set up as a monorepo with apps in subdirectories, with a nonstandard Dockerfile image for production. Am I missing existing support for this in the build configuration, or is this a feature you'd consider putting on the roadmap?

Thanks!
Jeff

calls to "execSync" should inherit users environment

A reminder for myself, will issue a PR shortly.

Calls to execSync should almost always inherit the users environment variables, particularly when using docker or kubectl cli tools. This will allow users to override DOCKER_HOST, KUBECONFIG, etc, and in general behave more often "as expected" (ie: docker-machine would currently not work properly, as it relies on environment variables being passed to docker).

A wrapper like:

const execSyncWithEnv = (cmd, args, options = {}) => {
  execSync(cmd, args, Object.assign({}, options, {
    env: Object.assign({}, process.env, options.env)
  }));
}

Should be all we need

deploy-node-app requires kubectl > 1.14.1

I am trying out KubeSail with a sample NodeJS app. Running deploy-node-app, it gets as far as the command:

kubectl --context=kubesail-fineline apply -f deployment-prod.yaml

And gives the following error:

error: SchemaError(io.k8s.api.authorization.v1.SubjectAccessReviewSpec): invalid object doesn't have additional properties

If I try and run that command directly at the command line I get the same error.

I tested another kubectl command:

kubectl get deployments

And that one runs OK and successfully retrieves the list of my kubesail deployments.

get UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toString' of null

Hi.
trying to npx deploy-node-app and get : " UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toString' of null"
the complete log :

npx: installed 120 in 22.963s
(node:1196) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'toString' of null
at execSyncWithEnv (C:\Users\Administrator\AppData\Roaming\npm-cache_npx\1196\node_modules\deploy-node-app\src\util.js:151:55)
at ensureBinaries (C:\Users\Administrator\AppData\Roaming\npm-cache_npx\1196\node_modules\deploy-node-app\src\util.js:164:24)
at DeployNodeApp (C:\Users\Administrator\AppData\Roaming\npm-cache_npx\1196\node_modules\deploy-node-app\src\deployNodeApp.js:509:30)
at Object. (C:\Users\Administrator\AppData\Roaming\npm-cache_npx\1196\node_modules\deploy-node-app\src\index.js:38:1)
at Module._compile (internal/modules/cjs/loader.js:1147:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
at Module.load (internal/modules/cjs/loader.js:996:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at C:\Program Files\nodejs\node_modules\npm\node_modules\libnpx\index.js:268:14
(node:1196) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:1196) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Deploy of node.js express + mongodb app failing

npx deploy-node-app -f

? What is the container image name for our project? To use docker hub, try username/project-name. Note: Make sure this is marked private, or it may be automatically created as a public image! babvin/writersadda

/home/vinay/.npm/_npx/b1f1036aac97e0d1/node_modules/deploy-node-app/src/languages/nodejs.js:33
if (!entrypoint.startsWith('npm') && !entrypoint.startsWith('node')) {
^

TypeError: Cannot read properties of undefined (reading 'startsWith')
at Object.entrypoint (/home/vinay/.npm/_npx/b1f1036aac97e0d1/node_modules/deploy-node-app/src/languages/nodejs.js:33:21)
at promptForEntrypoint (/home/vinay/.npm/_npx/b1f1036aac97e0d1/node_modules/deploy-node-app/src/deployNodeApp.js:101:63)
at generateArtifact (/home/vinay/.npm/_npx/b1f1036aac97e0d1/node_modules/deploy-node-app/src/deployNodeApp.js:625:56)
at async init (/home/vinay/.npm/_npx/b1f1036aac97e0d1/node_modules/deploy-node-app/src/deployNodeApp.js:759:17)
at async DeployNodeApp (/home/vinay/.npm/_npx/b1f1036aac97e0d1/node_modules/deploy-node-app/src/deployNodeApp.js:855:3)

Node.js v20.10.0

kubernetes-models-ts

Not a bug or a feature per-se. Just want to raise awareness of this great package.

https://github.com/tommy351/kubernetes-models-ts

It has TypeScript interfaces and objects for all Kubernetes objects.

It's part of kosko, but not tightly integrated and stands well on it's own.

I've been using it and experimenting with it. I think it can go well with this package and we don't have to write YAML and can take advantage of OO inheritance and config via JS code, rather than YAML templating.

If you want, I can share my private repo with you that has some POC WIP code.

The future of Deployment - a Dream Setup

From the perspective of a developer, the following would be a dream setup.

I define "environments" where:

  • An environment defines the system requirements
  • Environments can be run on different machines

I define these environments declaratively with .env.json files. For example:

// my-app/backend/.env.json

{
  "name": "backend",
  "dependencies": {
    "python": "^3.7.4",
    "postgresql": "^12.0"
  },
  "devDependencies": { // Dependencies for development
    "git": "^2.7.4"
  },
  "prodDependencies": { // Dependencies for production
    "openssh": "^8.1" // Allow machines to connect to the server
  },
}
// my-app/frontend/.env.json

{
  "name": "frontend",
  "dependencies": {
    "nodejs": "^12.2.0" // The frontend is a Node.js server
  },
  "devDependencies": {
    "git": "^2.7.4"
  },
  "prodDependencies": {
    "openssh": "^8.1",
    "certbot": "^1.15.0" // To get HTTPS certificate
  },
}

While developing my app, I run all these environments on my personal machine.

Once I want to deploy, I give you guys a set of repositories and you take care of the rest:

  • You search in my repositories for .env.json files
  • You automatically spin up a new (virtual) machine and run all my environments on this single machine.
  • You monitor the machine running my environments and as the load hits the performance limits of the machine, you spin up new machines running my environments and distribute load between these machines.

This is high level and the devil is in the details. To name a few:

  • How do you determine what environment to scale up? You'd need to now what process belongs to what environment.
  • A stateless process is easy to scale up, but what about a database? The machines running my database need to communicate with each other. Maybe you could provide a kubesail library that provides the list of the IP address of all machines running the database so that I can properly configure PostgreSQL? Is a list of IP addresses sufficient to configure PostgreSQL?
  • Will certbot still work when the frontend is being scaled up to several machines?

But such details are not my point. My point is that, as an open source community, we should all work together towards that dream: we should develop tools that helps us get there.

AFAICT Docker is very far away from that dream. Not only is it far away but it is actually a step in the wrong direction: I don't see how Docker contributes to this dream.

On the other hand, Nix (https://github.com/NixOS/nix) gets us much closer to the dream.

To set it as a hyperbole; Docker is a devil disguised as an angel that insidiously gets us closer to hell. Nix, on the other hand, is a good Samaritan that shows us the way to heaven. It's Nix that showed me that system requirements can be defined in a declarative way and, for that, I will forever be grateful and appreciative of the Nix community.

Whether or not Nix will be the right tool for you guys, I don't know; that's your job to figure that out. All I want, as a mere developer, is my dream.

Needless to say that if you guys get us to the dream, you're in for a big big winning lottery ticket.

Single machine/wm deploy instead of Kubernetes

deploy-node-app looks neat, I was thinking of doing something like that in the context of Reframe. I might as well just use what your building. Cool.

Kubernetes is great to scale up, but for prototypes and small/medium traffic apps, it's overkill.

What do you think of supporting single machine/vm deployments with Nix? That'd be easier for smaller projects.

If my app has lots of traffic, chances are that I have the money to hire a devOp and I don't need deploy-node-app anymore.

It's also nice to have a similar env in prod than in dev (a single machine/vm deployment is closer to my dev machine than a kube deployment).

npm start stopped working on Windows

Hi,

I've been using your package to create and run an application. However, this stopped working about 2 months ago and I'm not sure what caused it - I've just had the chance to delve into what is going on.

When I run npm start I've been getting the following:

[api] >> Command "git grep "^.env$" .gitignore" failed to run
[api] bash ./bin/dev_api.sh exited with code 1
--> Sending SIGTERM to other processes..
[www] Starting the development server...

The API fails to start, because git grep throws an error.

If I comment the following lines in deployNodeApp.js:373-376 out, npm start begins working again:

 if (opts.generateDefaultEnv || opts.generateLocalPortsEnv) {
    const envVars = await generateEnv(metaModules, opts.generateLocalPortsEnv ? format : null)
    const envVarLines = []
    for (const env in envVars) {
      envVarLines.push(`${env}=${envVars[env]}`)
    }
    const content = envVarLines.join('\n') + '\n'
    //checkForGitIgnored('.env')
    //if (format === 'k8s') {
    //  checkForGitIgnored('secrets/')
    //}
    if (output === '-') process.stdout.write(content)
    else await confirmWriteFile('.env', { content, output })
    return null
  }

Not sure what this code is supposed to do - but I assume it's necessary, so not sure how to resolve.
I'm unsure if this is something I've changed in my project, or whether something else has caused this.

Any ideas?

Custom Dockerfile/skaffold.yml support

From the developer's perspective (and from kubesail customer's perspective), I would definitely be happy if you add support of building from my custom Dockerfile & skaffold.yml files; otherwise, the CI/CD integration between kubesail and git is pointless since it can not build my scala projects.

Config file tool - cannot connect to localhost.

npx deploy-node-app

will then ask you if you would like to use the tool to create a Kubernetes config. if you hit yes, it opens a browser that goes to kubesail.com momentarily, then attempts to redirect back to localhost

Screen Shot 2019-04-24 at 4 37 44 pm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.