Deploy
This is ready for deployment using both Docker and Node.
Docker is recommended. If using Node you need a Redis server.
Public Server:
https://badges.cssnr.com/
To Docker
This is designed to be deployed with Docker Compose which includes redis.
To deploy to a Standalone Docker host, see docker-compose.yaml.
To deploy to a Swarm cluster using Traefik, see docker-compose-swarm.yaml.
To run directly, you need to set the REDIS_URL
. You can NOT use localhost
in docker.
docker run -e "REDIS_URL=redis://redis:6379" -p 80:3000 ghcr.io/smashedr/node-badges:latest
Change 80
to the host port you want the app to listen on.
The container port should be 3000
unless you set the PORT
variable.
docker run -e "REDIS_URL=redis://redis:6379" -e "PORT=80" -p 80:80 ghcr.io/smashedr/node-badges:latest
Compose Examples
💡 Click on a heading to expand/collapse the item.
Basic
app:
image: ghcr.io/smashedr/node-badges:latest
env:
REDIS_URL: 'redis://redis:6379'
With Healthcheck
app:
image: ghcr.io/smashedr/node-badges:latest
env:
REDIS_URL: 'redis://redis:6379'
healthcheck:
test: ['CMD-SHELL', 'curl -sf localhost:3000/app-health-check || exit 1']
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
Full Stack Example
services:
nginx:
image: ghcr.io/cssnr/docker-nginx-proxy:latest
environment:
- SERVICE_NAME=app
- SERVICE_PORT=3000
depends_on:
- app
ports:
- '${PORT:-80}:80'
app:
image: ghcr.io/smashedr/node-badges:latest
depends_on:
- redis
redis:
image: redis:6-alpine
command: 'redis-server --appendonly yes'
volumes:
- redis_data:/data
volumes:
redis_data:
Swarm with Traefik
version: '3.8'
services:
nginx:
image: ghcr.io/cssnr/docker-nginx-proxy:latest
environment:
- SERVICE_NAME=app
- SERVICE_PORT=3000
deploy:
replicas: 1
resources:
limits:
cpus: '1.0'
memory: 64M
labels:
- traefik.enable=true
- traefik.docker.network=traefik-public
- traefik.constraint-label=traefik-public
- traefik.http.routers.node-badges-http.rule=Host(`badges.cssnr.com`)
- traefik.http.routers.node-badges-http.entrypoints=http
- traefik.http.routers.node-badges-http.middlewares=https-redirect
- traefik.http.routers.node-badges-https.rule=Host(`badges.cssnr.com`)
- traefik.http.routers.node-badges-https.entrypoints=https
- traefik.http.routers.node-badges-https.tls=true
- traefik.http.services.node-badges-https.loadbalancer.server.port=80
healthcheck:
test: ['CMD-SHELL', 'curl -sf localhost:80/health-check || exit 1']
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
depends_on:
- app
networks:
- internal
- traefik-public
app:
image: ghcr.io/smashedr/node-badges:latest
deploy:
replicas: 1
resources:
limits:
cpus: '2.0'
memory: 256M
healthcheck:
test: ['CMD-SHELL', 'curl -sf localhost:3000/app-health-check || exit 1']
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
depends_on:
- redis
networks:
- internal
redis:
image: redis:6-alpine
command: 'redis-server --appendonly yes'
deploy:
replicas: 1
resources:
limits:
cpus: '1.0'
memory: 128M
volumes:
- redis_data:/data
networks:
- internal
volumes:
redis_data:
networks:
internal:
driver: overlay
traefik-public:
external: true
To Node
This is ready to be deployed to services like Render using their Redis (Render Key Value) store. You can set the redis server url with the REDIS_URL
environment variable. The default value is redis://redis:6379
.
The server listens on the PORT
environment variable and installs/starts normally.
npm install
npm start
To use without redis, install node-cache
, comment out the redis lines, and uncomment the node-cache lines.
API Keys
API Keys and secrets are provided as environment variables.
Variable | Description |
---|---|
VT_API_KEY | VirusTotal API Token |
GITHUB_TOKEN | GitHub PAT (no permissions) |
Endpoints that require/recommend API keys.
Endpoint | Required | Recommended |
---|---|---|
/vt/** | VT_API_KEY | GITHUB_TOKEN |
Currently, the only endpoints that require API keys are the VirusTotal endpoints.
Resources
The app loads all Simple Icon and Lucide Icon into memory. This makes the base memory usage about ~100 MB
. Therefore, you should allocate at least 128 MB
for request overhead.
NAME MEM USAGE
smashedr-node-badges_app 95.31MiB
smashedr-node-badges_redis 3.68MiB
smashedr-node-badges_nginx 4.984MiB
Workflows
You can copy my deploy.yaml which deploys to both Render and Portainer. This is also configured automatically after a successful Build job has completed, or manually.
There is also render.yaml
files for Dockerfile and Node deployments here.
Developing
You can run the dev server with Docker compose or Node run.
With Docker
Docker includes Redis and live server reloading with the docker-compose-dev.yaml file.
docker compose -f "docker-compose-dev.yaml" up --build --remove-orphans --force-recreate
Then visit: http://localhost/
How Live Reloading Works in Docker
This mounts the ./src
directory into the container for live reloading with nodemon
.
To use a different source path set the APP_FILES
environment variable to your source.
For more details, see the docker-compose-dev.yaml file.
With Node
Make sure you have a redis server running and set the REDIS_URL
environment variable.
export REDIS_URL=redis://localhost:6379
npm i
npm run dev
Then visit: http://localhost:3000/
With Custom Port
To use a different port set the PORT
environment variable then run the dev server.
export PORT=8080
Work in Progress
These docs are not yet complete. See the README.md on GitHub for more details.