2
3
mirror of https://github.com/octoleo/docker-joomla.git synced 2024-10-31 18:52:28 +00:00

Change the update script to a PHP script reading the downloads site API

This commit is contained in:
Michael Babker 2017-01-03 20:26:38 -06:00
parent 332fe7ec8d
commit 246245e771
2 changed files with 92 additions and 26 deletions

92
update.php Normal file
View File

@ -0,0 +1,92 @@
<?php
// Fetch the current 3.x version from the downloads site API
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://downloads.joomla.org/api/v1/latest/cms');
$result = curl_exec($ch);
curl_close($ch);
if ($result === false)
{
echo 'Could not fetch version data, please check your connection.' . PHP_EOL;
exit(1);
}
$data = json_decode($result, true);
foreach ($data['branches'] as $branch)
{
if ($branch['branch'] === 'Joomla! 3')
{
$version = $branch['version'];
}
}
if (!isset($version))
{
echo 'Joomla! 3.x version data not included in API response.' . PHP_EOL;
exit(1);
}
$urlVersion = str_replace('.', '-', $version);
$filename = "Joomla_$version-Stable-Full_Package.zip";
// Fetch the SHA1 signature for the file
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "https://downloads.joomla.org/api//v1/signatures/cms/$urlVersion");
$result = curl_exec($ch);
curl_close($ch);
if ($result === false)
{
echo 'Could not fetch signature data, please check your connection.' . PHP_EOL;
exit(1);
}
$data = json_decode($result, true);
foreach ($data['files'] as $file)
{
if ($file['filename'] === $filename)
{
$signature = $file['sha1'];
}
}
if (!isset($signature))
{
echo 'ZIP file SHA1 signature not included in API response.' . PHP_EOL;
exit(1);
}
foreach (['apache', 'apache-php7', 'fpm', 'fpm-php7'] as $variant)
{
$dockerfile = __DIR__ . "/$variant/Dockerfile";
$fileContents = file_get_contents($dockerfile);
$fileContents = preg_replace('#ENV JOOMLA_VERSION [^ ]*\n#', "ENV JOOMLA_VERSION $version\n", $fileContents);
$fileContents = preg_replace('#ENV JOOMLA_SHA1 [^ ]*\n#', "ENV JOOMLA_SHA1 $signature\n\n", $fileContents);
file_put_contents($dockerfile, $fileContents);
// To make management easier, we use these files for all variants
copy(__DIR__ . '/docker-entrypoint.sh', __DIR__ . "/$variant/docker-entrypoint.sh");
copy(__DIR__ . '/makedb.php', __DIR__ . "/$variant/makedb.php");
}
echo 'Dockerfile variants updated' . PHP_EOL;

View File

@ -1,26 +0,0 @@
#!/bin/bash
set -e
# TODO - We (Joomla) need to expose an alternate API to checking the latest version other than our XML files
current="$(curl -A 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36' -sSL 'https://developer.joomla.org/latest_version.json' | sed -r 's/^.*"current":"([^"]+)".*$/\1/')"
# We're putting a lot of trust in this process, once Joomla has an exposed API to query the SHA1 use that instead
wget -O joomla.zip https://github.com/joomla/joomla-cms/releases/download/$current/Joomla_$current-Stable-Full_Package.zip
sha1="$(sha1sum joomla.zip | sed -r 's/ .*//')"
for variant in apache apache-php7 fpm fpm-php7; do
(
set -x
sed -ri '
s/^(ENV JOOMLA_VERSION) .*/\1 '"$current"'/;
s/^(ENV JOOMLA_SHA1) .*/\1 '"$sha1"'/;
' "$variant/Dockerfile"
# To make management easier, we use these files for all variants
cp docker-entrypoint.sh "$variant/docker-entrypoint.sh"
cp makedb.php "$variant/makedb.php"
)
done
rm joomla.zip