Skip to content

Commit

Permalink
feat: palm support (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrrypg committed Aug 2, 2024
1 parent 38a63ce commit e61465c
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ You can enable it adding `drydock-backups` to the `plugins` section of the `conf
- **BACKUP_AZURE_ACCOUNT_NAME**: Name of the account to access the container.
- **BACKUP_AZURE_CONTAINER_SAS_TOKEN**: SAS token to access the container.
- **BACKUP_K8S_USE_EPHEMERAL_VOLUMES**: Use ephemeral volumes to set up the cronjob. (default: `False`)
- **BACKUP_K8S_EPHEMERAL_VOLUME_STORAGE_CLASS**: Custom StorageClass name for ephemeral volumes creation. (default: `None`)
- **BACKUP_K8S_EPHEMERAL_VOLUME_SIZE**: Size of the ephemeral volume. (default: `8Gi`)
- **BACKYP_MINIO_EXPIRATION_DAYS**: Number of days to setup the lifecycle policy when Minio is enabled. (default: `0`)
- **BACKUP_MYSQL_USERNAME**: Username to access the mysql database. (default: `{{ MYSQL_ROOT_USERNAME }}`)
- **BACKUP_MYSQL_PASSWORD**: Password to access the mysql database. (default: `{{ MYSQL_ROOT_PASSWORD }}`)
- **BACKUP_MONGO_PASSWORD**: Password to access the mongodb database. (default: `{{ MONGODB_PASSWORD }}`)
Expand Down
6 changes: 6 additions & 0 deletions drydock_backups/patches/k8s-jobs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ spec:
ephemeral:
volumeClaimTemplate:
spec:
{%- if BACKUP_K8S_EPHEMERAL_VOLUME_STORAGE_CLASS %}
storageClassName: {{ BACKUP_K8S_EPHEMERAL_VOLUME_STORAGE_CLASS }}
{%- endif %}
accessModes:
- ReadWriteOnce
resources:
Expand Down Expand Up @@ -146,6 +149,9 @@ spec:
ephemeral:
volumeClaimTemplate:
spec:
{%- if BACKUP_K8S_EPHEMERAL_VOLUME_STORAGE_CLASS %}
storageClassName: {{ BACKUP_K8S_EPHEMERAL_VOLUME_STORAGE_CLASS }}
{%- endif %}
accessModes:
- ReadWriteOnce
resources:
Expand Down
26 changes: 21 additions & 5 deletions drydock_backups/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import os.path

import importlib_resources
import pkg_resources

from tutor import hooks as tutor_hooks

Expand All @@ -23,7 +23,9 @@
"AZURE_ACCOUNT_NAME": "",
"CUSTOM_STORAGE_ENDPOINT": None,
"K8S_USE_EPHEMERAL_VOLUMES": False,
"K8S_EPHEMERAL_VOLUME_STORAGE_CLASS": None,
"K8S_EPHEMERAL_VOLUME_SIZE": "8Gi",
"MINIO_EXPIRATION_DAYS": 0,
"MYSQL_USERNAME": '{{ MYSQL_ROOT_USERNAME }}',
"MYSQL_PASSWORD": '{{ MYSQL_ROOT_PASSWORD }}',
"MONGO_PASSWORD": '{{ MONGODB_PASSWORD }}',
Expand Down Expand Up @@ -80,7 +82,7 @@

# Plugin templates
tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
str(importlib_resources.files("drydock_backups") / "templates")
pkg_resources.resource_filename("drydock_backups" ,"templates")
)

tutor_hooks.Filters.ENV_TEMPLATE_TARGETS.add_items( [
Expand All @@ -89,18 +91,32 @@
],
)
# Load all patches from the "patches" folder
for path in glob(str(importlib_resources.files("drydock_backups") / "patches" / "*")):
for path in glob(
os.path.join(
pkg_resources.resource_filename("drydock_backups", "patches"),
"*",
)
):
with open(path, encoding="utf-8") as patch_file:
tutor_hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read()))

# # init script
with open(
str(importlib_resources.files("drydock_backups") / "templates" / "drydock_backups" / "task" / "mongodb" / "init"),
pkg_resources.resource_filename("drydock_backups", "templates/drydock_backups/task/mongodb/init"),
encoding="utf-8",
) as fi:
tutor_hooks.Filters.CLI_DO_INIT_TASKS.add_item(("mongodb-backup", fi.read()), priority=tutor_hooks.priorities.HIGH)
with open(
str(importlib_resources.files("drydock_backups") / "templates" / "drydock_backups" / "task" / "mysql" / "init"),
pkg_resources.resource_filename("drydock_backups", "templates/drydock_backups/task/mysql/init"),
encoding="utf-8",
) as fi:
tutor_hooks.Filters.CLI_DO_INIT_TASKS.add_item(("mysql", fi.read()), priority=tutor_hooks.priorities.HIGH)

@tutor_hooks.Actions.PLUGIN_LOADED.add()
def _add_minio_init(_name: str) -> None:
if _name == "minio":
with open(
pkg_resources.resource_filename("drydock_backups", "templates/drydock_backups/task/minio/init"),
encoding="utf-8",
) as file:
tutor_hooks.Filters.CLI_DO_INIT_TASKS.add_item(("minio", file.read()), priority=tutor_hooks.priorities.HIGH)
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ RUN set -eux; \

RUN echo 'deb [ signed-by=/etc/apt/keyrings/mysql.gpg ] http://repo.mysql.com/apt/debian/ bookworm mysql-8.4-lts' > /etc/apt/sources.list.d/mysql.list

# The following command is required to prevent the following error:
# GPG error: http://repo.mysql.com/apt/debian buster InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B7B3B788A8D3785C
# The solution was found here: https://askubuntu.com/questions/1497140/how-to-fix-apt-update-after-to-upgrade-the-mysql-list-file#comment2623210_1497141
# RUN gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys B7B3B788A8D3785C && rm /etc/apt/keyrings/mysql.gpg && gpg --output /etc/apt/keyrings/mysql.gpg --export B7B3B788A8D3785C
RUN curl -fsSL https://www.mongodb.org/static/pgp/server-4.4.asc | gpg -o /usr/share/keyrings/mongodb-server-4.4.gpg --dearmor

RUN curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor

RUN echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/7.0 main" | tee /etc/apt/sources.list.d/mongodb-org-7.0.list
RUN echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-4.4.gpg ] http://repo.mongodb.org/apt/debian bookworm/mongodb-org/4.4 main" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list

RUN apt-get update && apt-get install -y \
mysql-community-client=8.4.2-1debian12 \
mongodb-org \
mongodb-database-tools \
awscli \
&& rm -rf /var/lib/apt/lists/*

Expand Down
5 changes: 5 additions & 0 deletions drydock_backups/templates/drydock_backups/task/minio/init
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mc config host add minio http://minio:9000 {{ OPENEDX_AWS_ACCESS_KEY }} {{ OPENEDX_AWS_SECRET_ACCESS_KEY }} --api s3v4
mc mb --ignore-existing minio/{{ BACKUP_BUCKET_NAME }}
{%- if BACKUP_MINIO_EXPIRATION_DAYS > 0 %}
mc ilm add --expiry-days "{{ BACKUP_MINIO_EXPIRATION_DAYS }}" minio/{{ BACKUP_BUCKET_NAME }}
{%- endif %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
echo "Initialising MongoDB..."
mongosh --host {{MONGODB_HOST }} {% if MONGODB_ROOT_USERNAME and MONGODB_ROOT_PASSWORD %} -u {{ MONGODB_ROOT_USERNAME }} -p {{ MONGODB_ROOT_PASSWORD }} {% endif %} admin <<EOF
mongo --host {{MONGODB_HOST }} {% if MONGODB_ROOT_USERNAME and MONGODB_ROOT_PASSWORD %} -u {{ MONGODB_ROOT_USERNAME }} -p {{ MONGODB_ROOT_PASSWORD }} {% endif %} admin <<EOF
if (db.getUser("{{ BACKUP_MONGO_USERNAME }}") == null) {
db.createUser({
user: "{{ BACKUP_MONGO_USERNAME }}",
Expand Down
2 changes: 1 addition & 1 deletion drydock_backups/templates/drydock_backups/task/mysql/init
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- if BACKUP_MYSQL_USERNAME -%}
mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e "CREATE USER '{{ BACKUP_MYSQL_USERNAME }}'@'%' IDENTIFIED BY '{{ BACKUP_MYSQL_PASSWORD }}';"
mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e "CREATE USER IF NOT EXISTS '{{ BACKUP_MYSQL_USERNAME }}'@'%' IDENTIFIED BY '{{ BACKUP_MYSQL_PASSWORD }}';"
mysql -u {{ MYSQL_ROOT_USERNAME }} --password="{{ MYSQL_ROOT_PASSWORD }}" --host "{{ MYSQL_HOST }}" --port {{ MYSQL_PORT }} -e "GRANT SELECT, RELOAD, PROCESS ON *.* TO '{{ BACKUP_MYSQL_USERNAME }}'@'%';"
{%- endif %}
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ classifiers = [
requires-python = ">=3.8"

dependencies = [
"tutor>=18.0.0,<19.0.0"
"tutor>=16.0.0,<17.0.0"
]

[project.optional-dependencies]
Expand Down Expand Up @@ -60,7 +60,7 @@ version_variables = [
]

[tool.semantic_release.branches.main]
match = "(main|master)"
match = "palm"

[tool.semantic_release.changelog.environment]
keep_trailing_newline = true
Expand Down

0 comments on commit e61465c

Please sign in to comment.