From 33727a431ec752857fc3d6ec267b0113a119536d Mon Sep 17 00:00:00 2001 From: Vasily Zubarev Date: Thu, 20 Mar 2025 21:14:30 +0100 Subject: [PATCH] ci: improve first install --- Dockerfile | 7 ++++++- README.md | 6 ++---- docker-entrypoint.sh | 8 +++----- package.json | 1 + prisma/seed.ts | 30 +++++++++++++++++++++++------- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3ddbd06..843ce66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,11 @@ RUN npm run build # Production stage FROM node:23-slim +# Default environment variables +ENV UPLOAD_PATH=/app/uploads +ENV NODE_ENV=production +ENV DATABASE_URL=file:/app/data/db.sqlite + # Install required system dependencies RUN apt-get update && apt-get install -y \ ghostscript \ @@ -36,7 +41,7 @@ RUN apt-get update && apt-get install -y \ WORKDIR /app # Create upload directory and set permissions -RUN mkdir -p /app/upload && chown -R node:node /app/upload +RUN mkdir -p /app/upload # Copy built assets from builder COPY --from=builder /app/node_modules ./node_modules diff --git a/README.md b/README.md index ac52917..f560b07 100644 --- a/README.md +++ b/README.md @@ -125,10 +125,8 @@ Deploy your own instance of TaxHacker with Vercel in just a few clicks: For server deployment, we provide a [Docker image](./Dockerfile) and [Docker Compose](./docker-compose.yml) files that makes setting up TaxHacker simple: ```bash -# Download docker-compose.yml file curl -O https://raw.githubusercontent.com/vas3k/TaxHacker/main/docker-compose.yml -# Run it docker compose up ``` @@ -191,13 +189,13 @@ npx prisma migrate dev && npx prisma generate # Seed the database with default data (optional) npm run seed -# Start the development server with Turbopack +# Start the development server npm run dev ``` Visit `http://localhost:3000` to see your local instance of TaxHacker. -For a production build: +For a production build, instead of `npm run dev` use the following commands: ```bash # Build the application diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 29ff556..ce82139 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -5,11 +5,9 @@ set -e echo "Running database migrations..." npx prisma migrate deploy -# Run database seeding if SEED_DATABASE is set to true -if [ "$SEED_DATABASE" = "true" ]; then - echo "Seeding database..." - npm run seed -fi +# Initialize database +echo "Checking and seeding database if needed..." +npm run seed # Start the application echo "Starting the application..." diff --git a/package.json b/package.json index 723d131..652459d 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "taxhacker", "version": "0.1.0", "private": true, + "type": "module", "scripts": { "dev": "next dev --turbopack", "build": "next build", diff --git a/prisma/seed.ts b/prisma/seed.ts index 08c1366..b052cd7 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,5 +1,15 @@ import { PrismaClient } from "@prisma/client" -const prisma = new PrismaClient() + +const DATABASE_URL = process.env.DATABASE_URL || "file:./db.sqlite" +const prisma = new PrismaClient({ + datasources: { + db: { + url: DATABASE_URL, + }, + }, +}) + +const forceSeed = process.argv.includes("--force") const settings = [ { @@ -410,13 +420,19 @@ const fields = [ }, ] +async function isDatabaseEmpty() { + const fieldsCount = await prisma.field.count() + return fieldsCount === 0 +} + async function main() { - // Clean up existing data - // await prisma.category.deleteMany({}) - // await prisma.currency.deleteMany({}) - // await prisma.field.deleteMany({}) - // await prisma.setting.deleteMany({}) - // await prisma.project.deleteMany({}) + const isEmpty = await isDatabaseEmpty() + if (!isEmpty && !forceSeed) { + console.log("Database is already seeded. Use 'npm run seed -- --force' to force reseeding.") + return + } + + console.log("Starting database seeding...") // Seed projects for (const project of projects) {