fix: Add Chromium to Docker for PDF certificate generation
- Install chromium in Alpine Dockerfile - Add PUPPETEER_EXECUTABLE_PATH env var support - Fallback to system Chrome paths if bundled Chrome not found Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,11 @@ COPY package*.json ./
|
|||||||
# Inštalácia závislostí (len produkčné)
|
# Inštalácia závislostí (len produkčné)
|
||||||
RUN npm ci --only=production
|
RUN npm ci --only=production
|
||||||
|
|
||||||
|
# Inštalácia Chromium pre generovanie PDF certifikátov
|
||||||
|
RUN apk add --no-cache chromium
|
||||||
|
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
|
||||||
|
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
||||||
|
|
||||||
# Kopírovanie zdrojového kódu
|
# Kopírovanie zdrojového kódu
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
COPY drizzle.config.js ./
|
COPY drizzle.config.js ./
|
||||||
|
|||||||
@@ -294,10 +294,48 @@ export const generateCertificate = async (registraciaId, templateName = 'AIcerti
|
|||||||
// Launch Puppeteer and generate PDF
|
// Launch Puppeteer and generate PDF
|
||||||
let browser;
|
let browser;
|
||||||
try {
|
try {
|
||||||
browser = await puppeteer.launch({
|
const launchOptions = {
|
||||||
headless: true,
|
headless: true,
|
||||||
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// Use PUPPETEER_EXECUTABLE_PATH env var if set (for Docker), otherwise try system paths
|
||||||
|
const executablePath = process.env.PUPPETEER_EXECUTABLE_PATH;
|
||||||
|
if (executablePath) {
|
||||||
|
launchOptions.executablePath = executablePath;
|
||||||
|
logger.info(`Using Chrome from PUPPETEER_EXECUTABLE_PATH: ${executablePath}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
browser = await puppeteer.launch(launchOptions);
|
||||||
|
} catch (launchError) {
|
||||||
|
// If no env var set, try common system Chrome paths
|
||||||
|
if (!executablePath) {
|
||||||
|
const systemChromePaths = [
|
||||||
|
'/usr/bin/chromium-browser',
|
||||||
|
'/usr/bin/chromium',
|
||||||
|
'/usr/bin/google-chrome',
|
||||||
|
'/usr/bin/google-chrome-stable',
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const chromePath of systemChromePaths) {
|
||||||
|
try {
|
||||||
|
await fs.access(chromePath);
|
||||||
|
logger.info(`Using system Chrome at: ${chromePath}`);
|
||||||
|
browser = await puppeteer.launch({
|
||||||
|
...launchOptions,
|
||||||
|
executablePath: chromePath,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
} catch {
|
||||||
|
// Continue to next path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!browser) {
|
||||||
|
throw new Error('Chrome nie je nainštalovaný. Pridajte do Dockerfile: RUN apk add --no-cache chromium && ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.setContent(html, { waitUntil: 'networkidle0' });
|
await page.setContent(html, { waitUntil: 'networkidle0' });
|
||||||
|
|||||||
Reference in New Issue
Block a user