项目作者: mardix

项目描述 :
An itty-bitty PaaS that uses git push to deploy micro-services and websites on your own servers, like Okurrr!!!
高级语言: Python
项目地址: git://github.com/mardix/polybox.git
创建时间: 2019-12-03T05:52:26Z
项目社区:https://github.com/mardix/polybox

开源协议:MIT License

下载


:+: Sailor :+:


About

Sailor is a tiny PaaS to install on your servers/VPS (DigitalOcean, Hetzner, Linode).

It uses git push to deploy micro-apps, micro-services and sites.

It natively supports Python, Nodejs, Static sites, and any other languages that can use the command line.

Sites deployed with Sailor automatically have SSL assigned with LetsEncrypt.

Sailor can run long-running background workers and cron jobs.

It allows you to deploy multiple sites/apps using a single repository.

It gives you the option of having testing/staging/production environment deployed from the same codebase.

Sailor let’s you see some stats about your apps, along with scaling them.

Sailor makes deploying apps a smooth sailing.

Ship it like a Sailor!


Features

  • Automatic HTTPS
  • Git Push deployment
  • Deploy multiple apps on a single server / VPS
  • Deploy multiple apps from a single repository
  • Runs long running apps
  • Runs workers/background applications
  • Easy configuration with sailor.yml manifest
  • Easy command line setup
  • Cron-like/Scheduled script executions
  • App management: ls, start, stop, reload, rm, stop, scale, log, info etc
  • Run scripts during application lifecycle: release, predeploy, postdeploy, destroy
  • SSL/HTTPS with LetsEncrypt and ZeroSSL
  • Supports any Shell script, therefore any other languages are supported
  • Metrics to see app’s health
  • Create static sites
  • Multi languages: Python, Nodejs, PHP, HTML/Static
  • Support Flask, Django, Express, etc…
  • Python >= 3.8
  • Nginx
  • Logs

+ Getting Started

1. Server Requirements

  • Fresh server (highly recommended)
  • SSH to server with root access
  • Ubuntu 22.04

2. Install Sailor on the server

On the server, run the code below to setup the environment for Sailor and install all its dependencies. A new user, sailor, will be created and will be used to interact with SSH for Sailor.

  1. curl https://raw.githubusercontent.com/mardix/sailor/master/install.sh > install.sh
  2. chmod 755 install.sh
  3. ./install.sh

3. Setup Git on local repo

On your local machine, point a Git remote to your Sailor server (set in step 2), with sailor as username.

Format: git remote add sailor sailor@$host:$app_name

With:

  • $host The server name or IP address
  • $app_name The name of the application, that is set in the sailor.yml (the manifest to deploy)

Example: git remote add sailor sailor@my-server-host.com:myappname.com


+ Getting work done!

1. Work on your app…

…go into your repo and do what you do best, like a sailor!

2. Edit Sailor.yml

At the root of your app directory, create sailor.yml (required).

  1. # sailor.yml
  2. ---
  3. apps:
  4. # -> with remote: sailor@$host:myapp.com
  5. - name: myapp.com
  6. runtime: python
  7. process:
  8. web:
  9. cmd: app:app
  10. server_name: myapp.com
  11. workers: 2
  12. cron: "0 0 * * * python backup.py"
  13. myownworker: python events-listener.py
3. Add Git Remote

Example: git remote add sailor sailor@$host:myapp.com

4. Deploy

Push your code: git push sailor master

5. Profit!

We did it, Okurrr!


+ Sailor Commands

Sailor communicates with your server via SSH, with the user name: sailor

You must already already have SSH access to the machine for it to work.

ie: ssh sailor@$host

List all commands
  1. ssh sailor@$host
List all apps: ls
  1. ssh sailor@$host ls

The command above will show the minimal info. To expand:

  1. ssh sailor@$host ls x
Start app: start $app_name
  1. ssh sailor@$host start $app_name
Stop app: stop $app_name
  1. ssh sailor@$host stop $app_name
Remove app: rm $app_name

To completely delete the application

  1. ssh sailor@$host rm $app_name

To force remove an app without prompt rm -f $app_name

  1. ssh sailor@$host rm -f $app_name
Reload app: reload $app_name

To reload a running application

  1. ssh sailor@$host reload $app_name
Show app info: info $app_name
  1. ssh sailor@$host info $app_name
Show app log: log $app_name
  1. ssh sailor@$host log $app_name
Reset SSL: reset-ssl $app_name

To re-issue the SSL

  1. ssh sailor@$host reset-ssl $app_name
Scale app’s workers

To increase/decrease the total workers for this process

  1. ssh sailor@$host scale $app_name $proc=$count $proc2=$count2

Example:

  1. ssh sailor@$host scale site.com web=4
Reload all apps: reload-all
  1. ssh sailor@$host apps:reload-all
Stop all apps: stop-all
  1. ssh sailor@$host apps:stop-all

— Misc —

Show the version: x:version
  1. ssh sailor@$host system:version
Update the system x:update

To update Sailor to the latest from Github

  1. ssh sailor@$host system:update

Additionally, you can update from a specific branch, usually for testing purposes

  1. ssh sailor@$host system:update $branch-name

About

Sailor is a utility to install on a host machine, that allows you to deploy multiple apps, micro-services, webites, run scripts and background workers on a single VPS (Digital Ocean, Linode, Hetzner).

Sailor follows a process similar to Heroku or Dokku where you Git push code to the host and Sailor will:

  • create an instance on the host machine
  • deploy the new code
  • create virtual environments for your application
  • get a free SSL from LetsEncrypt and assign it to your domain
  • execute scripts to be executed
  • put your application online
  • monitor the application
  • restart the application if it crashes

Sailor supports deployment for:

  • Python (Flask/Django)
  • Nodejs (Express)
  • PHP
  • HTML (React/Vuejs/Static).
  • any of shell scripts

Why Sailor?

Sailor is a simpler alternative to Docker containers or Dokku. It mainly deals with your application deployment, similar to Heroku.

Sailor takes away all the complexity of Docker Containers or Dokku and gives you something simpler to deploy your applications, similar to Heroku, along with SSL.


Languages Supported

  • Python
  • Nodejs
  • Static HTML
  • PHP
  • Any shell script

Using Sailor

Sailor supports a Heroku-like workflow, like so:

  • Create a git SSH remote pointing to your Sailor server with the app name as repo name.
    git remote add sailor sailor@[yourserver]:[appname].
  • Push your code: git push sailor master.
  • Sailor determines the runtime and installs the dependencies for your app (building whatever’s required).
    • For Python, it installs and segregates each app’s dependencies from requirements.txt into a virtualenv.
    • For Node, it installs whatever is in package.json into node_modules.
  • It then looks at sailor.yml and starts the relevant applications using a generic process manager.
  • You can optionally also specify a release worker which is run once when the app is deployed.
  • A static worker type, with the root path as the argument, can be used to deploy a gh-pages style static site.

sailor.yml

sailor.yml is a manifest format for describing apps. It declares environment variables, scripts, and other information required to run an app on your server. This document describes the schema in detail.

sailor.yml contains an array of all apps to be deploy, and they are identified by name.

When setting up the remote, the name must match the name in the sailor.yml

  1. # ~ Sailor ~
  2. # sailor.yml
  3. # Sailor Configuration (https://mardix.github.io/sailor)
  4. #
  5. ---
  6. # *required: list/array of all applications to run
  7. apps:
  8. -
  9. # *required - the name of the application
  10. name:
  11. # runtime: python|node|static|shell
  12. # python for wsgi application (default python)
  13. # node: for node application, where the command should be ie: 'node inde.js 2>&1 | cat'
  14. # static: for HTML/Static page and PHP
  15. # shell: for any script that can be executed via the shell script, ie: command 2>&1 | cat
  16. runtime: static
  17. # auto_restart (bool): to force server restarts when deploying
  18. auto_restart: true
  19. # static_paths (array): specify list of static path to expose, [/url:path, ...]
  20. static_paths:
  21. # SSL issuer: letsencrypt(default)|zerossl
  22. ssl_issuer: letsencrypt
  23. # threads (int): The total threads to use
  24. threads: 4
  25. # wsgi (bool): if runtime is python by default it will use wsgi, if false it will fallback to the command provided
  26. wsgi: true
  27. # nginx (object): nginx specific config. can be omitted
  28. nginx:
  29. include_file: ''
  30. # uwsgi (object): uwsgi specific config. can be omitted
  31. uwsgi:
  32. gevent: false
  33. asyncio: false
  34. # env (object) custom environment variable
  35. env:
  36. KEY: VALUE
  37. KEY2: VALUE2
  38. # scripts to run during application lifecycle
  39. scripts:
  40. # release (array): commands to execute each time the application is released/pushed
  41. release:
  42. # destroy (array): commands to execute when the application is being deleted
  43. destroy:
  44. # predeploy (array): commands to execute before spinning the app
  45. predeploy:
  46. # postdeploy (array): commands to execute after spinning the app
  47. postdeploy:
  48. # *required - process - list of all processes to run.
  49. # 'web' is special, it’s the only process type that can receive external HTTP traffic
  50. # only one web proctype can exist
  51. # all other process name will be regular worker.
  52. # The name doesn't matter
  53. process:
  54. # == web
  55. # (dict/object): it’s the only process type that can receive external HTTP traffic
  56. web:
  57. # == (required) cmd(str) - the command to execute
  58. #-> cmd: app:app (for python using wsgi)
  59. #-> cmd: node server.js 2>&1 cat (For other web app which requires a server command)
  60. #-> cmd: /web-root-dir-name (for static html+php)
  61. cmd:
  62. # == (required) server_name(str)
  63. # the server name without http/https
  64. server_name:
  65. # == server_port(str)
  66. # to use IP/PORT based instead of server_name. To give access to http://IP:8080
  67. # ie:
  68. # server_name: _ # server_name must be set to '_'
  69. # server_port: 8080
  70. server_port:
  71. # === workers(int)
  72. # the number of workers to run, by default 1
  73. workers: 1
  74. # === enabled(bool)
  75. # a boolean to enable/disable this process, by default true
  76. enabled: true
  77. # ==
  78. # other processes (string): command to run, with a name. The name doesn't matter - It can be named anything
  79. worker1:
  80. # == (required) cmd(str) - the command to execute
  81. cmd:
  82. # === workers(int)
  83. # the number of workers to run, by default 1
  84. workers: 1
  85. # === enabled(bool)
  86. # a boolean to enable/disable this process, by default true
  87. enabled: true
  88. # ==
  89. # for simplicity you can pass the command in the name as a string
  90. # workerX: python script.py
  91. workerX:
  92. # == cron
  93. # Cron proc allows you to run script periodically like cronjob
  94. # similar to web, only one cron can exist. And it can only have 1 worker
  95. # Also, put the cron in quotes to prevent deploy error
  96. # Simple cron expression:
  97. # minute [0-59], hour [0-23], day [0-31], month [1-12], weekday [1-7] (starting Monday, no ranges allowed on any field)
  98. # cron: "* * * * * python cron.py"
  99. cron:

FAQ

How to deploy site with IP and PORT (without SERVER_NAME) ?

You can deploy a site without a server name.

The server IP will be used instead of a server name

You need to set the web.server_port to the desired port.

Beware the connection will not be behind NGINX nor use SSL.

This option is mainly for internal or IP based app.

  1. # example sailor.yml
  2. ...
  3. process:
  4. web:
  5. ...,
  6. #-- set server name to _
  7. server_name: _
  8. #-- set server port
  9. server_port: 8081

TODO

  • Allow multiple server name on same app with their own ssl
  • Auto scaling, up to a max workers

CHANGELOG

  • 0.12.0

    • Now installs on Ubuntu 22.04
    • Supports Python 3.11 as python3.11
    • Ubuntu 20.04 is still supported by using install-2004.sh
  • 0.11.1

    • Update command rm -f|--force to force remove an application without the prompt. ie: sailor rm -f $app_name
  • 0.11.0

    • Added possibility to deploy site without server_name but using IP and desired PORT
    • Change commands to be more streamline
      • ls
      • start
      • rm
      • x:update
      • x:version
  • 0.10.0

    • Rebranding Sailor
    • Added process option enabled to run/not-run a process. Especially if you don’t want to run a process without removing the code.
    • Fixed undefined value in setup_node_runtime
    • fixed bindaddress bug
  • 0.5.0

    • Added revision hash info and deploy time.
    • Log deploy info
  • 0.4.0

    • added new proctype ‘cron’ To help execute cron. cron workers, which require a simplified cron expression preceding the command to be run (e.g. cron: * * * * * python batch.py to run a batch every minyte
      1. proces:
      2. cron: "* * * * * python cron.py"
    • expand process list to allow process to have extended properties as dict/hash:

      1. process:
      2. web:
      3. cmd:
      4. server_name:
      5. workers:
      6. others:
      7. cmd:
      8. workers:
    • renamed command: ‘app’ -> ‘apps’
    • fixed bug: log issues due to permission
    • remove environment settings from command. Can now be added in the yml file
    • server_name can now be added in process.web.server_name
    • allow to system:update to be able to update from a different branch system:update 1.2.0
  • 0.3.1

    • fixed letsencrypt issue
  • 0.2.0

    • Rebranding Boxie to Sailor with Cardi B image, Okrrrrrr! (joke, joke)
    • Remove Python 2 support.
    • Recommend Ubuntu 20.04.
    • Added separate install process for Ubuntu 2018.04
    • Added custom index.html page
    • Added aplication/json in nginx
    • No longer supports self-signed SSL
  • 0.1.0

    • Initial
    • sailor.yml contains the application configuration
    • ‘app.run.web’ is set for static/web/wsgi command. Static accepts one path
    • added ‘cli.upgrade’ to upgrade to the latest version
    • ‘sailor.json’ can now have scripts to run
    • ‘uwsgi’ and ‘nginx’ are hidden, ‘app.env’ can contain basic key
    • ‘app.static_paths’ is an array
    • Fixed python virtualenv setup, if the repo was used for a different runtime
    • Simplifying “web” worker. No need for static or wsgi.
    • Python default to wsgi worker, to force to a standalone set env.wsgi: false
    • reformat uwsgi file name ‘{app-name}_{kind}.{index}.ini’ (3 underscores)
    • static sites have their own directives
    • combined static html & php
    • Support languages: Python(2, 3), Node, Static HTML, PHP
    • simplify command name
    • added metrics
    • Letsencrypt
    • ssl default
    • https default
    • Multiple domain name deployment
      ```

Alternatives

Credit: Sailor is a fork of Piku https://github.com/piku/piku. Great work and Thank you.


Author: Mardix

License: MIT

Copyright 2021, 2022 to Forever