Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Optimize dockerfile

Khuram Niaz212d87e29972
diff --git a/Dockerfile b/Dockerfile
index 9598358..b081f6c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,10 +1,8 @@
-# Use the official Node.js 22 LTS image as the base image
FROM node:20.18.0-alpine AS base
# Install dependencies only when needed
FROM base AS deps
-# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
# Set the working directory
WORKDIR /app
@@ -32,7 +30,6 @@ WORKDIR /app
# Set environment variables
ENV NODE_ENV=production
-# Comment the following line in case you do not want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs && \
@@ -45,14 +42,12 @@ RUN chown nextjs:nodejs .next
# Set up /data directory with the right permissions
RUN mkdir -p /data/files/resumes && chown -R nextjs:nodejs /data/files/resumes
-RUN npm install [email protected] --no-save
+# RUN npm install [email protected] --no-save
# Automatically leverage output traces to reduce image size
-# https://nextjs.org/docs/advanced-features/output-file-tracing
+
COPY --from=builder /app/public ./public
COPY --from=builder /app/prisma ./prisma
-COPY --from=builder /app/src/lib/data ./src/lib/data
-COPY --from=builder /app/node_modules/bcryptjs ./node_modules/bcryptjs
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
@@ -61,6 +56,5 @@ EXPOSE 3000
ENV PORT=3000
# Start as root, fix /data permissions, then run app as nextjs user
-# Using 'su' which is built into Alpine base image
CMD chown -R nextjs:nodejs /data && \
- exec su -s /bin/sh nextjs -c "npx prisma migrate deploy && npm run seed && node server.js"
+ exec su -s /bin/sh nextjs -c "npx -y [email protected] migrate deploy && node server.js"
diff --git a/prisma/seed.js b/prisma/seed.js
deleted file mode 100644
index 807bea3..0000000
--- a/prisma/seed.js
+++ /dev/null
@@ -1,100 +0,0 @@
-const { STATUS_DATA, JOB_SOURCES } = require("../src/lib/data/seedData");
-
-const { PrismaClient } = require("@prisma/client");
-const bcrypt = require("bcryptjs");
-
-const prisma = new PrismaClient();
-
-async function seedUser() {
- try {
- const email = process.env.USER_EMAIL;
- if (!email || email.trim() === "") {
- console.warn(
- "\x1b[33m[WARNING] USER_EMAIL environment variable is blank or not set. Please set USER_EMAIL in your .env file. Seeding will continue, but user will not be created.\x1b[0m"
- );
- return;
- }
- const password = await bcrypt.hash(process.env.USER_PASSWORD, 10);
- // Check if the user already exists
- const existingUser = await prisma.user.findUnique({
- where: {
- email,
- },
- });
- if (!existingUser) {
- await prisma.user.create({
- data: {
- email,
- name: "Admin",
- password,
- },
- });
- console.log("Seeded new user: ", { email });
- } else {
- console.log("User already exists: ", { email });
- }
- } catch (error) {
- console.error("Error seeding user: ", error);
- throw error;
- }
-}
-
-async function seedStatus() {
- try {
- const statuses = STATUS_DATA;
- for (const status of statuses) {
- // Check if the status already exists
- const existingStatus = await prisma.jobStatus.findUnique({
- where: {
- value: status.value,
- },
- });
-
- // If the status does not exist, create it
- if (!existingStatus) {
- await prisma.jobStatus.create({
- data: status,
- });
- }
- }
- console.log("Seeded statuses");
- } catch (error) {
- console.error("Error seeding status: ", error);
- throw error;
- }
-}
-
-async function seedJobSouces() {
- try {
- const sources = JOB_SOURCES;
- for (const source of sources) {
- const { label, value } = source;
- await prisma.jobSource.upsert({
- where: {
- value,
- },
- update: { label, value },
- create: { label, value },
- });
- }
- console.log("Seeded job sources");
- } catch (error) {
- console.error("Error seeding job sources: ", error);
- throw error;
- }
-}
-
-async function main() {
- await seedUser();
- await seedStatus();
- await seedJobSouces();
-}
-
-main()
- .catch((e) => {
- console.error(e);
- process.exit(1);
- })
- .finally(async () => {
- await prisma.$disconnect();
- });
diff --git a/src/instrumentation.ts b/src/instrumentation.ts
new file mode 100644
index 0000000..47ae674
--- /dev/null
+++ b/src/instrumentation.ts
@@ -0,0 +1,6 @@
+export async function register() {
+ if (process.env.NEXT_RUNTIME === "nodejs") {
+ const { runSeed } = await import("@/lib/seed");
+ await runSeed();
+ }
+}
diff --git a/src/lib/data/seedData.js b/src/lib/data/seedData.js
deleted file mode 100644
index 2e284de..0000000
--- a/src/lib/data/seedData.js
+++ /dev/null
@@ -1,26 +0,0 @@
-const STATUS_DATA = [
- { label: "Draft", value: "draft" },
- { label: "Applied", value: "applied" },
- { label: "Interview", value: "interview" },
- { label: "Offer", value: "offer" },
- { label: "Rejected", value: "rejected" },
- { label: "Expired", value: "expired" },
- { label: "Archived", value: "archived" },
-];
-
-const JOB_SOURCES = [
- { label: "Indeed", value: "indeed" },
- { label: "Linkedin", value: "linkedin" },
- { label: "Monster", value: "monster" },
- { label: "Glassdoor", value: "glassdoor" },
- { label: "Company Career page", value: "careerpage" },
- { label: "Google", value: "google" },
- { label: "ZipRecruiter", value: "ziprecruiter" },
- { label: "Job Street", value: "jobstreet" },
- { label: "Other", value: "other" },
-];
-
-module.exports = {
- STATUS_DATA,
- JOB_SOURCES,
-};
diff --git a/src/lib/seed.ts b/src/lib/seed.ts
new file mode 100644
index 0000000..bee2ca1
--- /dev/null
+++ b/src/lib/seed.ts
@@ -0,0 +1,86 @@
+import prisma from "@/lib/db";
+
+// @ts-expect-error - no types for bcryptjs
+import bcrypt from "bcryptjs";
+
+const STATUS_DATA = [
+ { label: "Draft", value: "draft" },
+ { label: "Applied", value: "applied" },
+ { label: "Interview", value: "interview" },
+ { label: "Offer", value: "offer" },
+ { label: "Rejected", value: "rejected" },
+ { label: "Expired", value: "expired" },
+ { label: "Archived", value: "archived" },
+];
+
+const JOB_SOURCES = [
+ { label: "Indeed", value: "indeed" },
+ { label: "Linkedin", value: "linkedin" },
+ { label: "Monster", value: "monster" },
+ { label: "Glassdoor", value: "glassdoor" },
+ { label: "Company Career page", value: "careerpage" },
+ { label: "Google", value: "google" },
+ { label: "ZipRecruiter", value: "ziprecruiter" },
+ { label: "Job Street", value: "jobstreet" },
+ { label: "Other", value: "other" },
+];
+
+async function seedUser() {
+ const email = process.env.USER_EMAIL;
+ if (!email || email.trim() === "") {
+ console.warn(
+ "[seed] USER_EMAIL not set, skipping user creation"
+ );
+ return;
+ }
+
+ const existingUser = await prisma.user.findUnique({
+ where: { email },
+ });
+
+ if (!existingUser) {
+ const password = await bcrypt.hash(process.env.USER_PASSWORD || "", 10);
+ await prisma.user.create({
+ data: {
+ email,
+ name: "Admin",
+ password,
+ },
+ });
+ console.log("[seed] Created user:", email);
+ }
+}
+
+async function seedStatuses() {
+ for (const status of STATUS_DATA) {
+ const existing = await prisma.jobStatus.findUnique({
+ where: { value: status.value },
+ });
+ if (!existing) {
+ await prisma.jobStatus.create({ data: status });
+ }
+ }
+ console.log("[seed] Statuses ready");
+}
+
+async function seedJobSources() {
+ for (const source of JOB_SOURCES) {
+ await prisma.jobSource.upsert({
+ where: { value: source.value },
+ update: { label: source.label, value: source.value },
+ create: { label: source.label, value: source.value },
+ });
+ }
+ console.log("[seed] Job sources ready");
+}
+
+export async function runSeed() {
+ try {
+ await seedUser();
+ await seedStatuses();
+ await seedJobSources();
+ console.log("[seed] Database seeding complete");
+ } catch (error) {
+ console.error("[seed] Error during seeding:", error);
+ }
+}