Compare commits

...

11 Commits

Author SHA1 Message Date
3wc d998b61117 Don't duplicate stack name in vol path
continuous-integration/drone/push Build is passing Details
2023-11-10 22:02:54 +00:00
3wc c93d5c6f44 set.add() returns None 🤡
continuous-integration/drone/push Build is passing Details
2023-11-10 22:00:35 +00:00
3wc 52e52a1e1d Set theory
continuous-integration/drone/push Build is passing Details
2023-11-10 21:56:51 +00:00
3wc 771cf31824 Unglob
continuous-integration/drone/push Build is passing Details
2023-11-10 21:55:21 +00:00
3wc 83834c6570 Whoops fix Mounts path
continuous-integration/drone/push Build is passing Details
2023-11-10 21:53:34 +00:00
3wc 98b5f077e2 Allow selective path spec
continuous-integration/drone/push Build is passing Details
2023-11-10 21:50:54 +00:00
3wc ed687e52c3 Remove redundant stuff from entrypoint 2023-11-10 18:11:32 +00:00
3wc cf06532da9 Whoops, wrong image 2023-11-10 18:09:50 +00:00
3wc 319deaba4b Switch to backup-bot-two image
continuous-integration/drone/push Build is passing Details
2023-11-10 16:55:41 +00:00
3wc 3c44300a2e Whoops skip shellcheck
continuous-integration/drone/push Build is passing Details
2023-11-10 14:53:48 +00:00
3wc 5ac3a48125 Reinstate Docker image
continuous-integration/drone/push Build encountered an error Details
2023-11-10 14:52:59 +00:00
6 changed files with 35 additions and 24 deletions

View File

@ -2,11 +2,16 @@
kind: pipeline kind: pipeline
name: linters name: linters
steps: steps:
- name: run shellcheck - name: publish image
image: koalaman/shellcheck-alpine image: plugins/docker
commands: settings:
- shellcheck backup.sh username: 3wordchant
password:
trigger: from_secret: git_coopcloud_tech_token_3wc
branch: repo: git.coopcloud.tech/coop-cloud/backup-bot-two
- main tags: 2.0.0
registry: git.coopcloud.tech
when:
event:
exclude:
- pull_request

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM docker:24.0.7-dind
RUN apk add --upgrade --no-cache restic bash python3 py3-pip
# Todo use requirements file with specific versions
RUN pip install click==8.1.7 docker==6.1.3 resticpy==1.0.2
COPY backupbot.py /usr/bin/backup
ENTRYPOINT /bin/bash

View File

@ -1,3 +1,3 @@
export ENTRYPOINT_VERSION=v1 export ENTRYPOINT_VERSION=v2
export BACKUPBOT_VERSION=v1 export BACKUPBOT_VERSION=v1
export SSH_CONFIG_VERSION=v1 export SSH_CONFIG_VERSION=v1

View File

@ -85,6 +85,7 @@ def get_backup_cmds():
services = client.services.list() services = client.services.list()
for s in services: for s in services:
labels = s.attrs['Spec']['Labels'] labels = s.attrs['Spec']['Labels']
mounts = s.attrs['Spec']['TaskTemplate']['ContainerSpec']['Mounts']
if (backup := labels.get('backupbot.backup')) and bool(backup): if (backup := labels.get('backupbot.backup')) and bool(backup):
stack_name = labels['com.docker.stack.namespace'] stack_name = labels['com.docker.stack.namespace']
# Remove this lines to backup only a specific service # Remove this lines to backup only a specific service
@ -92,9 +93,15 @@ def get_backup_cmds():
# if SERVICE and SERVICE != stack_name: # if SERVICE and SERVICE != stack_name:
# continue # continue
backup_apps.add(stack_name) backup_apps.add(stack_name)
backup_paths = backup_paths.union( for mount in mounts:
Path(VOLUME_PATH).glob(f"{stack_name}_*")) if path := labels.get('backupbot.backup.path'):
if not (container:= container_by_service.get(s.name)): path_ = Path(VOLUME_PATH) / f"{mount['Source']}/_data/{path}"
else:
path_ = Path(VOLUME_PATH) / f"{mount['Source']}"
logging.debug(
f"Added backup path {path_}")
backup_paths.add(path_)
if not (container := container_by_service.get(s.name)):
logging.error( logging.error(
f"Container {s.name} is not running, hooks can not be executed") f"Container {s.name} is not running, hooks can not be executed")
continue continue

View File

@ -2,7 +2,7 @@
version: "3.8" version: "3.8"
services: services:
app: app:
image: docker:24.0.7-dind image: git.coopcloud.tech/coop-cloud/backup-bot-two:2.0.0
volumes: volumes:
- "/var/run/docker.sock:/var/run/docker.sock" - "/var/run/docker.sock:/var/run/docker.sock"
- "/var/lib/docker/volumes/:/var/lib/docker/volumes/" - "/var/lib/docker/volumes/:/var/lib/docker/volumes/"
@ -23,9 +23,6 @@ services:
- source: entrypoint - source: entrypoint
target: /entrypoint.sh target: /entrypoint.sh
mode: 0555 mode: 0555
- source: backupbot
target: /usr/bin/backup
mode: 0555
entrypoint: ['/entrypoint.sh'] entrypoint: ['/entrypoint.sh']
healthcheck: healthcheck:
test: "pgrep crond" test: "pgrep crond"
@ -46,6 +43,3 @@ configs:
entrypoint: entrypoint:
name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION} name: ${STACK_NAME}_entrypoint_${ENTRYPOINT_VERSION}
file: entrypoint.sh file: entrypoint.sh
backupbot:
name: ${STACK_NAME}_backupbot_${BACKUPBOT_VERSION}
file: backupbot.py

View File

@ -2,11 +2,6 @@
set -e -o pipefail set -e -o pipefail
apk add --upgrade --no-cache restic bash python3 py3-pip
# Todo use requirements file with specific versions
pip install click==8.1.7 docker==6.1.3 resticpy==1.0.2
if [ -n "$SSH_HOST_KEY" ] if [ -n "$SSH_HOST_KEY" ]
then then
echo "$SSH_HOST_KEY" > /root/.ssh/known_hosts echo "$SSH_HOST_KEY" > /root/.ssh/known_hosts