Fix selftest when run in docker
This commit is contained in:
parent
4548f7de9c
commit
b28ca9238e
10
Dockerfile
10
Dockerfile
@ -11,10 +11,13 @@ RUN docker-php-ext-install pdo pdo_mysql bcmath
|
|||||||
|
|
||||||
COPY .docker /_docker
|
COPY .docker /_docker
|
||||||
|
|
||||||
RUN chmod +Xx /_docker/run.sh && \
|
RUN chmod +Xx /_docker/run.sh && \
|
||||||
chmod +Xx /_docker/init.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/config.php [ro]
|
||||||
# MapVolumes for: /var/www/html/dynamic [rw]
|
# MapVolumes for: /var/www/html/dynamic [rw]
|
||||||
@ -23,5 +26,6 @@ COPY ./www /var/www/html
|
|||||||
|
|
||||||
EXPOSE 80
|
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:
|
run:
|
||||||
php -S localhost:8000 -t .
|
php -S localhost:8000 -t .
|
||||||
|
|
||||||
docker:
|
dgi:
|
||||||
echo -n "VCSTYPE=" >> DOCKER_GIT_INFO ; echo "git" >> DOCKER_GIT_INFO
|
[ ! -f "DOCKER_GIT_INFO" ] || rm DOCKER_GIT_INFO
|
||||||
echo -n "BRANCH=" >> DOCKER_GIT_INFO ; git rev-parse --abbrev-ref HEAD >> DOCKER_GIT_INFO
|
echo -n "VCSTYPE=" >> DOCKER_GIT_INFO ; { echo "git" ; } >> DOCKER_GIT_INFO
|
||||||
echo -n "HASH=" >> DOCKER_GIT_INFO ; git rev-parse HEAD >> DOCKER_GIT_INFO
|
echo -n "BRANCH=" >> DOCKER_GIT_INFO ; { git rev-parse --abbrev-ref HEAD ; } >> DOCKER_GIT_INFO
|
||||||
echo -n "COMMITTIME=" >> DOCKER_GIT_INFO ; git log -1 --format=%cd --date=iso >> DOCKER_GIT_INFO
|
echo -n "HASH=" >> DOCKER_GIT_INFO ; { git rev-parse HEAD ; } >> DOCKER_GIT_INFO
|
||||||
echo -n "REMOTE=" >> DOCKER_GIT_INFO ; git remote -v | awk '{print $2}' | uniq | tr '\n' ';' >> 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 \
|
docker build \
|
||||||
-t $(DOCKER_NAME):$(HASH) \
|
-t $(DOCKER_NAME):$(HASH) \
|
||||||
-t $(DOCKER_NAME):$(NAMESPACE)-latest \
|
-t $(DOCKER_NAME):$(NAMESPACE)-latest \
|
||||||
@ -27,6 +30,7 @@ docker:
|
|||||||
run-docker: docker
|
run-docker: docker
|
||||||
mkdir -p ".run-data"
|
mkdir -p ".run-data"
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
|
-it \
|
||||||
--init \
|
--init \
|
||||||
--publish 8080:80 \
|
--publish 8080:80 \
|
||||||
--env "SMTP=0" \
|
--env "SMTP=0" \
|
||||||
@ -37,6 +41,7 @@ run-docker: docker
|
|||||||
run-docker-live: docker
|
run-docker-live: docker
|
||||||
mkdir -p "$(shell pwd)/.run-data"
|
mkdir -p "$(shell pwd)/.run-data"
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
|
-it \
|
||||||
--init \
|
--init \
|
||||||
--publish 8080:80 \
|
--publish 8080:80 \
|
||||||
--volume "$(shell pwd)/www:/var/www/html/" \
|
--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; }
|
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();
|
$updatedata = $SITE->modules->UpdatesLog()->listUpdateData();
|
||||||
|
|
||||||
|
@ -532,25 +532,34 @@ class SelfTest implements IWebsiteModule
|
|||||||
'exception' => null,
|
'exception' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
$r = shell_exec('git status 2>&1');
|
$r = Website::inst()->gitStatus();
|
||||||
$ok = ($r !== null) && (strpos($r, 'Your branch is up to date with') !== false) && (strpos($r, 'nothing to commit, working tree clean') !== false);
|
|
||||||
|
|
||||||
if (!$ok)
|
if (!$r)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
[
|
[
|
||||||
'result' => self::STATUS_ERROR,
|
'result' => self::STATUS_ERROR,
|
||||||
'message' => "{$xname} failed",
|
'message' => "{$xname} failed (command error)",
|
||||||
'long' => $r,
|
'long' => $r,
|
||||||
'exception' => null,
|
'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
|
return
|
||||||
[
|
[
|
||||||
'result' => self::STATUS_OK,
|
'result' => self::STATUS_OK,
|
||||||
'message' => "{".$xname."} succeeded",
|
'message' => "{".$xname."} succeeded ('$r[0]' | '$r[1]')",
|
||||||
'long' => $r,
|
'long' => $r,
|
||||||
'exception' => null,
|
'exception' => null,
|
||||||
];
|
];
|
||||||
@ -599,7 +608,8 @@ class SelfTest implements IWebsiteModule
|
|||||||
$url = $urlobj;
|
$url = $urlobj;
|
||||||
if (is_array($urlobj)) $url = $urlobj['url'];
|
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);
|
$r = curl_http_request($url);
|
||||||
$count++;
|
$count++;
|
||||||
|
@ -161,6 +161,40 @@ class Website
|
|||||||
return $this->config['prod'];
|
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()
|
public function isLoggedInByCookie()
|
||||||
{
|
{
|
||||||
if ($this->isLoggedIn !== null) return $this->isLoggedIn;
|
if ($this->isLoggedIn !== null) return $this->isLoggedIn;
|
||||||
|
Loading…
Reference in New Issue
Block a user