forked from xibosignage/xibo-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-pr.sh
More file actions
executable file
·126 lines (107 loc) · 3.93 KB
/
test-pr.sh
File metadata and controls
executable file
·126 lines (107 loc) · 3.93 KB
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
#!/usr/bin/env bash
#
# Copyright (C) 2026 Xibo Signage Ltd
#
# Xibo - Digital Signage - https://xibosignage.com
#
# This file is part of Xibo.
#
# Xibo is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# Xibo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Xibo. If not, see <http://www.gnu.org/licenses/>.
#
# Default values
SERVER_PORT=80
while getopts p:d:s: option; do
case "${option}" in
p) PR_NUMBER=${OPTARG};;
d) DELETE_PORT=${OPTARG};;
s) SERVER_PORT=${OPTARG};;
esac
done
# Create a network if it doesn't exist
NETWORK_NAME="test-pr-network"
docker network inspect "$NETWORK_NAME" >/dev/null 2>&1 || docker network create "$NETWORK_NAME"
if [ "$DELETE_PORT" == "all" ]; then
echo "Deleting all test containers..."
# Stop and remove all test-pr-* containers
docker ps -a --format '{{.Names}}' | grep "^test-pr-" | while read -r container_name; do
docker stop "$container_name" && docker rm "$container_name"
done
# Remove network if no containers are using it
docker network rm $NETWORK_NAME
exit
elif [ -n "$DELETE_PORT" ]; then
echo "Deleting containers for port $DELETE_PORT..."
# Stop and remove containers associated with the specific SERVER_PORT
docker ps -a --format '{{.Names}}' | grep "test-pr-.*-$DELETE_PORT" | while read -r container_name; do
docker stop "$container_name" && docker rm "$container_name"
done
# Remove network if no containers are using it
remaining_containers=$(docker ps -a --format '{{.Names}}' | grep "^test-pr-" | wc -l)
if [ "$remaining_containers" -eq 0 ]; then
docker network rm $NETWORK_NAME
fi
exit
fi
# Pull necessary Docker images
echo "Pulling Docker images..."
docker pull mysql:8.4
docker pull ghcr.io/xibosignage/xibo-xmr:latest
docker pull ghcr.io/xibosignage/xibo-cms:test-"$PR_NUMBER"
docker pull mongo:4.2
# Run the MySQL container
docker run --name test-pr-db-"$SERVER_PORT" \
--network "$NETWORK_NAME" \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_DATABASE=cms \
-e MYSQL_USER=cms \
-e MYSQL_PASSWORD=jenkins \
-d \
mysql:8.4
# Check if MongoDB container exists before creating
if ! docker ps -a --format '{{.Names}}' | grep -q "test-pr-mongo"; then
echo "Starting new MongoDB container..."
docker run --name test-pr-mongo \
--network "$NETWORK_NAME" \
-e MONGO_INITDB_ROOT_USERNAME=root \
-e MONGO_INITDB_ROOT_PASSWORD=example \
-d \
-p 27071:27071 \
mongo:4.2
else
echo "MongoDB container already exists, skipping creation."
fi
docker run --name test-pr-xmr-"$SERVER_PORT" -d ghcr.io/xibosignage/xibo-xmr:latest
# Run the CMS container
docker run --name test-pr-web-"$SERVER_PORT" \
--network "$NETWORK_NAME" \
-e MYSQL_HOST=test-pr-db-"$SERVER_PORT" \
-e MYSQL_USER=cms \
-e MYSQL_PASSWORD=jenkins \
-e CMS_DEV_MODE=true \
-e XMR_HOST=test-pr-xmr-"$SERVER_PORT" \
-e CMS_USAGE_REPORT=false \
-e INSTALL_TYPE=ci \
-e MYSQL_BACKUP_ENABLED=false \
--link test-pr-db-"$SERVER_PORT" \
--link test-pr-xmr-"$SERVER_PORT" \
--link test-pr-mongo \
-p "$SERVER_PORT":80 \
-d \
ghcr.io/xibosignage/xibo-cms:test-"$PR_NUMBER"
echo "Containers starting, waiting for ready event"
docker exec -t test-pr-web-"$SERVER_PORT" /bin/bash -c "/usr/local/bin/wait-for-command.sh -q -t 300 -c \"nc -z localhost 80\""
docker exec -t test-pr-web-"$SERVER_PORT" /bin/bash -c "chown -R www-data.www-data /var/www/cms"
docker exec --user www-data -t test-pr-web-"$SERVER_PORT" /bin/bash -c "cd /var/www/cms; /usr/bin/php bin/run.php 1"
sleep 5
echo "CMS running on port $SERVER_PORT"