Skip to content

Commit 56fc6b5

Browse files
committed
Implement the alpha version
1 parent 33b8029 commit 56fc6b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1510
-557
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ node_modules
44
dist
55
.tests
66
hvps
7+
lab
8+
.aider*

README.md

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,59 @@
11
# Hosty
22

3-
**This package is still under development, not ready for use yet!**
4-
53
A code based opinionated way to self-host and manage web apps.
64

7-
1. You write code describing what you want to deploy. For example:
5+
# Quick Example
6+
87
```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'
1717
})
1818

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',
2323
branch: 'main',
24+
domain: 'my-api-domain.com',
2425
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+
},
3032
})
3133

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
3537
})
3638

37-
// Deploy the app and database to the server
38-
deploy(server, [db, myapp])
39+
// 3. Deploy
40+
deploy(myVPS, database, api)
41+
run()
3942
```
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!).
4343

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
4549

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)
5854

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)
5958

60-
**This package is still under development, not ready for use yet!**
59+
...

files.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/srv/hosty/
2+
services/
3+
db-foo/
4+
compose.yaml
5+
...
6+
app-foo/
7+
.ports
8+
local ports to use
9+
compose.yaml
10+
source.yaml
11+
repo: 'repo url'
12+
branch: 'deployed branch'
13+
commit: 'last deployed commit hash'
14+
Caddyfile
15+
...
16+
backups/
17+
db-foo/
18+
yyyy-mm-dd_hh-mm-ss.sql.gz
19+
...
20+

src/ansible/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
import { AnyTask, Host, Playbook, Role, Step } from './types.js'
1+
import { AnyTask, Host, Playbook, Step, Tasks } from './types.js'
22

33
export * from './types.js'
44
export * as tasks from './tasks/index.js'
5-
export * as roles from './roles/index.js'
65

76
export function task(data: AnyTask) {
87
return data
98
}
109

11-
export function role(data: Role) {
12-
return data
13-
}
14-
1510
export function host(data: Host) {
1611
return data
1712
}
1813

19-
export function step(host: Host, role: Role): Step {
20-
return {
21-
hosts: host.name,
22-
tasks: role.tasks,
23-
handlers: role.handlers,
24-
}
14+
export function step(host: Host, tasks: Tasks): Step {
15+
return { hosts: host.name, tasks }
2516
}
2617

2718
export function playbook(data: Playbook) {

src/ansible/roles/assert.ts

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/ansible/roles/create_hosty_directory.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/ansible/roles/create_service.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)