Dave Gill

Just a Cron Job

I had finished the coding, ran the tests - everything was working. Now I needed to deploy it to an environment where I could actually get the Cron job to run. Did it actually work?

Simple enough I thought. Setting up a Cron job is easy, or it was easy. When you had a server (virtual or real) that was sitting there wasting cycle time etc etc. Add it to a crontab and thats it, it will run. But no. Now I am working on an ECS cluster. So the app runs in a service within the cluster and that particular service does not run cronjobs. The proper thing to do is to create a new service that runs cron jobs. So my job has gone from adding a line to a crontab somewhere to creating a whole new service with all the config and deployment that comes with it.

Only it is not even that easy. The base image choice for our container is Alpine because it is small and fast and therefore a good choice for a container. But it only allows cron jobs run as root. I dont want to run the cron job as rooot. I want it to run as the same user that runs the web app. Only that is not possible with the base image. So I have spent nearly 2 days trying to figure out how to persuade an Alpine based image to run a cron job for a non root user. I have even done research (AI tools were awful and went down some vwey weird paths - like running everything as root) and found some solutions proposed from Reddict, Github issues, AWS forums. SOme of them even suggested the same fix. Only none of them worked. I appreciate the common denominator here might well have been me. But, the bottom line is that the modern architecture I am now using as taken a simple task (remember when you could just add a line to a crontab>?) and turned into a complex task requiring 3-4 hours of work and research.

I am not sure I would call that progress.

I do like a challenge and I do like solving problems and I have indeed managed to do this by totally ignoring cron and doing my own thing.