switch branches after update

This commit is contained in:
mercury
2024-03-21 01:19:19 +04:00
parent 9f1b3d84f4
commit 5b1bf2b3d5
6 changed files with 53 additions and 2 deletions
+45
View File
@@ -140,6 +140,12 @@ class Bot
case preg_match('~^/updatebot$~', $this->input['callback'], $m): case preg_match('~^/updatebot$~', $this->input['callback'], $m):
$this->updatebot(); $this->updatebot();
break; break;
case preg_match('~^/branches$~', $this->input['callback'], $m):
$this->branches();
break;
case preg_match('~^/changeBranch (\d+)$~', $this->input['callback'], $m):
$this->changeBranch($m[1]);
break;
case preg_match('~^/getMirror$~', $this->input['callback'], $m): case preg_match('~^/getMirror$~', $this->input['callback'], $m):
$this->getMirror(); $this->getMirror();
break; break;
@@ -3783,7 +3789,13 @@ DNS-over-HTTPS with IP:
'callback_data' => "/debug", 'callback_data' => "/debug",
], ],
]; ];
exec('git -C / branch', $m);
$track = trim(file_get_contents('/update/branch'));
$data[] = [ $data[] = [
[
'text' => "{$m[0]} => $track",
'callback_data' => "/branches",
],
[ [
'text' => $this->i18n('update bot'), 'text' => $this->i18n('update bot'),
'callback_data' => "/updatebot", 'callback_data' => "/updatebot",
@@ -3801,6 +3813,39 @@ DNS-over-HTTPS with IP:
]; ];
} }
public function branches()
{
exec('git -C / branch -r', $m);
array_shift($m);
foreach ($m as $k => $v) {
$data[] = [
[
'text' => $v,
'callback_data' => "/changeBranch $k",
]
];
}
$data[] = [
[
'text' => $this->i18n('back'),
'callback_data' => "/menu config",
]
];
$this->update($this->input['from'], $this->input['message_id'], 'branches', $data);
}
public function changeBranch($i)
{
exec('git -C / branch -r', $m);
array_shift($m);
foreach ($m as $k => $v) {
if ($i == $k) {
file_put_contents('/update/branch', trim(str_replace('origin/', '', $v)));
}
}
$this->menu('config');
}
public function logs() public function logs()
{ {
foreach (scandir('/logs/') as $k => $v) { foreach (scandir('/logs/') as $k => $v) {
View File
+2 -2
View File
@@ -74,7 +74,6 @@ services:
- ./config/sshd_config:/etc/ssh/sshd_config - ./config/sshd_config:/etc/ssh/sshd_config
- ./logs/:/logs/ - ./logs/:/logs/
- ./app/webapp:/app - ./app/webapp:/app
- ./app/login.html:/app/login.html
ports: ports:
- 80:80 - 80:80
hostname: nginx hostname: nginx
@@ -96,7 +95,7 @@ services:
ipv4_address: 10.10.1.2 ipv4_address: 10.10.1.2
logging: *default-logging logging: *default-logging
php: php:
image: mercurykd/vpnbot-php:1.2 image: mercurykd/vpnbot-php:1.3
build: build:
dockerfile: dockerfile/php.dockerfile dockerfile: dockerfile/php.dockerfile
args: args:
@@ -117,6 +116,7 @@ services:
- ./mirror:/mirror - ./mirror:/mirror
- ./.env:/mirror/.env - ./.env:/mirror/.env
- ./update:/update - ./update:/update
- ./.git:/.git
environment: environment:
IP: ${IP} IP: ${IP}
VER: ${VER} VER: ${VER}
+1
View File
@@ -19,6 +19,7 @@ RUN apk add --no-cache --update php81 \
openssh \ openssh \
openssl \ openssl \
curl \ curl \
git \
py3-qt5 \ py3-qt5 \
&& wget https://github.com/ameshkov/dnslookup/releases/download/v1.9.1/dnslookup-linux-amd64-v1.9.1.tar.gz \ && wget https://github.com/ameshkov/dnslookup/releases/download/v1.9.1/dnslookup-linux-amd64-v1.9.1.tar.gz \
&& tar -xf dnslookup-linux-amd64-v1.9.1.tar.gz \ && tar -xf dnslookup-linux-amd64-v1.9.1.tar.gz \
+5
View File
@@ -6,11 +6,16 @@ echo "$$" > $pwd/update/update_pid
while true while true
do do
cmd=$(cat $pwd/update/pipe) cmd=$(cat $pwd/update/pipe)
branch=$(cat $pwd/update/branch 2>/dev/null)
if [[ -n "$cmd" ]] if [[ -n "$cmd" ]]
then then
docker compose down --remove-orphans docker compose down --remove-orphans
git reset --hard git reset --hard
git pull > ./update/message git pull > ./update/message
if [[ -n "$branch" ]]
then
git checkout -t origin/$branch || git checkout $branch
fi
IP=$(curl https://ipinfo.io/ip) VER=$(git describe --tags) docker compose up -d --force-recreate IP=$(curl https://ipinfo.io/ip) VER=$(git describe --tags) docker compose up -d --force-recreate
bash $pwd/update/update.sh & bash $pwd/update/update.sh &
exit 0 exit 0