feat: decouple storage
This commit is contained in:
parent
24c1467e68
commit
a665def876
2 changed files with 15 additions and 18 deletions
|
@ -376,7 +376,7 @@ function execute(string $runtimeId, array $build, array $vars, string $data, str
|
||||||
return $execution;
|
return $execution;
|
||||||
};
|
};
|
||||||
|
|
||||||
function runBuildStage(string $runtimeId, string $source, array $vars, string $baseImage, string $runtime): array
|
function runBuildStage(string $runtimeId, string $source, string $buildDir, array $vars, string $baseImage, string $runtime): array
|
||||||
{
|
{
|
||||||
global $orchestrationPool;
|
global $orchestrationPool;
|
||||||
$orchestration = $orchestrationPool->get();
|
$orchestration = $orchestrationPool->get();
|
||||||
|
@ -394,7 +394,7 @@ function runBuildStage(string $runtimeId, string $source, array $vars, string $b
|
||||||
/**
|
/**
|
||||||
* Move code files from source to temporary destination
|
* Move code files from source to temporary destination
|
||||||
*/
|
*/
|
||||||
$device = new Local();
|
$device = new Local($buildDir);
|
||||||
$destination = "/tmp/$runtimeId/code.tar.gz";
|
$destination = "/tmp/$runtimeId/code.tar.gz";
|
||||||
if (App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) === Storage::DEVICE_LOCAL) {
|
if (App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) === Storage::DEVICE_LOCAL) {
|
||||||
if(!$device->move($source, $destination)) {
|
if(!$device->move($source, $destination)) {
|
||||||
|
@ -515,17 +515,11 @@ function runBuildStage(string $runtimeId, string $source, array $vars, string $b
|
||||||
throw new Exception('Something went wrong during the build process.');
|
throw new Exception('Something went wrong during the build process.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload new code
|
/**
|
||||||
|
* Upload built code to expected build directory
|
||||||
|
*/
|
||||||
$path = $device->getPath(\uniqid() . '.' . \pathinfo('code.tar.gz', PATHINFO_EXTENSION));
|
$path = $device->getPath(\uniqid() . '.' . \pathinfo('code.tar.gz', PATHINFO_EXTENSION));
|
||||||
|
|
||||||
if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists
|
|
||||||
if (@\mkdir(\dirname($path), 0777, true)) {
|
|
||||||
\chmod(\dirname($path), 0777);
|
|
||||||
} else {
|
|
||||||
throw new Exception('Can\'t create directory: ' . \dirname($path));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) === Storage::DEVICE_LOCAL) {
|
if (App::getEnv('_APP_STORAGE_DEVICE', Storage::DEVICE_LOCAL) === Storage::DEVICE_LOCAL) {
|
||||||
if (!$device->move($builtCodePath, $path)) {
|
if (!$device->move($builtCodePath, $path)) {
|
||||||
throw new Exception('Failed to upload built code upload to storage', 500);
|
throw new Exception('Failed to upload built code upload to storage', 500);
|
||||||
|
@ -576,16 +570,17 @@ function runBuildStage(string $runtimeId, string $source, array $vars, string $b
|
||||||
// POST /v1/runtimes
|
// POST /v1/runtimes
|
||||||
App::post('/v1/runtimes')
|
App::post('/v1/runtimes')
|
||||||
->desc("Create a new runtime server")
|
->desc("Create a new runtime server")
|
||||||
->param('runtimeId', '', new Text(128), 'Unique runtime ID.', false)
|
->param('runtimeId', '', new Text(128), 'Unique runtime ID.')
|
||||||
->param('source', '', new Text(0), 'Path to source files.', false)
|
->param('source', '', new Text(0), 'Path to source files.')
|
||||||
->param('vars', '', new Assoc(), 'Environment Variables required for the build', false)
|
->param('destination', '', new Text(0), 'Destination folder to store build files into.')
|
||||||
->param('runtime', '', new Text(128), 'Runtime for the cloud function', false)
|
->param('vars', '', new Assoc(), 'Environment Variables required for the build')
|
||||||
->param('baseImage', '', new Text(128), 'Base image name of the runtime', false)
|
->param('runtime', '', new Text(128), 'Runtime for the cloud function')
|
||||||
|
->param('baseImage', '', new Text(128), 'Base image name of the runtime')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->action(function (string $runtimeId, string $source, array $vars, string $runtime, string $baseImage, Response $response) {
|
->action(function (string $runtimeId, string $source, string $destination, array $vars, string $runtime, string $baseImage, Response $response) {
|
||||||
|
|
||||||
// TODO: Check if runtime already exists..
|
// TODO: Check if runtime already exists..
|
||||||
$build = runBuildStage($runtimeId, $source, $vars, $baseImage, $runtime);
|
$build = runBuildStage($runtimeId, $source, $destination, $vars, $baseImage, $runtime);
|
||||||
if ( $build['status'] === 'ready') {
|
if ( $build['status'] === 'ready') {
|
||||||
$build = createRuntimeServer($runtimeId, $build, $vars, $baseImage, $runtime);
|
$build = createRuntimeServer($runtimeId, $build, $vars, $baseImage, $runtime);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Executor;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
|
use Utopia\Storage\Storage;
|
||||||
|
|
||||||
class Executor
|
class Executor
|
||||||
{
|
{
|
||||||
|
@ -48,6 +49,7 @@ class Executor
|
||||||
$params = [
|
$params = [
|
||||||
'runtimeId' => "$projectId-$deploymentId",
|
'runtimeId' => "$projectId-$deploymentId",
|
||||||
'source' => $source,
|
'source' => $source,
|
||||||
|
'destination' => APP_STORAGE_BUILDS . "/app-$projectId",
|
||||||
'vars' => $vars,
|
'vars' => $vars,
|
||||||
'runtime' => $runtime,
|
'runtime' => $runtime,
|
||||||
'baseImage' => $baseImage
|
'baseImage' => $baseImage
|
||||||
|
|
Loading…
Reference in a new issue