generated from github/welcome-to-github
-
-
Notifications
You must be signed in to change notification settings - Fork 13
135 lines (108 loc) · 4.29 KB
/
test-database-update.yml
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Database update tests
on:
push:
branches: [ devel ]
pull_request:
push:
branches: [ main ]
jobs:
test-database-update:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install docker-compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
# Get all releases
# Format them to a key-value array
# Start from release index which is 4.0.0
# Pull images starting from release 4.0.0
# Then pull the next image of the index, etc..
- name: Test all releases update from lbr38/repomanager
run: |
RELEASES=$(curl -s https://api.github.com/repos/lbr38/repomanager/releases?per_page=10000 | jq -r '.[].name' | tac)
index="0"
declare -A RELEASES_ARRAY
for release in $RELEASES; do
RELEASES_ARRAY["$index"]="$release"
index=$((index+1))
done
for i in "${!RELEASES_ARRAY[@]}"; do
if [[ "${RELEASES_ARRAY[$i]}" == "4.0.0" ]]; then
start_index="$i"
break
fi
done
for ((i=start_index; i<${#RELEASES_ARRAY[@]}; i++)); do
release="${RELEASES_ARRAY[$i]}"
docker rm -f repomanager
docker system prune -a -f
echo -e "\nPulling image for release $release\n"
docker run -d --restart always --name repomanager \
-e FQDN=repomanager.test.com \
-e MAX_UPLOAD_SIZE=32M \
-p 8080:8080 \
-v /etc/localtime:/etc/localtime:ro \
-v /var/lib/docker/volumes/repomanager-data:/var/lib/repomanager \
-v /var/lib/docker/volumes/repomanager-repo:/home/repo \
lbr38/repomanager:$release
if [ $? -ne 0 ]; then
echo "Failed to pull image for release $release"
exit 1
fi
# Retrieve and check errors in container logs
while true; do
OUTPUT=$(docker logs repomanager -n10000)
# Check if the logs contains failed message
if echo "$OUTPUT" | grep -q -i "failed"; then
echo "Database update seems to have failed: $OUTPUT"
exit 1
fi
if echo "$OUTPUT" | grep -q -i "error"; then
echo "Database update seems to have failed: $OUTPUT"
exit 1
fi
# Quit the loop if the maintenance page is disabled (meaning the update is done)
if echo "$OUTPUT" | grep -q "Disabling maintenance page"; then
break
fi
sleep 2
done
done
# Finally, test the devel image
- name: Test devel image from lbr38/repomanager
run: |
docker rm -f repomanager
docker system prune -a -f
echo -e "\Build devel image\n"
cd ${GITHUB_WORKSPACE}/docker
sed -i 's/env:.*/env: devel/g' docker-compose.yml
sed -i 's/fqdn:.*/fqdn: repomanager.test.com/g' docker-compose.yml
docker-compose -f docker-compose.yml up -d
if [ $? -ne 0 ]; then
echo "Failed to build devel image"
exit 1
fi
# Retrieve and check errors in container logs
while true; do
OUTPUT=$(docker logs repomanager -n10000)
# Check if the logs contains failed message
if echo "$OUTPUT" | grep -q -i "failed"; then
echo "Database update seems to have failed: $OUTPUT"
exit 1
fi
# Check if the logs contains error message
if echo "$OUTPUT" | grep -q -i "error"; then
echo "Database update seems to have failed: $OUTPUT"
exit 1
fi
# Quit the loop if the maintenance page is disabled (meaning the update is done)
if echo "$OUTPUT" | grep -q "Disabling maintenance page"; then
break
fi
sleep 2
done
# Print final container logs output
echo "$OUTPUT"