mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-11-22 13:20:29 +01:00
scaffold basic testing in CI
This commit is contained in:
parent
ac3a231d2b
commit
6ce197696a
@ -2,29 +2,23 @@ version: 2.1
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
canary:
|
canary:
|
||||||
docker:
|
machine:
|
||||||
- image: cimg/base:2020.06
|
image: ubuntu-1604:202007-01
|
||||||
working_directory: ~/docker-volume-backup
|
working_directory: ~/docker-volume-backup
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- setup_remote_docker:
|
|
||||||
version: 20.10.6
|
|
||||||
- run:
|
- run:
|
||||||
name: Build
|
name: Build
|
||||||
command: |
|
command: |
|
||||||
docker build . -t offen/docker-volume-backup:canary
|
docker build . -t offen/docker-volume-backup:canary
|
||||||
- run:
|
- run:
|
||||||
name: Create container from image
|
name: Run tests
|
||||||
command: |
|
command: |
|
||||||
docker run -d offen/docker-volume-backup:canary
|
which docker
|
||||||
echo "Sleeping for 30s before checking if container is still running."
|
which docker-compose
|
||||||
sleep 30
|
for test in test/**/test.sh; do
|
||||||
count=$(docker ps -q | wc -l)
|
. $test
|
||||||
if [[ $count != "1" ]]; then
|
done
|
||||||
echo "Expected one container to be running, found $count."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
docker stop $(docker ps -q)
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
docker:
|
docker:
|
||||||
|
@ -17,13 +17,12 @@ DOCKER_SOCK="/var/run/docker.sock"
|
|||||||
|
|
||||||
if [ -S "$DOCKER_SOCK" ]; then
|
if [ -S "$DOCKER_SOCK" ]; then
|
||||||
TEMPFILE="$(mktemp)"
|
TEMPFILE="$(mktemp)"
|
||||||
docker ps \
|
docker ps -q \
|
||||||
--format "{{.ID}}" \
|
|
||||||
--filter "label=docker-volume-backup.stop-during-backup=$BACKUP_STOP_CONTAINER_LABEL" \
|
--filter "label=docker-volume-backup.stop-during-backup=$BACKUP_STOP_CONTAINER_LABEL" \
|
||||||
> "$TEMPFILE"
|
> "$TEMPFILE"
|
||||||
CONTAINERS_TO_STOP="$(cat $TEMPFILE | tr '\n' ' ')"
|
CONTAINERS_TO_STOP="$(cat $TEMPFILE | tr '\n' ' ')"
|
||||||
CONTAINERS_TO_STOP_TOTAL="$(cat $TEMPFILE | wc -l)"
|
CONTAINERS_TO_STOP_TOTAL="$(cat $TEMPFILE | wc -l)"
|
||||||
CONTAINERS_TOTAL="$(docker ps --format "{{.ID}}" | wc -l)"
|
CONTAINERS_TOTAL="$(docker ps -q | wc -l)"
|
||||||
rm "$TEMPFILE"
|
rm "$TEMPFILE"
|
||||||
echo "$CONTAINERS_TOTAL containers running on host in total."
|
echo "$CONTAINERS_TOTAL containers running on host in total."
|
||||||
echo "$CONTAINERS_TO_STOP_TOTAL containers marked to be stopped during backup."
|
echo "$CONTAINERS_TO_STOP_TOTAL containers marked to be stopped during backup."
|
||||||
@ -99,7 +98,12 @@ if [ ! -z "$BACKUP_RETENTION_DAYS" ]; then
|
|||||||
sleep "$BACKUP_PRUNING_LEEWAY"
|
sleep "$BACKUP_PRUNING_LEEWAY"
|
||||||
bucket=$AWS_S3_BUCKET_NAME
|
bucket=$AWS_S3_BUCKET_NAME
|
||||||
|
|
||||||
rule_applies_to=$(mc rm $MC_GLOBAL_OPTIONS --fake --recursive -force --older-than "${BACKUP_RETENTION_DAYS}d" "backup-target/$bucket" | wc -l)
|
rule_applies_to=$(
|
||||||
|
mc rm $MC_GLOBAL_OPTIONS --fake --recursive -force \
|
||||||
|
--older-than "${BACKUP_RETENTION_DAYS}d" \
|
||||||
|
"backup-target/$bucket" \
|
||||||
|
| wc -l
|
||||||
|
)
|
||||||
if [ "$rule_applies_to" == "0" ]; then
|
if [ "$rule_applies_to" == "0" ]; then
|
||||||
echo "No backups found older than the configured retention period of $BACKUP_RETENTION_DAYS days."
|
echo "No backups found older than the configured retention period of $BACKUP_RETENTION_DAYS days."
|
||||||
echo "Doing nothing."
|
echo "Doing nothing."
|
||||||
@ -114,6 +118,8 @@ if [ ! -z "$BACKUP_RETENTION_DAYS" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mc rm $MC_GLOBAL_OPTIONS --recursive -force --older-than "${BACKUP_RETENTION_DAYS}d" "backup-target/$bucket"
|
mc rm $MC_GLOBAL_OPTIONS \
|
||||||
|
--recursive -force \
|
||||||
|
--older-than "${BACKUP_RETENTION_DAYS}d" "backup-target/$bucket"
|
||||||
echo "Successfully pruned ${rule_applies_to} backups older than ${BACKUP_RETENTION_DAYS} days."
|
echo "Successfully pruned ${rule_applies_to} backups older than ${BACKUP_RETENTION_DAYS} days."
|
||||||
fi
|
fi
|
||||||
|
0
test/default/docker-compose.yml
Normal file
0
test/default/docker-compose.yml
Normal file
5
test/default/test.sh
Normal file
5
test/default/test.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "all is well"
|
Loading…
Reference in New Issue
Block a user