Compare commits
1 Commits
feature/se
...
main
Author | SHA1 | Date | |
---|---|---|---|
f4d96b0875 |
21
.drone.yml
21
.drone.yml
@ -2,16 +2,11 @@
|
|||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: linters
|
name: linters
|
||||||
steps:
|
steps:
|
||||||
- name: publish image
|
- name: run shellcheck
|
||||||
image: plugins/docker
|
image: koalaman/shellcheck-alpine
|
||||||
settings:
|
commands:
|
||||||
username: 3wordchant
|
- shellcheck backup.sh
|
||||||
password:
|
|
||||||
from_secret: git_coopcloud_tech_token_3wc
|
trigger:
|
||||||
repo: git.coopcloud.tech/coop-cloud/backup-bot-two
|
branch:
|
||||||
tags: 2.0.0
|
- main
|
||||||
registry: git.coopcloud.tech
|
|
||||||
when:
|
|
||||||
event:
|
|
||||||
exclude:
|
|
||||||
- pull_request
|
|
||||||
|
10
Dockerfile
10
Dockerfile
@ -1,10 +0,0 @@
|
|||||||
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
|
|
@ -82,6 +82,7 @@ Add your `SSH_KEY` as docker secret:
|
|||||||
abra app secret insert <app_name> ssh_key v1 """$(cat backupkey)
|
abra app secret insert <app_name> ssh_key v1 """$(cat backupkey)
|
||||||
"""
|
"""
|
||||||
```
|
```
|
||||||
|
> Attention: This command needs to be executed exactly as stated above, because it places a trailing newline at the end, if this is missing you will get the following error: `Load key "/run/secrets/ssh_key": error in libcrypto`
|
||||||
|
|
||||||
### Restic REST server Storage
|
### Restic REST server Storage
|
||||||
|
|
||||||
|
2
abra.sh
2
abra.sh
@ -1,3 +1,3 @@
|
|||||||
export ENTRYPOINT_VERSION=v2
|
export ENTRYPOINT_VERSION=v1
|
||||||
export BACKUPBOT_VERSION=v1
|
export BACKUPBOT_VERSION=v1
|
||||||
export SSH_CONFIG_VERSION=v1
|
export SSH_CONFIG_VERSION=v1
|
||||||
|
11
backupbot.py
11
backupbot.py
@ -85,7 +85,6 @@ 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
|
||||||
@ -93,14 +92,8 @@ 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)
|
||||||
for mount in mounts:
|
backup_paths = backup_paths.union(
|
||||||
if path := labels.get('backupbot.backup.path'):
|
Path(VOLUME_PATH).glob(f"{stack_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)):
|
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")
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
version: "3.8"
|
version: "3.8"
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: git.coopcloud.tech/coop-cloud/backup-bot-two:2.0.0
|
image: docker:24.0.7-dind
|
||||||
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,6 +23,9 @@ 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"
|
||||||
@ -43,3 +46,6 @@ 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
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
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
|
||||||
|
Reference in New Issue
Block a user