Skip to content

Commit

Permalink
Implement the alpha version
Browse files Browse the repository at this point in the history
  • Loading branch information
webNeat committed Sep 7, 2024
1 parent 33b8029 commit 56fc6b5
Show file tree
Hide file tree
Showing 59 changed files with 1,510 additions and 557 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_modules
dist
.tests
hvps
lab
.aider*
83 changes: 41 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,59 @@
# Hosty

**This package is still under development, not ready for use yet!**

A code based opinionated way to self-host and manage web apps.

1. You write code describing what you want to deploy. For example:
# Quick Example

```ts
import {app, deploy, host, database} from 'hosty'

// a Postgres database
const db = database({
type: 'postgres',
name: 'awesome',
user: 'myuser',
pass: 'mypass',
import {app, db, deploy, run} from 'hosty'

// 1. Specify what you want to deploy

// A postgres database
const database = db.postgres({
name: 'my-db',
user: 'db_user',
pass: 'db_pass'
})

// a web app that uses the db above
const myapp = app({
domain: 'your-domain.com',
repo: 'https://github.com/....git',
// An application from a Git repo
const api = app.git({
name: 'my-api',
repo: 'https://url-to-my-repo.git',
branch: 'main',
domain: 'my-api-domain.com',
env: {
DB_HOST: db.host,
DB_USER: db.user,
DB_PASS: db.pass,
DB_NAME: db.name,
}
PORT: '80',
DB_HOST: database.host,
DB_USER: database.user,
DB_PASS: database.pass,
DB_NAME: database.name,
},
})

// The server to which you want to deploy
const server = host({
address: 'domain name or IP'
// 2. Specify where you want deploy
const myVPS = server({
name: '188.114.97.6' // hostname or IP
})

// Deploy the app and database to the server
deploy(server, [db, myapp])
// 3. Deploy
deploy(myVPS, database, api)
run()
```
2. You run `npx hosty deploy` to apply what you described.

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!).

## Prerequisits
This code will do the following:
1. Connect to your server via SSH
2. Create the postgres database
3. Clone your repo, build and run it
4. Configure the domain with https support

1. A Linux server to which you have SSH access.
- This can be a VPS, a home-lab server or any Linux machine that has a static IP.
- The user by which you connect should have the `sudo` ability.
- Only **Ubuntu** servers are supported right now.

2. [Ansible](https://www.ansible.com/) installed on your local machine.

## Get started

```
npm i hosty
```
# Requirements
**On local machine:**
- [Ansible](https://www.ansible.com/) (tested with v2.16.6)
- Nodejs (tested with v22.8)

**On the server**
- A Linux server that uses `apt` and `systemctl` (tested on Ubuntu 22.04)
- A user with `sudo` ability (using the root user is not recommended)

**This package is still under development, not ready for use yet!**
...
20 changes: 20 additions & 0 deletions files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/srv/hosty/
services/
db-foo/
compose.yaml
...
app-foo/
.ports
local ports to use
compose.yaml
source.yaml
repo: 'repo url'
branch: 'deployed branch'
commit: 'last deployed commit hash'
Caddyfile
...
backups/
db-foo/
yyyy-mm-dd_hh-mm-ss.sql.gz
...

15 changes: 3 additions & 12 deletions src/ansible/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import { AnyTask, Host, Playbook, Role, Step } from './types.js'
import { AnyTask, Host, Playbook, Step, Tasks } from './types.js'

export * from './types.js'
export * as tasks from './tasks/index.js'
export * as roles from './roles/index.js'

export function task(data: AnyTask) {
return data
}

export function role(data: Role) {
return data
}

export function host(data: Host) {
return data
}

export function step(host: Host, role: Role): Step {
return {
hosts: host.name,
tasks: role.tasks,
handlers: role.handlers,
}
export function step(host: Host, tasks: Tasks): Step {
return { hosts: host.name, tasks }
}

export function playbook(data: Playbook) {
Expand Down
140 changes: 0 additions & 140 deletions src/ansible/roles/assert.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/ansible/roles/create_hosty_directory.ts

This file was deleted.

75 changes: 0 additions & 75 deletions src/ansible/roles/create_service.ts

This file was deleted.

Loading

0 comments on commit 56fc6b5

Please sign in to comment.