feat: cleanup docker setup

- Add .dockerignore
- Replace .env with .env.example
- Add migrations service
- Cleanup Dockerfile: simpler setup, simpler copy, no migrations inside the image
- Update README to match new instruction
This commit is contained in:
Nour 2024-01-23 17:43:02 +00:00
parent c92b169435
commit 1d4251c23e
No known key found for this signature in database
GPG Key ID: 9744560DE7DA09AE
6 changed files with 90 additions and 46 deletions

20
.dockerignore Normal file
View File

@ -0,0 +1,20 @@
node_modules/
.env
.git/
.gitignore
.npmrc
.dockerignore
.DS_Store
npm-debug.log
logs/
tmp/
coverage/
dist/
*.md
*.tar.gz
*.zip
Dockerfile
nsecbunker.json
connection.txt
config

View File

@ -4,4 +4,8 @@
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="file:./dev.db"
# Enable to use different location for dev db file
# DATABASE_URL="file:./dev.db"
# Add your admin Nostr npub
# ADMIN_NPUBS=npub1q2s369...

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ dist
nsecbunker.json
connection.txt
config
.env

View File

@ -1,31 +1,26 @@
FROM node:20-alpine AS build
FROM node:20.11-bullseye AS build
WORKDIR /app
# Install dependencies
RUN apk update && \
apk add --no-cache openssl python3 make g++ \
&& ln -sf python3 /usr/bin/python
# Copy package files and install dependencies
COPY package.json package-lock.json ./
COPY package*.json ./
RUN npm install
# Copy application files
COPY src/ src/
COPY scripts/ scripts/
COPY prisma/schema.prisma prisma/
COPY tsconfig.json ./
COPY . .
# Generate prisma client and build the application
RUN npx prisma generate
RUN npm run build
# Runtime stage
FROM node:20-alpine
FROM node:20.11-alpine as runtime
WORKDIR /app
RUN apk update && \
apk add --no-cache openssl
apk add --no-cache openssl && \
rm -rf /var/cache/apk/*
# Copy built files from the build stage
COPY --from=build /app .
@ -33,11 +28,7 @@ COPY --from=build /app .
# Install only runtime dependencies
RUN npm install --only=production
# Copy and run migrations
COPY --from=build /app/prisma ./prisma
RUN npx prisma migrate deploy
RUN npx prisma db push
EXPOSE 3000
# Set entrypoint
ENTRYPOINT [ "node", "scripts/start.js" ]
ENTRYPOINT [ "node", "./dist/index.js" ]
CMD ["start"]

View File

@ -1,36 +1,44 @@
# nsecbunkerd
Daemon to remotely sign nostr events using keys.
## Easy setup via docker
## Easy setup via docker compose
To quickly install `nsecbunkerd` via Docker just run:
### Prepare your config directory
```
### Configurations
Prepare your config directory
```shell
mkdir $HOME/.nsecbunker-config
```
Clone `.env.example` and add your nostr public key to `ADMIN_NPUBS` to the `.env` file.
```shell
cp .env.example .env
```
### Start nsecbunkerd
```
docker run -d --name nsecbunkerd -v $HOME/.nsecbunker-config:/app/config pablof7z/nsecbunkerd start --admin <your-npub>
docker exec -i nsecbunkerd npx prisma db push
```
Create and start the project containers. This runs the migrations and then runs nsecbunkderd container.
#### Docker-compose
Edit `docker-compose.yml` and add your nostrpublic key in `command` directive, like `start --admin npub1nftkhktqglvcsj5n4wetkpzxpy4e5x78wwj9y9p70ar9u5u8wh6qsxmzqs`
```shell
# Optionally, build the image locally
docker compose build nsecbunkerd
And start the container
```
# Start the project
docker compose up
# Or in the background
docker compose up -d
docker compose exec nsecbunker npx prisma db push
```
### Get the connection string
```
docker exec nsecbunkerd cat /app/connection.txt
```shell
docker compose exec nsecbunkerd cat /app/connection.txt
```
nsecBunker will give you a connection string like:
@ -47,7 +55,7 @@ to find the options to add and approve keys from the CLI.
Node.js v18 or newer is required.
```
```shell
git clone <nsecbunkerd-repo>
npm i
npm run build
@ -71,11 +79,12 @@ Note that ONLY the npub that you designated as an administrator when launching n
Here you'll give nsecBunker your nsec. It will ask you for a passphrase to encrypt it on-disk.
The name is an internal name you'll use to refer to this keypair. Choose anything that is useful to you.
```
```shell
npm run nsecbunkerd -- add --name <your-key-name>
```
#### Example
```bash
$ npm run nsecbunkerd -- add --name "Uncomfortable family"

View File

@ -2,12 +2,31 @@ version: "3.3"
services:
nsecbunkerd:
image: nsecbunkerd
image: pablof7z/nsecbunkerd
build: .
restart: unless-stopped
pids_limit: 50
pids_limit: 100
mem_limit: 256mb
memswap_limit: 256mb
volumes:
- ./nsecbunker-config:/app/config
command: start --admin <npub>
- $HOME/.nsecbunker-config:/app/config
env_file:
- .env.example
ports:
- "3000:3000"
depends_on:
- migrations
migrations:
image: pablof7z/nsecbunkerd
volumes:
- $HOME/.nsecbunker-config:/app/config
env_file:
- .env.example
restart: no
entrypoint: ""
command:
- npx
- prisma
- migrate
- deploy