-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrun.sh
executable file
·61 lines (47 loc) · 1.38 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
set -e
# Required secrets (vault env vars)
# - $CONFIG_TOML
# - $GPG_KEYS
# - $CONFIG_NETRC
# - $GRAPHQL_SERVER_BASE_URL
# - $GRAPHQL_USERNAME
# - $GRAPHQL_PASSWORD
# - $GITLAB_SERVER
# - $GITLAB_TOKEN
IMAGE='quay.io/app-sre/git-keeper:latest'
CONFIG_DIR="$PWD/config"
mkdir -p $CONFIG_DIR/
# fix for expired Let's Encrypt (DST) Root certificate
export REQUESTS_CA_BUNDLE=/etc/pki/tls/cert.pem
# setup requirements
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install uv
# get repos
uv run repos.py > repos.txt
# dump gpg keys to file
echo "$GPG_KEYS" | base64 -d > $CONFIG_DIR/gpg_keys
# get config.toml -- includes s3/gitlab creds
echo "$CONFIG_TOML" | base64 -d > $CONFIG_DIR/config.toml
# hack for .netrc
echo "$CONFIG_NETRC" | base64 -d > $CONFIG_DIR/.netrc
chmod 0666 $CONFIG_DIR/.netrc
# determine subpath for S3 based on date
# daily, weekly or monthly backup folders with different retention policy
SUBPATHS='backups/daily'
if [ "$(date +%d)" -eq 1 ]; then
SUBPATHS="$SUBPATHS,backups/monthly"
fi
if [ "$(date +%w)" -eq 1 ]; then
SUBPATHS="$SUBPATHS,backups/weekly"
fi
docker pull $IMAGE
cat repos.txt | docker run --rm -i \
-e GIT_SSL_NO_VERIFY=true \
-v $CONFIG_DIR:/config:z \
$IMAGE \
--config /config/config.toml \
--gpgs /config/gpg_keys \
--subfolders $SUBPATHS