diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..185d46e --- /dev/null +++ b/.dockerignore @@ -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 diff --git a/.env b/.env.example similarity index 75% rename from .env rename to .env.example index c498ab5..17fb0b8 100644 --- a/.env +++ b/.env.example @@ -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" \ No newline at end of file +# Enable to use different location for dev db file +# DATABASE_URL="file:./dev.db" + +# Add your admin Nostr npub +# ADMIN_NPUBS=npub1q2s369... diff --git a/.gitignore b/.gitignore index 2681548..ce46655 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ dist nsecbunker.json connection.txt config +.env diff --git a/Dockerfile b/Dockerfile index f20388c..1eb99be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 6455b67..a998bc6 100644 --- a/README.md +++ b/README.md @@ -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 -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 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 ``` #### Example + ```bash $ npm run nsecbunkerd -- add --name "Uncomfortable family" diff --git a/docker-compose.yml b/docker-compose.yml index 221fd63..3d620b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,32 @@ version: "3.3" services: - nsecbunkerd: - image: nsecbunkerd - build: . - restart: unless-stopped - pids_limit: 50 - mem_limit: 256mb - memswap_limit: 256mb - volumes: - - ./nsecbunker-config:/app/config - command: start --admin + nsecbunkerd: + image: pablof7z/nsecbunkerd + build: . + restart: unless-stopped + pids_limit: 100 + mem_limit: 256mb + memswap_limit: 256mb + volumes: + - $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