add docker support, move to env file, add example

This commit is contained in:
creations 2025-01-05 20:48:29 -05:00
parent 608f4d5e8d
commit 58016ee4ea
Signed by: creations
GPG key ID: 8F553AA4320FC711
7 changed files with 75 additions and 6 deletions

7
.example.env Normal file
View file

@ -0,0 +1,7 @@
PORT=6600
HOST=0.0.0.0
#NODE_ENV=development
#REDIS_HOST=127.0.0.1
#REDIS_PORT=6379
REDIS_PASSWORD=pasw0rd

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/node_modules
bun.lockb
/config/secrets.ts
.env

15
Dockerfile Normal file
View file

@ -0,0 +1,15 @@
# docker/dev.Dockerfile
FROM oven/bun:latest
WORKDIR /app/booru-api
COPY package.json ./
COPY bun.lockb ./
RUN bun install
COPY . .
ENV NEXT_TELEMETRY_DISABLED 1
CMD bun run start

30
compose.yml Normal file
View file

@ -0,0 +1,30 @@
services:
booru-api:
container_name: booru-api
build:
context: .
volumes:
- .:/app/booru-api
restart: unless-stopped
ports:
- "${PORT:-6600}:${PORT:-6600}"
env_file:
- .env
depends_on:
- dragonfly-redis
networks:
- booru-network
dragonfly-redis:
container_name: dragonfly-redis
image: docker.dragonflydb.io/dragonflydb/dragonfly
restart: unless-stopped
environment:
REDIS_PASSWORD: ${redis_password:-pasw0rd}
command: ["--requirepass", "${redis_password:-pasw0rd}"]
networks:
- booru-network
networks:
booru-network:
driver: bridge

View file

@ -1,7 +1,21 @@
import dotenv from "dotenv";
import { logger } from "@/helpers/logger";
try {
dotenv.config();
} catch {
logger.error("No .env file found consider creating one");
}
export const environment: Environment = {
port: 6600,
host: "127.0.0.1",
development:
process.argv.includes("--dev") ||
process.argv.includes("--development"),
port: parseInt(process.env.PORT || "6600", 10),
host: process.env.HOST || "0.0.0.0",
development: process.env.NODE_ENV === "development",
};
export const redisConfig: RedisConfig = {
host: process.env.REDIS_HOST || "dragonfly-redis",
port: parseInt(process.env.REDIS_PORT || "6379", 10),
password: process.env.REDIS_PASSWORD || undefined,
};

View file

@ -27,6 +27,7 @@
},
"type": "module",
"dependencies": {
"dotenv": "^16.4.7",
"redis": "^4.7.0"
}
}

View file

@ -1,4 +1,4 @@
import { redisConfig } from "@config/secrets";
import { redisConfig } from "@config/environment";
import { logger } from "@helpers/logger";
import { createClient, type RedisClientType } from "redis";
@ -23,6 +23,7 @@ class RedisJson {
RedisJson.instance.client.on("error", (err: Error) => {
logger.error("Redis connection error:");
logger.error((err as Error) || "Unknown error");
logger.error(redisConfig.host);
process.exit(1);
});