|
1 | 1 | # Hosty
|
2 | 2 |
|
3 |
| -**This package is still under development, not ready for use yet!** |
4 |
| - |
5 | 3 | A code based opinionated way to self-host and manage web apps.
|
6 | 4 |
|
7 |
| -1. You write code describing what you want to deploy. For example: |
| 5 | +# Quick Example |
| 6 | + |
8 | 7 | ```ts
|
9 |
| -import {app, deploy, host, database} from 'hosty' |
10 |
| - |
11 |
| -// a Postgres database |
12 |
| -const db = database({ |
13 |
| - type: 'postgres', |
14 |
| - name: 'awesome', |
15 |
| - user: 'myuser', |
16 |
| - pass: 'mypass', |
| 8 | +import {app, db, deploy, run} from 'hosty' |
| 9 | + |
| 10 | +// 1. Specify what you want to deploy |
| 11 | + |
| 12 | +// A postgres database |
| 13 | +const database = db.postgres({ |
| 14 | + name: 'my-db', |
| 15 | + user: 'db_user', |
| 16 | + pass: 'db_pass' |
17 | 17 | })
|
18 | 18 |
|
19 |
| -// a web app that uses the db above |
20 |
| -const myapp = app({ |
21 |
| - domain: 'your-domain.com', |
22 |
| - repo: 'https://github.com/....git', |
| 19 | +// An application from a Git repo |
| 20 | +const api = app.git({ |
| 21 | + name: 'my-api', |
| 22 | + repo: 'https://url-to-my-repo.git', |
23 | 23 | branch: 'main',
|
| 24 | + domain: 'my-api-domain.com', |
24 | 25 | env: {
|
25 |
| - DB_HOST: db.host, |
26 |
| - DB_USER: db.user, |
27 |
| - DB_PASS: db.pass, |
28 |
| - DB_NAME: db.name, |
29 |
| - } |
| 26 | + PORT: '80', |
| 27 | + DB_HOST: database.host, |
| 28 | + DB_USER: database.user, |
| 29 | + DB_PASS: database.pass, |
| 30 | + DB_NAME: database.name, |
| 31 | + }, |
30 | 32 | })
|
31 | 33 |
|
32 |
| -// The server to which you want to deploy |
33 |
| -const server = host({ |
34 |
| - address: 'domain name or IP' |
| 34 | +// 2. Specify where you want deploy |
| 35 | +const myVPS = server({ |
| 36 | + name: '188.114.97.6' // hostname or IP |
35 | 37 | })
|
36 | 38 |
|
37 |
| -// Deploy the app and database to the server |
38 |
| -deploy(server, [db, myapp]) |
| 39 | +// 3. Deploy |
| 40 | +deploy(myVPS, database, api) |
| 41 | +run() |
39 | 42 | ```
|
40 |
| -2. You run `npx hosty deploy` to apply what you described. |
41 |
| - |
42 |
| -That's it, the database is created and your app is now deployed to `https://your-domain.com` (Yes, the SSL certificate is also taken care off!). |
43 | 43 |
|
44 |
| -## Prerequisits |
| 44 | +This code will do the following: |
| 45 | +1. Connect to your server via SSH |
| 46 | +2. Create the postgres database |
| 47 | +3. Clone your repo, build and run it |
| 48 | +4. Configure the domain with https support |
45 | 49 |
|
46 |
| -1. A Linux server to which you have SSH access. |
47 |
| - - This can be a VPS, a home-lab server or any Linux machine that has a static IP. |
48 |
| - - The user by which you connect should have the `sudo` ability. |
49 |
| - - Only **Ubuntu** servers are supported right now. |
50 |
| - |
51 |
| -2. [Ansible](https://www.ansible.com/) installed on your local machine. |
52 |
| - |
53 |
| -## Get started |
54 |
| - |
55 |
| -``` |
56 |
| -npm i hosty |
57 |
| -``` |
| 50 | +# Requirements |
| 51 | +**On local machine:** |
| 52 | +- [Ansible](https://www.ansible.com/) (tested with v2.16.6) |
| 53 | +- Nodejs (tested with v22.8) |
58 | 54 |
|
| 55 | +**On the server** |
| 56 | +- A Linux server that uses `apt` and `systemctl` (tested on Ubuntu 22.04) |
| 57 | +- A user with `sudo` ability (using the root user is not recommended) |
59 | 58 |
|
60 |
| -**This package is still under development, not ready for use yet!** |
| 59 | +... |
0 commit comments