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.

Refactor docker entrypoint

Khuram Niazd821503be980
diff --git a/Dockerfile b/Dockerfile
index 912c8b2..858fa88 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -29,13 +29,12 @@ FROM base AS runner
WORKDIR /app
# Set environment variables
-ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
-RUN apk add --no-cache openssl
+RUN apk add --no-cache openssl su-exec
RUN addgroup --system --gid 1001 nodejs && \
- adduser --system --uid 1001 nextjs
+ adduser --system --uid 1001 -h /home/nextjs nextjs
# Set the correct permission for prerender cache
RUN mkdir .next
@@ -44,8 +43,6 @@ 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
-# Automatically leverage output traces to reduce image size
-
COPY --from=builder /app/public ./public
COPY --from=builder /app/prisma ./prisma
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
diff --git a/deploy.sh b/deploy.sh
index b3c7027..24d5f10 100755
--- a/deploy.sh
+++ b/deploy.sh
@@ -26,7 +26,7 @@ echo ""
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
-echo -e "${GREEN}[1/6]${NC} Current directory: $SCRIPT_DIR"
+echo -e "${GREEN}[1/5]${NC} Current directory: $SCRIPT_DIR"
echo ""
# Detect Docker Compose (standalone v2 or plugin)
@@ -48,56 +48,21 @@ if [ ! -d ".git" ]; then
exit 1
fi
-# Ensure .env exists and AUTH_SECRET is set
-echo -e "${GREEN}[2/6]${NC} Checking environment configuration..."
-
-if [ ! -f ".env" ]; then
- if [ -f ".env.example" ]; then
- cp .env.example .env
- echo -e " Created ${YELLOW}.env${NC} from .env.example"
- else
- echo -e " ${RED}Warning: No .env.example found. Creating empty .env${NC}"
- touch .env
- fi
-fi
-
-# Generate AUTH_SECRET if missing or empty
-if ! grep -q '^AUTH_SECRET=.\+' .env 2>/dev/null; then
- NEW_SECRET=$(openssl rand -base64 32)
- if grep -q '^AUTH_SECRET=' .env 2>/dev/null; then
- # AUTH_SECRET line exists but is empty — replace it (handle macOS vs Linux sed)
- if sed --version >/dev/null 2>&1; then
- sed -i "s|^AUTH_SECRET=.*|AUTH_SECRET=$NEW_SECRET|" .env
- else
- sed -i '' "s|^AUTH_SECRET=.*|AUTH_SECRET=$NEW_SECRET|" .env
- fi
- else
- echo "AUTH_SECRET=$NEW_SECRET" >> .env
- fi
- echo -e " Generated ${YELLOW}AUTH_SECRET${NC} in .env"
-else
- echo -e " AUTH_SECRET already set in .env"
-fi
-
-echo ""
-
# Fetch latest changes
-echo -e "${GREEN}[3/6]${NC} Fetching latest changes from GitHub..."
+echo -e "${GREEN}[2/5]${NC} Fetching latest changes from GitHub..."
git fetch origin
# Checkout and pull the specified branch
-echo -e "${GREEN}[4/6]${NC} Checking out branch: ${YELLOW}$BRANCH${NC}"
+echo -e "${GREEN}[3/5]${NC} Checking out branch: ${YELLOW}$BRANCH${NC}"
git checkout "$BRANCH"
-
-echo -e "${GREEN}[4/6]${NC} Pulling latest changes..."
git pull origin "$BRANCH"
# Stop existing containers
-echo -e "${GREEN}[5/6]${NC} Stopping existing containers..."
+echo -e "${GREEN}[4/5]${NC} Stopping existing containers..."
$COMPOSE_CMD down
# Build and start containers
-echo -e "${GREEN}[6/6]${NC} Building and starting containers..."
+echo -e "${GREEN}[5/5]${NC} Building and starting containers..."
$COMPOSE_CMD up -d --build
echo ""
diff --git a/docker-compose.yml b/docker-compose.yml
index 1611e91..82867a3 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -10,12 +10,13 @@ services:
- NODE_ENV=production
- DATABASE_URL=file:/data/dev.db
- AUTH_SECRET=${AUTH_SECRET:-}
- - NEXTAUTH_URL=${NEXTAUTH_URL}
- - AUTH_TRUST_HOST=true
- - OLLAMA_BASE_URL=${OLLAMA_BASE_URL}
- - OPENAI_API_KEY=${OPENAI_API_KEY}
- - DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY}
- - RAPIDAPI_KEY=${RAPIDAPI_KEY}
+ - NEXTAUTH_URL=${NEXTAUTH_URL:-http://localhost:3000}
+ - AUTH_TRUST_HOST=${AUTH_TRUST_HOST:-true}
+ - TZ=${TZ:-America/Edmonton}
+ - OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://host.docker.internal:11434}
+ - OPENAI_API_KEY=${OPENAI_API_KEY:-}
+ - DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY:-}
+ - RAPIDAPI_KEY=${RAPIDAPI_KEY:-}
volumes:
- ./jobsyncdb/data:/data
restart: unless-stopped
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index 50902b5..79dea26 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -7,6 +7,10 @@ if [ -z "$AUTH_SECRET" ]; then
echo "AUTH_SECRET was not set — generated a temporary secret for this container."
fi
+# Run migrations as root (before switching users)
+npx -y [email protected] migrate deploy
+
# Fix /data permissions and run app as nextjs user
chown -R nextjs:nodejs /data
-exec su -m -s /bin/sh nextjs -c "npx -y [email protected] migrate deploy && node server.js"
+export HOME=/home/nextjs
+exec su-exec nextjs node server.js