Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic database setup + docker #28

Merged
merged 30 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f248d95
decoupled app and config
Egge21M May 28, 2024
439246b
added lnurlController tests
Egge21M May 28, 2024
9562912
added lnurl valid request test
Egge21M May 31, 2024
b0d7f53
added lnmock
Egge21M May 31, 2024
6bdb157
added coverage dependencies
Egge21M Jun 3, 2024
f0b2cd3
fixed lnurl test
Egge21M Jun 10, 2024
608d158
added test config
Egge21M Jun 10, 2024
b468a91
added database tests
Egge21M Jun 11, 2024
bb9106b
updated test config
Egge21M Jun 11, 2024
38e583f
added general tests
Egge21M Jun 11, 2024
dbe67b6
updated config
Egge21M Jun 11, 2024
c4971aa
added infoController tests
Egge21M Jun 11, 2024
2dbd0a6
middleware tests
Egge21M Jun 11, 2024
c604af3
added node-pg-migrate + npm scripts
Egge21M May 18, 2024
cb3a4b2
added init migration
Egge21M May 18, 2024
99d0c2d
added migrate to dependecies
Egge21M May 18, 2024
214add5
removed db migration from start script
Egge21M May 18, 2024
6159125
updated migration file
Egge21M Jun 3, 2024
cc535da
added setup function
Egge21M Jun 3, 2024
76d274c
added dockerfile
Egge21M Jun 3, 2024
da0f110
fixed migrations in docker
Egge21M Jun 3, 2024
a3eb428
added deploy docs
Egge21M Jun 3, 2024
ac81994
updated docs
Egge21M Jun 5, 2024
29919f8
added workspace package.json to dockerfile
Egge21M Jun 6, 2024
7c5018f
automatic callback setup
Egge21M Jun 10, 2024
9f924c4
updated frontend
Egge21M Jun 11, 2024
0b1e5d2
fixed frontend in docker
Egge21M Jun 12, 2024
880269d
removed unused npm script
Egge21M Jun 13, 2024
d2f137a
clean up
Egge21M Jun 16, 2024
62ebace
added error handling to info controller
Egge21M Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
coverage
dist
.env
37 changes: 37 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "3.9"

services:
postgres:
image: postgres:alpine
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=test
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
networks:
- common-net
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

server:
build: .
depends_on:
postgres:
condition: service_healthy
ports:
- "8000:5000"
environment:
- PGPASSWORD=test
- PGDATABASE=postgres
- PGUSER=postgres
- PGHOST=postgres
- PGPORT=5432
networks:
- common-net

networks:
common-net: {}
40 changes: 40 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM node:18-alpine AS base

FROM base AS deps

RUN apk add --no-cache libc6-compat

WORKDIR /app

COPY package.json package-lock.json* ./
COPY npubcash-website/package.json npubcash-website/package-lock.json* ./npubcash-website/

RUN npm ci

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN npm run build

FROM base AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 npc

COPY --from=builder --chown=npc:nodejs /app/dist ./dist
COPY --from=builder --chown=npc:nodejs /app/npubcash-website/dist ./npubcash-website/dist
COPY --from=builder --chown=npc:nodejs /app/migrations ./migrations

USER npc

EXPOSE 8000

ENV PORT 8000


CMD node dist/index.js
79 changes: 79 additions & 0 deletions docs/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Deploy npub.cash

## Prerequisites

In order to deploy npub.cash yourself you will need:

- A postgres database to connect to
- A Blink API account

## Deploy npubcash-server

Deploying npubcash-server is easy. There are two ways to deploy the app:

### Docker

npub.cash ships with a dockerfile. Clone the repository, build the image and deploy it.

```sh
git clone -b migrations --recurse-submodules https://github.com/cashubtc/npubcash-server.git

cd npubcash-server

docker build -t npc-server .
```

Once deployed make sure to set your environment variables accordingly (see below)

### Manually

You can also build the application code yourself and deploy it Manually

```sh
git clone -b migrations --recurse-submodules https://github.com/cashubtc/npubcash-server.git

cd npubcash-server

npm ci

npm run build
```

Once deployed you can start the service using `npm run start`. Make sure to set your environment variables accordingly (see below)

### Env variables

npubcash-server needs a couple of environment variables to run.

```sh
#Your database connection settings
PGUSER=
PGPASSWORD=
PGHOST=
PGDATABASE=
PGPORT=
# The url of the default mint
MINTURL=
# You Blink API settings
BLINK_API_KEY=
BLINK_WALLET_ID=
BLINK_URL=
# The nostr private key used by the NIP-57 provider
ZAP_SECRET_KEY=
# LNURL settings
LNURL_MIN_AMOUNT=
LNURL_MAX_AMOUNT=
# The hostname your app will be reached under
HOSTNAME=
```

## Setup Blink

Right now there is no way for a mint to let you know once an invoice has been paid (until websockets are merged soon(tm)).
Therefore npubcash-server uses Blink as a wrapper. You need to configure your Blink API credentials in your environment and then add your servers webhook url to Blink.
Open the Blink Callback [Dashboard](https://dashboard.blink.sv/callback) and add your webhook url. It will be `https://<your hostname>/api/v1/paid`

## Setup locally

It is possible to quickly setup npubcash-server locally for development using the `compose.yaml` file.
However as the service relies on Blinks webhook integration, you will need to have the machine running the server reachable publicly and add its IP to the Blink dashboard
Loading