chore: update Dockerfile to include scripts directory and modify start command for production; add default admin password to ENV.md
This commit is contained in:
@@ -61,6 +61,3 @@ docker-compose.dev.yml
|
|||||||
# documentation
|
# documentation
|
||||||
README.md
|
README.md
|
||||||
docs
|
docs
|
||||||
|
|
||||||
# scripts
|
|
||||||
scripts
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ RUN pnpm prisma generate
|
|||||||
# Copy source files
|
# Copy source files
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
COPY public ./public
|
COPY public ./public
|
||||||
|
COPY scripts ./scripts
|
||||||
|
|
||||||
# Build the application
|
# Build the application
|
||||||
RUN pnpm build
|
RUN pnpm build
|
||||||
@@ -64,6 +65,7 @@ COPY --from=builder /app/.next ./.next
|
|||||||
COPY --from=builder /app/public ./public
|
COPY --from=builder /app/public ./public
|
||||||
COPY --from=builder /app/next-env.d.ts ./
|
COPY --from=builder /app/next-env.d.ts ./
|
||||||
COPY --from=builder /app/tailwind.config.ts ./
|
COPY --from=builder /app/tailwind.config.ts ./
|
||||||
|
COPY --from=builder /app/scripts ./scripts
|
||||||
|
|
||||||
# Add non-root user for security
|
# Add non-root user for security
|
||||||
RUN addgroup --system --gid 1001 nodejs && \
|
RUN addgroup --system --gid 1001 nodejs && \
|
||||||
@@ -83,5 +85,5 @@ EXPOSE 3000
|
|||||||
HEALTHCHECK --interval=30s --timeout=3s \
|
HEALTHCHECK --interval=30s --timeout=3s \
|
||||||
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1
|
||||||
|
|
||||||
# Start the application
|
# Start the application (init DB then start)
|
||||||
CMD ["pnpm", "start"]
|
CMD ["pnpm", "start:prod"]
|
||||||
3
ENV.md
3
ENV.md
@@ -11,6 +11,9 @@ MONGODB_URI=mongodb://admin:your-secure-password@mongodb:27017/stripstream?authS
|
|||||||
NEXTAUTH_SECRET=your-secret-key-here-generate-with-openssl-rand-base64-32
|
NEXTAUTH_SECRET=your-secret-key-here-generate-with-openssl-rand-base64-32
|
||||||
NEXTAUTH_URL=http://localhost:3020
|
NEXTAUTH_URL=http://localhost:3020
|
||||||
|
|
||||||
|
# Admin User (optional - default password for julienfroidefond@gmail.com)
|
||||||
|
ADMIN_DEFAULT_PASSWORD=Admin@2025
|
||||||
|
|
||||||
# Node Environment
|
# Node Environment
|
||||||
NODE_ENV=production
|
NODE_ENV=production
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
|
"start:prod": "node scripts/init-db.mjs && pnpm start",
|
||||||
|
"init-db": "node scripts/init-db.mjs",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"icons": "node scripts/generate-icons.js"
|
"icons": "node scripts/generate-icons.js"
|
||||||
|
|||||||
75
scripts/init-db.mjs
Executable file
75
scripts/init-db.mjs
Executable file
@@ -0,0 +1,75 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Script d'initialisation de la base de données
|
||||||
|
* Exécuté au démarrage de l'application
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { PrismaClient } from "@prisma/client";
|
||||||
|
import bcrypt from "bcryptjs";
|
||||||
|
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
|
const ADMIN_EMAIL = "julienfroidefond@gmail.com";
|
||||||
|
const ADMIN_PASSWORD = process.env.ADMIN_DEFAULT_PASSWORD || "Admin@2025";
|
||||||
|
|
||||||
|
async function initializeAdminUser() {
|
||||||
|
try {
|
||||||
|
// Vérifier si l'utilisateur existe déjà
|
||||||
|
const existingAdmin = await prisma.user.findUnique({
|
||||||
|
where: { email: ADMIN_EMAIL },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (existingAdmin) {
|
||||||
|
// Vérifier si l'utilisateur a le rôle admin
|
||||||
|
const hasAdminRole = existingAdmin.roles.includes("ROLE_ADMIN");
|
||||||
|
|
||||||
|
if (hasAdminRole) {
|
||||||
|
console.log(`✅ Admin user ${ADMIN_EMAIL} already exists with admin role`);
|
||||||
|
} else {
|
||||||
|
// Ajouter le rôle admin
|
||||||
|
const updatedRoles = Array.from(new Set([...existingAdmin.roles, "ROLE_ADMIN"]));
|
||||||
|
await prisma.user.update({
|
||||||
|
where: { email: ADMIN_EMAIL },
|
||||||
|
data: { roles: updatedRoles },
|
||||||
|
});
|
||||||
|
console.log(`✅ Admin role added to ${ADMIN_EMAIL}`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Créer l'utilisateur admin
|
||||||
|
const hashedPassword = await bcrypt.hash(ADMIN_PASSWORD, 10);
|
||||||
|
await prisma.user.create({
|
||||||
|
data: {
|
||||||
|
email: ADMIN_EMAIL,
|
||||||
|
password: hashedPassword,
|
||||||
|
roles: ["ROLE_USER", "ROLE_ADMIN"],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`✅ Admin user created: ${ADMIN_EMAIL}`);
|
||||||
|
console.log(` Default password: ${ADMIN_PASSWORD}`);
|
||||||
|
console.log(` ⚠️ Please change the password after first login!`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ Error initializing admin user:", error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
console.log("🔧 Initializing database...");
|
||||||
|
|
||||||
|
try {
|
||||||
|
await initializeAdminUser();
|
||||||
|
console.log("✅ Database initialization completed");
|
||||||
|
process.exit(0);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ Database initialization failed:", error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
|
|
||||||
Reference in New Issue
Block a user