From 07d03719acbb7b7fadf700eb174ebb0de20ae245 Mon Sep 17 00:00:00 2001 From: Miguel Ramirez <133135158+marbonilla@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:37:59 -0500 Subject: [PATCH] feat: support docker operations for image in drydock backups (#53) * feat: support docker operations for image in drydock backups * fix: update image variable in defaults and jobs template * fix: update .gitignore * fix: using BACKUP_VARIABLE * fix: update readme * fix: update gitignore for /build/ folder --- .gitignore | 2 +- drydock_backups/README.rst | 2 +- .../patches/drydock-multipurpose-jobs | 4 +- drydock_backups/plugin.py | 55 ++++++++----------- .../drydock-backups/build/backups}/Dockerfile | 0 .../build/backups}/docker-entrypoint.sh | 0 6 files changed, 26 insertions(+), 37 deletions(-) rename drydock_backups/{ => templates/drydock-backups/build/backups}/Dockerfile (100%) rename drydock_backups/{ => templates/drydock-backups/build/backups}/docker-entrypoint.sh (100%) diff --git a/.gitignore b/.gitignore index 0261fe23..24478be3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,8 @@ __pycache__ # Packages *.egg *.egg-info +/build/ dist -build eggs parts bin diff --git a/drydock_backups/README.rst b/drydock_backups/README.rst index 87494edf..a7c80877 100644 --- a/drydock_backups/README.rst +++ b/drydock_backups/README.rst @@ -15,7 +15,7 @@ You can enable it adding `drydock-backups` to the `plugins` section of the `conf Configuration variables ----------------------- -- **BACKUP_IMAGE**: The image used to run the cronjob. (default: `ednxops/shipyard-utils:v1.0.0`) +- **BACKUP_DOCKER_IMAGE**: The image used to run the cronjob. (default: `ednxops/shipyard-utils:v{{BACKUP_VERSION}}`) - **BACKUP_CRON_SCHEDULE**: Cron schedule to run the backup. (default: `0 2 * * *`) - **BACKUP_STORAGE_SERVICE**: Storage service to use. (default: `aws-s3`) (options: `aws-s3`, `azure-blob`) - **BACKUP_AWS_ACCESS_KEY**: AWS access key to access the bucket or minIO user. diff --git a/drydock_backups/patches/drydock-multipurpose-jobs b/drydock_backups/patches/drydock-multipurpose-jobs index 02074efb..2fc4345c 100644 --- a/drydock_backups/patches/drydock-multipurpose-jobs +++ b/drydock_backups/patches/drydock-multipurpose-jobs @@ -23,7 +23,7 @@ spec: restartPolicy: OnFailure containers: - name: backup - image: {{ BACKUP_IMAGE }} + image: {{ BACKUP_DOCKER_IMAGE }} env: - name: MYSQL_HOST value: '{{ MYSQL_HOST }}' @@ -100,7 +100,7 @@ spec: restartPolicy: OnFailure containers: - name: backup - image: {{ BACKUP_IMAGE }} + image: {{ BACKUP_DOCKER_IMAGE }} env: - name: MONGODB_HOST value: '{{ MONGODB_HOST }}' diff --git a/drydock_backups/plugin.py b/drydock_backups/plugin.py index 70ab570b..7930ca1f 100644 --- a/drydock_backups/plugin.py +++ b/drydock_backups/plugin.py @@ -8,12 +8,12 @@ import pkg_resources from tutor import hooks -from .__about__ import __version__ +from drydock.__about__ import __version__ config = { "defaults": { "VERSION": __version__, - "IMAGE": "ednxops/shipyard-utils:v15.4.0", + "DOCKER_IMAGE": "ednxops/shipyard-utils:v{{BACKUP_VERSION}}", "CRON_SCHEDULE": '0 2 * * *', "STORAGE_SERVICE": "aws-s3", "AWS_ACCESS_KEY": "", @@ -88,47 +88,36 @@ # Images to be built by `tutor images build`. # Each item is a quadruple in the form: # ("", ("path", "to", "build", "dir"), "", "") -hooks.Filters.IMAGES_BUILD.add_items( - [ - # To build `myimage` with `tutor images build myimage`, - # you would add a Dockerfile to templates/drydock-backups/build/myimage, - # and then write: - ### ( - ### "myimage", - ### ("plugins", "drydock-backups", "build", "myimage"), - ### "docker.io/myimage:{{ DRYDOCK_BACKUPS_VERSION }}", - ### (), - ### ), - ] -) +hooks.Filters.IMAGES_BUILD.add_items([ + ( + "backups", + ("plugins", "drydock-backups", "build", "backups"), + "{{BACKUP_DOCKER_IMAGE}}", + (), + ) +]) # Images to be pulled as part of `tutor images pull`. # Each item is a pair in the form: # ("", "") -hooks.Filters.IMAGES_PULL.add_items( - [ - # To pull `myimage` with `tutor images pull myimage`, you would write: - ### ( - ### "myimage", - ### "docker.io/myimage:{{ DRYDOCK_BACKUPS_VERSION }}", - ### ), - ] -) +hooks.Filters.IMAGES_PULL.add_items([ + ( + "backups", + "{{BACKUP_DOCKER_IMAGE}}", + ) +]) # Images to be pushed as part of `tutor images push`. # Each item is a pair in the form: # ("", "") -hooks.Filters.IMAGES_PUSH.add_items( - [ - # To push `myimage` with `tutor images push myimage`, you would write: - ### ( - ### "myimage", - ### "docker.io/myimage:{{ DRYDOCK_BACKUPS_VERSION }}", - ### ), - ] -) +hooks.Filters.IMAGES_PUSH.add_items([ + ( + "backups", + "{{BACKUP_DOCKER_IMAGE}}", + ) +]) ######################################## diff --git a/drydock_backups/Dockerfile b/drydock_backups/templates/drydock-backups/build/backups/Dockerfile similarity index 100% rename from drydock_backups/Dockerfile rename to drydock_backups/templates/drydock-backups/build/backups/Dockerfile diff --git a/drydock_backups/docker-entrypoint.sh b/drydock_backups/templates/drydock-backups/build/backups/docker-entrypoint.sh similarity index 100% rename from drydock_backups/docker-entrypoint.sh rename to drydock_backups/templates/drydock-backups/build/backups/docker-entrypoint.sh