Fetch old version and env vars
This commit is contained in:
parent
54c0e8bf82
commit
a447f21297
4 changed files with 68 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
global $cli;
|
||||
|
||||
use Appwrite\Docker\Compose;
|
||||
use Utopia\CLI\Console;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\View;
|
||||
|
@ -12,9 +13,9 @@ $cli
|
|||
->action(function () {
|
||||
/**
|
||||
* 1. Start - DONE
|
||||
* 2. Check for older setup and get older version
|
||||
* 2. Check for older setup and get older version - DONE
|
||||
* 2.1 If older version is equal or bigger(?) than current version, **stop setup**
|
||||
* 2.2. Get ENV vars
|
||||
* 2.2. Get ENV vars - DONE
|
||||
* 2.2.1 Fetch from older docker-compose.yml file
|
||||
* 2.2.2 Fetch from older .env file (manually parse)
|
||||
* 2.3 Use old ENV vars as default values
|
||||
|
@ -22,14 +23,46 @@ $cli
|
|||
* Otherwise, just use default vars. - DONE
|
||||
* 3. Ask user to backup important volumes, env vars, and SQL tables
|
||||
* In th future we can try and automate this for smaller/medium size setups
|
||||
* 4. Drop new docker-compose.yml setup (located inside the container, no network dependencies with appwrite.io)
|
||||
* 4. Drop new docker-compose.yml setup (located inside the container, no network dependencies with appwrite.io) - DONE
|
||||
* 5. Run docker-compose up -d - DONE
|
||||
* 6. Run data migration
|
||||
*/
|
||||
$vars = Config::getParam('variables');
|
||||
$path = '/usr/src/code/appwrite';
|
||||
$version = null;
|
||||
|
||||
Console::success('Starting Appwrite installation...');
|
||||
|
||||
// Create directory with write permissions
|
||||
if (null !== $path && !\file_exists(\dirname($path))) {
|
||||
if (!@\mkdir(\dirname($path), 0755, true)) {
|
||||
Console::error('Can\'t create directory '.\dirname($path));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
$data = @file_get_contents($path.'/docker-compose.yml');
|
||||
|
||||
if($data !== false) {
|
||||
$compose = new Compose($data);
|
||||
$service = $compose->getService('appwrite');
|
||||
$version = ($service) ? $service->getImageVersion() : $version;
|
||||
|
||||
if($version) {
|
||||
foreach($compose->getServices() as $service) { // Fetch all env vars from previous compose file
|
||||
if(!$service) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$env = $service->getEnvironment()->list();
|
||||
|
||||
var_dump($env);
|
||||
}
|
||||
|
||||
// Fetch all env vars from previous .env file
|
||||
}
|
||||
}
|
||||
|
||||
$httpPort = Console::confirm('Choose your server HTTP port: (default: 80)');
|
||||
$httpPort = ($httpPort) ? $httpPort : 80;
|
||||
|
||||
|
@ -64,8 +97,6 @@ $cli
|
|||
->setParam('vars', $input)
|
||||
;
|
||||
|
||||
$path = '/usr/src/code';
|
||||
|
||||
if(!file_put_contents($path.'/docker-compose.yml', $templateForCompose->render(false))) {
|
||||
Console::error('Failed to save Docker Compose file');
|
||||
exit(1);
|
||||
|
|
|
@ -17,11 +17,11 @@ class Service
|
|||
public function __construct(array $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
$this->service['environment'] = isset($this->service['environment']) ? new Env(implode("\n", $this->service['environment'])) : null;
|
||||
$this->service['environment'] = isset($this->service['environment']) ? new Env(implode("\n", $this->service['environment'])) : new Env('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return string
|
||||
*/
|
||||
public function getContainerName(): string
|
||||
{
|
||||
|
@ -29,10 +29,27 @@ class Service
|
|||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return string
|
||||
*/
|
||||
public function getImage(): string
|
||||
{
|
||||
return (isset($this->service['image'])) ? $this->service['image'] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getImageVersion(): string
|
||||
{
|
||||
$image = $this->getImage();
|
||||
return substr($image, strpos($image, ':')+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEnvironment(): Env
|
||||
{
|
||||
return $this->service['environment'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,16 @@ class Env
|
|||
return (isset($this->vars[$key])) ? $this->vars[$key] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All Vars
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list(): array
|
||||
{
|
||||
return $this->vars;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -39,6 +39,8 @@ class ComposeTest extends TestCase
|
|||
$this->assertCount(17, $this->object->getServices());
|
||||
$this->assertEquals('appwrite-telegraf', $this->object->getService('telegraf')->getContainerName());
|
||||
$this->assertEquals('appwrite', $this->object->getService('appwrite')->getContainerName());
|
||||
$this->assertEquals('', $this->object->getService('appwrite')->getImageVersion());
|
||||
$this->assertEquals('2.2', $this->object->getService('traefik')->getImageVersion());
|
||||
}
|
||||
|
||||
public function testNetworks()
|
||||
|
|
Loading…
Reference in a new issue