Fix selftest when run in docker
This commit is contained in:
parent
4548f7de9c
commit
b28ca9238e
@ -14,7 +14,10 @@ COPY .docker /_docker
|
||||
RUN chmod +Xx /_docker/run.sh && \
|
||||
chmod +Xx /_docker/init.sh
|
||||
|
||||
COPY ./www /var/www/html
|
||||
COPY ./www /var/www/html
|
||||
COPY ./DOCKER_GIT_INFO /DOCKER_GIT_INFO
|
||||
|
||||
RUN chmod a+r /DOCKER_GIT_INFO
|
||||
|
||||
# MapVolumes for: /var/www/html/config.php [ro]
|
||||
# MapVolumes for: /var/www/html/dynamic [rw]
|
||||
@ -23,5 +26,6 @@ COPY ./www /var/www/html
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["/_docker/run.sh"]
|
||||
ENTRYPOINT ["/_docker/run.sh"]
|
||||
CMD []
|
||||
|
||||
|
17
Makefile
17
Makefile
@ -9,12 +9,15 @@ HASH=$(shell git rev-parse HEAD)
|
||||
run:
|
||||
php -S localhost:8000 -t .
|
||||
|
||||
docker:
|
||||
echo -n "VCSTYPE=" >> DOCKER_GIT_INFO ; echo "git" >> DOCKER_GIT_INFO
|
||||
echo -n "BRANCH=" >> DOCKER_GIT_INFO ; git rev-parse --abbrev-ref HEAD >> DOCKER_GIT_INFO
|
||||
echo -n "HASH=" >> DOCKER_GIT_INFO ; git rev-parse HEAD >> DOCKER_GIT_INFO
|
||||
echo -n "COMMITTIME=" >> DOCKER_GIT_INFO ; git log -1 --format=%cd --date=iso >> DOCKER_GIT_INFO
|
||||
echo -n "REMOTE=" >> DOCKER_GIT_INFO ; git remote -v | awk '{print $2}' | uniq | tr '\n' ';' >> DOCKER_GIT_INFO
|
||||
dgi:
|
||||
[ ! -f "DOCKER_GIT_INFO" ] || rm DOCKER_GIT_INFO
|
||||
echo -n "VCSTYPE=" >> DOCKER_GIT_INFO ; { echo "git" ; } >> DOCKER_GIT_INFO
|
||||
echo -n "BRANCH=" >> DOCKER_GIT_INFO ; { git rev-parse --abbrev-ref HEAD ; } >> DOCKER_GIT_INFO
|
||||
echo -n "HASH=" >> DOCKER_GIT_INFO ; { git rev-parse HEAD ; } >> DOCKER_GIT_INFO
|
||||
echo -n "COMMITTIME=" >> DOCKER_GIT_INFO ; { git log -1 --format=%cd --date=iso ; } >> DOCKER_GIT_INFO
|
||||
echo -n "REMOTE=" >> DOCKER_GIT_INFO ; { git remote -v | awk '{print $$2}' | uniq | tr '\n' ';'; } >> DOCKER_GIT_INFO
|
||||
|
||||
docker: dgi
|
||||
docker build \
|
||||
-t $(DOCKER_NAME):$(HASH) \
|
||||
-t $(DOCKER_NAME):$(NAMESPACE)-latest \
|
||||
@ -27,6 +30,7 @@ docker:
|
||||
run-docker: docker
|
||||
mkdir -p ".run-data"
|
||||
docker run --rm \
|
||||
-it \
|
||||
--init \
|
||||
--publish 8080:80 \
|
||||
--env "SMTP=0" \
|
||||
@ -37,6 +41,7 @@ run-docker: docker
|
||||
run-docker-live: docker
|
||||
mkdir -p "$(shell pwd)/.run-data"
|
||||
docker run --rm \
|
||||
-it \
|
||||
--init \
|
||||
--publish 8080:80 \
|
||||
--volume "$(shell pwd)/www:/var/www/html/" \
|
||||
|
@ -8,7 +8,7 @@ require_once (__DIR__ . '/../internals/website.php');
|
||||
|
||||
if (!isset($API_OPTIONS['name'])) { $FRAME_OPTIONS->forceResult(400, "Wrong parameters."); return; }
|
||||
|
||||
$name = $API_OPTIONS['name'];
|
||||
$name = urldecode($API_OPTIONS['name']);
|
||||
|
||||
$updatedata = $SITE->modules->UpdatesLog()->listUpdateData();
|
||||
|
||||
|
@ -532,25 +532,34 @@ class SelfTest implements IWebsiteModule
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
$r = shell_exec('git status 2>&1');
|
||||
$ok = ($r !== null) && (strpos($r, 'Your branch is up to date with') !== false) && (strpos($r, 'nothing to commit, working tree clean') !== false);
|
||||
$r = Website::inst()->gitStatus();
|
||||
|
||||
if (!$ok)
|
||||
if (!$r)
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => "{$xname} failed",
|
||||
'message' => "{$xname} failed (command error)",
|
||||
'long' => $r,
|
||||
'exception' => null,
|
||||
];
|
||||
}
|
||||
else
|
||||
else if (!$r[2])
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => "{$xname} failed (git repo not clean)",
|
||||
'long' => $r,
|
||||
'exception' => null,
|
||||
];
|
||||
}
|
||||
else
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_OK,
|
||||
'message' => "{".$xname."} succeeded",
|
||||
'message' => "{".$xname."} succeeded ('$r[0]' | '$r[1]')",
|
||||
'long' => $r,
|
||||
'exception' => null,
|
||||
];
|
||||
@ -599,7 +608,8 @@ class SelfTest implements IWebsiteModule
|
||||
$url = $urlobj;
|
||||
if (is_array($urlobj)) $url = $urlobj['url'];
|
||||
|
||||
if ($url === 'direct') continue;
|
||||
if ($url === 'direct') continue;
|
||||
if ($urlname === 'homebrew-tap') continue;
|
||||
|
||||
$r = curl_http_request($url);
|
||||
$count++;
|
||||
|
@ -161,6 +161,40 @@ class Website
|
||||
return $this->config['prod'];
|
||||
}
|
||||
|
||||
public function gitStatus(): array|false {
|
||||
if (file_exists('/DOCKER_GIT_INFO'))
|
||||
{
|
||||
$dgi = preg_split("/\r\n|\n|\r/", file_get_contents('/DOCKER_GIT_INFO'));
|
||||
$branch = '';
|
||||
$sha = '';
|
||||
foreach ($dgi as $line)
|
||||
{
|
||||
$split = explode('=', $line, 2);
|
||||
if (count($split) !== 2) continue;
|
||||
|
||||
if ($split[0] === 'BRANCH') { $branch = $split[1]; continue; }
|
||||
if ($split[0] === 'HASH') { $sha = $split[1]; continue; }
|
||||
}
|
||||
|
||||
if ($branch !== '' && $sha !== '') return [$branch, $sha, true];
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = shell_exec('git status 2>&1');
|
||||
$branch = shell_exec('git rev-parse --abbrev-ref HEAD');
|
||||
$sha = shell_exec('git rev-parse HEAD');
|
||||
|
||||
if ($status === false || $status === null || $status === '') return false;
|
||||
if ($branch === false || $branch === null || $branch === '') return false;
|
||||
if ($sha === false || $sha === null || $sha === '') return false;
|
||||
|
||||
$clean = (str_contains($status, 'Your branch is up to date with')) && (str_contains($status, 'nothing to commit, working tree clean'));
|
||||
|
||||
return [$branch, $sha, $clean];
|
||||
}
|
||||
}
|
||||
|
||||
public function isLoggedInByCookie()
|
||||
{
|
||||
if ($this->isLoggedIn !== null) return $this->isLoggedIn;
|
||||
|
Loading…
Reference in New Issue
Block a user