#972 -- Make the repository friendlier to people using release builds.

This commit is contained in:
Buster "Silver Eagle" Neece 2018-11-19 22:53:15 -06:00
parent acc0fbde22
commit a1163afba5
6 changed files with 71 additions and 29 deletions

17
.gitattributes vendored
View File

@ -12,4 +12,19 @@ Dockerfile text eol=lf
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.jpg binary
# Files that should be excluded from the Release zip/gz's
/.github export-ignore
/tests export-ignore
/util/docker export-ignore
/util/openapi.php export-ignore
/util/unused.php export-ignore
/*.yml export-ignore
/*.yaml export-ignore
/.travis.yml export-ignore
/docker.sh export-ignore
/README.md export-ignore
/SUPPORT.md export-ignore
/CODE_OF_CONDUCT.md export-ignore
/CONTRIBUTING.md export-ignore

View File

@ -196,7 +196,8 @@ return function (\Azura\Container $di)
$di[\App\Version::class] = function($di) {
return new \App\Version(
$di[\Azura\Cache::class]
$di[\Azura\Cache::class],
$di['settings']
);
};

View File

@ -14,19 +14,13 @@ while test $# -gt 0; do
done
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' ansible|grep "install ok installed")
echo Checking for Ansible: $PKG_OK
echo "Checking for Ansible: $PKG_OK"
. /etc/lsb-release
if [ "" == "$PKG_OK" ]; then
if [[ "" == "$PKG_OK" ]]; then
sudo apt-get update
sudo apt-get install -q -y software-properties-common
sudo add-apt-repository -y ppa:ansible/ansible
# if [ $DISTRIB_RELEASE = "14.04" ]; then
# sudo add-apt-repository -y ppa:fkrull/deadsnakes-python2.7
# fi
sudo apt-get update
sudo apt-get install -q -y python2.7 python-pip python-mysqldb ansible
fi
@ -34,4 +28,4 @@ fi
APP_ENV="${APP_ENV:-production}"
echo "Installing AzuraCast (Environment: $APP_ENV)"
ansible-playbook util/ansible/deploy.yml --inventory=util/ansible/hosts --extra-vars "app_env=$APP_ENV"
ansible-playbook util/ansible/deploy.yml --inventory=util/ansible/hosts --extra-vars "app_env=$APP_ENV"

View File

@ -89,13 +89,21 @@ class CheckForUpdates extends TaskAbstract
}
try {
$request_body = [
'id' => $app_uuid,
'is_docker' => (bool)$this->app_settings[Settings::IS_DOCKER],
'environment' => $this->app_settings[Settings::APP_ENV],
];
$commit_hash = $this->version->getCommitHash();
if ($commit_hash) {
$request_body['version'] = $commit_hash;
} else {
$request_body['release'] = Version::FALLBACK_VERSION;
}
$response = $this->http_client->request('POST', self::UPDATE_URL, [
'json' => [
'id' => $app_uuid,
'is_docker' => (bool)$this->app_settings[Settings::IS_DOCKER],
'version' => $this->version->getCommitHash(),
'environment' => $this->app_settings[Settings::APP_ENV],
]
'json' => $request_body,
]);
$update_data_raw = $response->getBody()->getContents();

View File

@ -2,6 +2,7 @@
namespace App;
use Azura\Cache;
use Azura\Settings;
use Symfony\Component\Process\Process;
/**
@ -9,12 +10,24 @@ use Symfony\Component\Process\Process;
*/
class Version
{
/** @var string Version that is displayed if no Git repository information is present. */
const FALLBACK_VERSION = '0.9.1';
/** @var Cache */
protected $cache;
public function __construct(Cache $cache)
/** @var string */
protected $repo_dir;
/** @var Settings */
protected $app_settings;
public function __construct(Cache $cache, Settings $app_settings)
{
$this->cache = $cache;
$this->app_settings = $app_settings;
$this->repo_dir = $app_settings[Settings::BASE_DIR];
}
/**
@ -23,7 +36,7 @@ class Version
public function getVersion()
{
$details = $this->getDetails();
return $details['tag'] ?? 'N/A';
return $details['tag'] ?? self::FALLBACK_VERSION;
}
/**
@ -32,16 +45,19 @@ class Version
public function getVersionText()
{
$details = $this->getDetails();
return 'v'.$details['tag'].', #'.$details['commit_short'].' ('.$details['commit_date'].')';
return (isset($details['tag']))
? 'v'.$details['tag'].', #'.$details['commit_short'].' ('.$details['commit_date'].')'
: 'v'.self::FALLBACK_VERSION.' Release Build';
}
/**
* @return string The long-form Git hash that represents the current commit of this installation.
* @return string|null The long-form Git hash that represents the current commit of this installation.
*/
public function getCommitHash(): string
public function getCommitHash(): ?string
{
$details = $this->getDetails();
return $details['commit'];
return $details['commit'] ?? null;
}
/**
@ -56,7 +72,7 @@ class Version
if (!$details) {
$details = $this->cache->getOrSet('app_version_details', function() {
return $this->_getRawDetails();
}, 86400);
}, $this->app_settings->isProduction() ? 86400 : 600);
}
return $details;
@ -69,6 +85,10 @@ class Version
*/
protected function _getRawDetails(): array
{
if (!is_dir($this->repo_dir.'/.git')) {
return [];
}
$details = [];
// Get the long form of the latest commit's hash.
@ -111,7 +131,7 @@ class Version
protected function _runProcess($proc, $default = ''): string
{
$process = new Process($proc);
$process->setWorkingDirectory(dirname(__DIR__));
$process->setWorkingDirectory($this->repo_dir);
$process->run();
if (!$process->isSuccessful()) {

View File

@ -19,9 +19,9 @@ while test $# -gt 0; do
done
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' ansible|grep "install ok installed")
echo Checking for Ansible: $PKG_OK
echo "Checking for Ansible: $PKG_OK"
if [ "" == "$PKG_OK" ]; then
if [[ "" == "$PKG_OK" ]]; then
sudo apt-get update
sudo apt-get install -q -y software-properties-common
sudo apt-add-repository ppa:ansible/ansible
@ -37,8 +37,12 @@ UPDATE_REVISION="${UPDATE_REVISION:-30}"
echo "Updating AzuraCast (Environment: $APP_ENV, Update revision: $UPDATE_REVISION)"
if [ $APP_ENV = "production" ]; then
git reset --hard && git pull
if [[ ${APP_ENV} = "production" ]]; then
if [[ -d ".git" ]]; then
git reset --hard && git pull
else
echo "You are running a release build. Any code updates should be applied manually."
fi
fi
ansible-playbook util/ansible/update.yml --inventory=util/ansible/hosts --extra-vars "app_env=$APP_ENV update_revision=$UPDATE_REVISION"