Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cron job for pruning docker images #11

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

VinneyJ
Copy link

@VinneyJ VinneyJ commented Jun 26, 2024

Description

This change introduces a scheduled cron job on the Dev server to automatically prune unused Docker images every 4 hours. The main objective is to manage disk space efficiently by removing old and unused Docker images, thus preventing potential space-related issues that can cause PRs to fail. This maintenance task ensures that the development environment remains clean and that only relevant Docker images are retained.

Fixes # (issue)

  • Fixes disk space issues caused by the accumulation of old Docker images on the DEV instance(s).
  • Resolves PR failures due to insufficient disk space.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation

@VinneyJ VinneyJ requested a review from a team June 26, 2024 12:51
Copy link
Member

@kilemensi kilemensi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏽

--

  1. Name should include prune I think e.g. docker-prune-cron, etc.
  2. Should we prune everything?

docker-cronjob/prune_docker_images.sh Outdated Show resolved Hide resolved
docker-cronjob/README.md Outdated Show resolved Hide resolved
@VinneyJ VinneyJ requested a review from kilemensi June 27, 2024 09:02
@kilemensi kilemensi requested review from a team and removed request for kilemensi June 27, 2024 09:13
Add the following line to schedule the job:

```
0 */4 * * * /home/azureuser/prune_docker_images.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally you don't want scripts laying around in a home folder. You usually put them in say ~/.local/bin, etc.

But since we're going to develop this further to be part of Dokku plugin ecosystem, I guess we can leave it here for now.

docker-prune-cron/README.md Outdated Show resolved Hide resolved
docker-prune-cron/prune_docker_images.sh Outdated Show resolved Hide resolved
Copy link
Contributor

@thepsalmist thepsalmist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 mostly LGTM. I agree with @kilemensi , since docker system prune gives you a --volumes option, no need to have them as two separate commands

-f, --force Do not prompt for confirmation
--volumes Prune anonymous volumes

I've learnt its never a good idea to have sudo within scripts; you can have a check if script is being run as a user with sudo privileges.

@VinneyJ
Copy link
Author

VinneyJ commented Jun 27, 2024

I've learnt its never a good idea to have sudo within scripts; you can have a check if script is being run as a user with sudo privileges.

I have realized that running the script directly with sudo, like sudo ./docker_prune_cron.sh, doesn't seem to work. Our options are to either modify the sudoers file or add user to the docker group. I'm not sure if everyone is comfortable with any of these approaches in the dev server. @thepsalmist

@VinneyJ VinneyJ requested a review from thepsalmist June 28, 2024 06:50
@thepsalmist
Copy link
Contributor

I've learnt its never a good idea to have sudo within scripts; you can have a check if script is being run as a user with sudo privileges.

I have realized that running the script directly with sudo, like sudo ./docker_prune_cron.sh, doesn't seem to work. Our options are to either modify the sudoers file or add user to the docker group. I'm not sure if everyone is comfortable with any of these approaches in the dev server. @thepsalmist

@VinneyJ why would this not work, any error logs?

@VinneyJ
Copy link
Author

VinneyJ commented Jul 2, 2024

No stdout log at all, @thepsalmist. Nothing appears even in the logs file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants