small adjustemnts in readme and envars

This commit is contained in:
counterweight 2025-10-18 14:34:43 +02:00
parent 11b6aee6e9
commit 40d08e21ae
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
4 changed files with 39 additions and 141 deletions

View file

@ -20,8 +20,6 @@ RUN adduser -S nodejs -u 1001
RUN chown -R nodejs:nodejs /app RUN chown -R nodejs:nodejs /app
USER nodejs USER nodejs
# Expose port
EXPOSE 3000
# Health check # Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \

155
README.md
View file

@ -1,21 +1,28 @@
# ntfy emergency app - Message Webapp # ntfy emergency app - Message Webapp
A simple web application that allows users to send emergency messages through an ntfy server. This is a simple web application that allows users to send emergency messages to a ntfy server.
tldr: I look at messaging apps very infrequently and have no notifications for them. But what happens if there's a real emergency and someone needs to grab my attention? The only app in my phone that has notifications is the ntfy client, which I use to monitor servers and services. Why not receive a ntfy alert? This small webapp lets my trusted ones send me a high priority message if needed.
More details:
- You can deploy in a single `docker run`, simply passing the ntfy details through env vars.
- You can use it with both the official ntfy instance or with a selfhosted instance of your own.
- Deals with ntfy username/password auth if needed.
- No auth or spam protection: either roll your own, or simply pray nobody spams you.
## Installation ## Dev setup
1. Install dependencies: 1. Install dependencies:
```bash ```bash
npm install npm install
``` ```
2. Configure environment variables: 2. Configure environment variables:
```bash ```bash
export NTFY_URL="https://your-ntfy-server.com" cp env.example .env
export NTFY_USER="your-username" # Edit .env with your values
export NTFY_PASSWORD="your-password"
export PORT=3000 # optional, defaults to 3000
``` ```
3. Run the application: 3. Run the application:
@ -23,7 +30,7 @@ export PORT=3000 # optional, defaults to 3000
npm start npm start
``` ```
## Environment Variables ## Environment Variables in detail
- `NTFY_URL`: URL of your ntfy server (required) - `NTFY_URL`: URL of your ntfy server (required)
- `NTFY_USER`: Username for ntfy authentication (required) - `NTFY_USER`: Username for ntfy authentication (required)
@ -31,22 +38,17 @@ npm start
- `NTFY_TOPIC`: ntfy topic/channel to send messages to (optional, defaults to "emergencia") - `NTFY_TOPIC`: ntfy topic/channel to send messages to (optional, defaults to "emergencia")
- `PORT`: Port to run the application on (optional, defaults to 3000) - `PORT`: Port to run the application on (optional, defaults to 3000)
### Docker Registry Variables (Optional) ### Docker Registry Variables (Optional, needed to push to private registry)
Note that we assume that you `docker` cli is authenticated for the registry you want to use.
- `DOCKER_REGISTRY`: Custom registry to publish the image to (optional) - `DOCKER_REGISTRY`: Custom registry to publish the image to (optional)
- `DOCKER_USERNAME`: Username/organization in the registry (optional) - `DOCKER_USERNAME`: Username/organization in the registry (optional)
- `DOCKER_TAG`: Tag for the Docker image (optional, defaults to "latest") - `DOCKER_TAG`: Tag for the Docker image (optional, defaults to "latest")
## Usage
1. Open your browser to `http://localhost:3000` (or the configured port)
2. Fill out the form with your name and message
3. Click "Send Message"
4. You'll receive confirmation if the message was sent successfully
## Deployment ## Deployment
### Option 1: Docker Compose (Recommended) ### Option 1: Docker Run
1. Create a `.env` file with your credentials: 1. Create a `.env` file with your credentials:
```bash ```bash
@ -56,122 +58,39 @@ NTFY_PASSWORD=your-password
NTFY_TOPIC=emergencia NTFY_TOPIC=emergencia
``` ```
2. Run with Docker Compose: 2. Run with Docker:
```bash ```bash
docker-compose up -d docker run -d \
--name ntfy-emergency-app \
-p 3000:3000 \
--env-file .env \
forgejo.contrapeso.xyz/counterweight/ntfy-emergency-app:latest
``` ```
The application will be available at `http://localhost:3000` The application will be available at `http://localhost:3000`
### Option 2: Direct Installation ### Option 2: Direct Installation
To deploy on a Linux server:
1. Upload files to the server 1. Upload files to the server
2. Install Node.js (version 14 or higher) 2. Install Node.js (version 14 or higher)
3. Configure environment variables 3. Create a `.env` file with your credentials:
4. Run `npm install` to install dependencies
5. Run `npm start` to start the application
### systemd Example (optional)
Create file `/etc/systemd/system/ntfy-emergency-app.service`:
```ini
[Unit]
Description=NTFY Emergency App
After=network.target
[Service]
Type=simple
User=your-username
WorkingDirectory=/path/to/ntfy-emergency-app
Environment=NTFY_URL=https://your-ntfy-server.com
Environment=NTFY_USER=your-username
Environment=NTFY_PASSWORD=your-password
Environment=NTFY_TOPIC=emergencia
Environment=PORT=3000
ExecStart=/usr/bin/node server.js
Restart=always
[Install]
WantedBy=multi-user.target
```
Then:
```bash ```bash
sudo systemctl daemon-reload NTFY_URL=https://your-ntfy-server.com
sudo systemctl enable ntfy-emergency-app NTFY_USER=your-username
sudo systemctl start ntfy-emergency-app NTFY_PASSWORD=your-password
NTFY_TOPIC=emergencia
```
4. Install dependencies:
```bash
npm install
```
5. Start the application:
```bash
npm start
``` ```
## Docker Image Publishing ## Docker Image Publishing
### Manual Build and Publishing
#### Option 1: Without custom registry (Docker Hub)
```bash ```bash
# Build and publish
npm run docker:build-tag-push npm run docker:build-tag-push
``` ```
#### Option 2: With custom registry
```bash
# Configure environment variables
export DOCKER_REGISTRY=your-registry.com
export DOCKER_USERNAME=your-username
export DOCKER_TAG=v1.0.0
# Build and publish
npm run docker:build-tag-push
```
#### Option 3: Manual
```bash
docker build -t ntfy-emergency-app .
docker tag ntfy-emergency-app your-registry/ntfy-emergency-app:latest
docker push your-registry/ntfy-emergency-app:latest
```
### Using with Private Registry
To use the image from a private registry:
```bash
# Authenticate with the registry
docker login your-registry.com
# Run the image
docker run -d \
--name ntfy-emergency-app \
-p 3000:3000 \
-e NTFY_URL=https://your-ntfy-server.com \
-e NTFY_USER=your-username \
-e NTFY_PASSWORD=your-password \
-e NTFY_TOPIC=emergencia \
your-registry.com/ntfy-emergency-app:latest
```
## Project Structure
```
ntfy-emergency-app/
├── server.js # Main Express server
├── package.json # Dependencies and scripts
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose orchestration
├── scripts/ # Helper scripts
│ ├── docker-tag.sh # Script to tag images
│ └── docker-push.sh # Script to publish images
├── public/
│ ├── index.html # Main page
│ └── style.css # CSS styles
└── README.md # This file
```
## Notes
- Messages are sent to the topic configured in `NTFY_TOPIC` (defaults to "emergencia")
- Message format is: "Name: Message"
- The application validates that both fields are complete before sending

View file

@ -1,19 +0,0 @@
services:
ntfy-emergency-app:
build: .
container_name: ntfy-emergency-app
ports:
- "3000:3000"
environment:
- NTFY_URL=${NTFY_URL}
- NTFY_USER=${NTFY_USER}
- NTFY_PASSWORD=${NTFY_PASSWORD}
- NTFY_TOPIC=${NTFY_TOPIC:-emergencia}
- PORT=3000
restart: unless-stopped
healthcheck:
test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s

View file

@ -3,9 +3,9 @@ NTFY_URL=https://your-ntfy-server.com
NTFY_USER=your-username NTFY_USER=your-username
NTFY_PASSWORD=your-password NTFY_PASSWORD=your-password
NTFY_TOPIC=emergencia NTFY_TOPIC=emergencia
PORT=3000
# Optional variables for Docker registry # Optional variables for Docker registry
# DOCKER_REGISTRY=your-registry.com # DOCKER_REGISTRY=your-registry.com
# DOCKER_USERNAME=your-username # DOCKER_USERNAME=your-username
# DOCKER_TAG=latest # DOCKER_TAG=latest
# Note: Do not include https:// in DOCKER_REGISTRY