Skip to content

Commit

Permalink
feat: basic deno lightning address server (#1)
Browse files Browse the repository at this point in the history
* feat: basic deno lightning address server

* doc: update readme

* add docker build GH workflow

* return 404 for missing amount instead of Error which uses 5xx

* fix: run db migration at startup

* chore: remove unused field

* feat: encrypt connection secret field

* chore: also deploy  on deno branch

* fix: remove --env from start command

* chore: add volume to fly config

* fix: docker deployment

* fix: fly deploy branch

* fix: properly follow LNURL spec and add LNURL error handling

* doc: update README

* chore: remove feat/deno branch from fly deploy workflow

---------

Co-authored-by: Fmar <[email protected]>
  • Loading branch information
rolznz and frnandu authored Oct 8, 2024
1 parent 3a65a41 commit bd87489
Show file tree
Hide file tree
Showing 29 changed files with 5,166 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fly.toml
node_modules

5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LOG_LEVEL=debug
BASE_URL=http://localhost:8080
DATABASE_URL=postgresql://myuser:mypass@localhost:5432/alby_lite
# generate using deno task db:generate:key
ENCRYPTION_KEY=
22 changes: 22 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Docker build & push
on:
push:
release:
types: [published]
jobs:
build:
env:
REGISTRY: ghcr.io
IMAGENAME: ${{ github.event.repository.name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out code
- name: Docker build
uses: mr-smithers-excellent/docker-build-push@v5
id: build
with:
image: ${{ env.IMAGENAME }}
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- master
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
alby-lite.db*
node_modules
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": ["denoland.vscode-deno"],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
}
}
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM denoland/deno:1.45.5
EXPOSE 8080

WORKDIR /app

COPY . .

USER deno

CMD ["task", "start"]
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# Alby Lite

A minimal LNURL + Zapper service powered powered by [NWC](https://nwc.dev)

## Development

- [Install Deno](https://docs.deno.com/runtime/manual/getting_started/installation/)
- Copy `.env.example` to `.env`
- Setup DB: `deno task db:migrate`
- Run in dev mode: `deno task dev`

### Creating a new migration

- Create the migration files: `deno task db:generate`
- The migration will automatically happen when the app starts.

### Running Tests

`deno task test`

## Deployment

### Run with Deno

`deno task start`

### Docker (from Alby's Container Registry)

`docker run -p 8080:8080 --pull always ghcr.io/getalby/lite:latest`

### Docker (from source)

docker run -p 8080:8080 $(docker build -q .)

### Deploy on Fly

- `fly deploy`
21 changes: 21 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"imports": {
"hono": "jsr:@hono/hono@^4.5.5",
"drizzle-orm": "npm:[email protected]",
"drizzle-kit": "npm:[email protected]",
"postgres": "npm:[email protected]"
},
"tasks": {
"cache": "deno cache ./src/main.ts ./src/db/schema.ts npm:@libsql/client",
"cache:reload": "deno cache --reload ./src/main.ts ./src/db/schema.ts",
"db:generate": "deno run -A --node-modules-dir npm:drizzle-kit generate",
"db:generate:key": "deno run ./src/db/generateKey.ts",
"dev": "deno run --env --allow-net --allow-env --allow-read --allow-write --watch src/main.ts",
"start": "deno run --allow-net --allow-env --allow-read --allow-write src/main.ts",
"test": "deno test --env --allow-env"
},
"compilerOptions": {
"jsx": "precompile",
"jsxImportSource": "hono/jsx"
}
}
Loading

0 comments on commit bd87489

Please sign in to comment.