renovatebot / config-help

Please use the Discussions feature of https://github.com/renovatebot/renovate instead
https://github.com/renovatebot/renovate/discussions
MIT License
27 stars 16 forks source link

Dockerfile config with cron for renovate #877

Closed Luchanso closed 4 years ago

Luchanso commented 4 years ago

Which Renovate are you using?

Renovate Open Source CLI

Which platform are you using?

Bitbucket Server

What would you like to do?

Hi, guys, I write docker image with cron tab and can't run renovate on schedule, maybe because base image use dumb-init (but I'm not sure).

My dockerfile:

FROM renovate/renovate:slim
WORKDIR /usr/src/app/
COPY ./config.js .
USER root
RUN apt-get update && apt-get install -y cron && rm -rf /var/lib/apt/lists/*
COPY cron-renovate-scheduler /etc/cron.d/cron-renovate-scheduler
RUN chmod 0644 /etc/cron.d/cron-renovate-scheduler
USER 1000
RUN crontab /etc/cron.d/cron-renovate-scheduler
CMD ["cron", "-f"]

In cron-renovate-scheduler, wrote * * * * * root echo hello > /proc/1/fd/1 2>/proc/1/fd/2

After build and run, I got just runned once renovate application and after container automatically destroy - without "hello" 😢

Luchanso commented 4 years ago

Thank you guys, I solve this via nodejs

FROM renovate/renovate:slim
WORKDIR /usr/src
COPY ./config.js ./app
COPY ./src ./cron/src
COPY ./yarn.lock ./cron
COPY ./package.json ./cron
USER root
RUN cd ./cron && yarn
USER 1000

CMD ["node", "./cron/src/index.js"]
const { CronJob } = require("cron");
const { spawn } = require("child_process");

function executeRenovate() {
    const renovate = spawn("docker-entrypoint.sh", {
        cwd: '/usr/src/app',
        stdio: "inherit",
        stderr: "inherit",
    });
    renovate.on('close', (code) => {
        if (code !== 0) {
            job.stop();
            console.error('Failed in renovate. Return code', code);
            process.exit(code);
        }
        console.log(`Renovate exited with code ${code}`);
    });
    renovate.on('error', (err) => {
        job.stop();
        console.error('Failed in renovate. Return code');
        console.error(err);
        process.exit(1);
    });
}

// everyday at 00:00 https://crontab.guru/#0_0_*_*_*
var job = new CronJob("0 0 * * *", () => {
    console.log('--- CRON JOB CALL ---');
    executeRenovate();
});
console.log('--- CRON JOB START ---');
job.start();
executeRenovate();