feat: add cronjobs to docker

This commit is contained in:
Ravinou 2023-09-23 18:09:10 +02:00
parent f1cfe2459b
commit 9e55b47f77
No known key found for this signature in database
GPG key ID: EEEE670C40F6A4D7
4 changed files with 11 additions and 11 deletions

View file

@ -1,12 +1,14 @@
FROM node:18-bookworm-slim
RUN apt-get update && \
apt-get install -y curl git jq borgbackup openssh-server sudo && \
apt-get install -y curl git jq jc borgbackup openssh-server sudo cron && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN echo "borgwarehouse ALL=(ALL) NOPASSWD: /usr/sbin/service ssh restart" >> /etc/sudoers
RUN echo "borgwarehouse ALL=(ALL) NOPASSWD: /usr/sbin/service cron restart" >> /etc/sudoers
RUN groupadd borgwarehouse
RUN useradd -m -g borgwarehouse borgwarehouse

View file

@ -40,11 +40,18 @@ check_repos_directory() {
fi
}
add_cron_job() {
local CRON_JOB="* * * * * curl --request POST --url 'http://localhost:3000/api/cronjob/checkStatus' --header 'Authorization: Bearer $CRONJOB_KEY'; curl --request POST --url 'http://localhost:3000/api/cronjob/getStorageUsed' --header 'Authorization: Bearer $CRONJOB_KEY'"
echo "$CRON_JOB" | crontab -u borgwarehouse -
}
init_ssh_server
check_ssh_directory
create_authorized_keys_file
check_repos_directory
add_cron_job
sudo service ssh restart
sudo service cron restart
exec "$@"

View file

@ -1,9 +0,0 @@
borgwarehouse ALL=(ALL) NOPASSWD: /usr/sbin/userdel -rf [[\:xdigit\:]]*
borgwarehouse ALL=(ALL) NOPASSWD: /usr/sbin/useradd -d /var/borgwarehouse/[[\:xdigit\:]]* -s /bin/bash -m --badname [[\:xdigit\:]]*
borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/mkdir -p /var/borgwarehouse/[[\:xdigit\:]]*/repos/repo[[\:digit\:]]*, /usr/bin/mkdir -p /var/borgwarehouse/[[\:xdigit\:]]*/.ssh
borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/touch /var/borgwarehouse/[[\:xdigit\:]]*/.ssh/authorized_keys
borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/chmod -R 750 /var/borgwarehouse/[[\:xdigit\:]]*, /usr/bin/chmod 600 /var/borgwarehouse/[[\:xdigit\:]]*/.ssh/authorized_keys
borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/chown -R [[\:xdigit\:]]*\:borgwarehouse /var/borgwarehouse/[[\:xdigit\:]]*
borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/tee /var/borgwarehouse/[[\:xdigit\:]]*/.ssh/authorized_keys
borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/sed -ri s|*|g /var/borgwarehouse/[[\:xdigit\:]]*/.ssh/authorized_keys
borgwarehouse ALL=(ALL) NOPASSWD: /usr/bin/du -s -- [[\:xdigit\:]]*

View file

@ -34,7 +34,7 @@ if [ ${#repositoryName} != 8 ]; then
fi
# Delete the repository and the line associated in the authorized_keys file
if [ -d "$1" ]; then
if [ -d "${pool}/${repositoryName}" ]; then
# Delete the repository
rm -rf "${pool}/${repositoryName}"
# Delete the line in the authorized_keys file