From 8b7147965e7f717e6c6928ce3e2fc870d952276b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 13 Sep 2023 14:45:19 +0200 Subject: [PATCH] Fix git deploys with S3 storage --- app/views/install/compose.phtml | 21 +++++++++++++++++++++ app/workers/builds.php | 18 +++++++++++------- docker-compose.yml | 21 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 2fca03a04..f2ad01f57 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -383,6 +383,27 @@ services: - _APP_FUNCTIONS_MEMORY - _APP_OPTIONS_FORCE_HTTPS - _APP_DOMAIN + - _APP_STORAGE_DEVICE + - _APP_STORAGE_S3_ACCESS_KEY + - _APP_STORAGE_S3_SECRET + - _APP_STORAGE_S3_REGION + - _APP_STORAGE_S3_BUCKET + - _APP_STORAGE_DO_SPACES_ACCESS_KEY + - _APP_STORAGE_DO_SPACES_SECRET + - _APP_STORAGE_DO_SPACES_REGION + - _APP_STORAGE_DO_SPACES_BUCKET + - _APP_STORAGE_BACKBLAZE_ACCESS_KEY + - _APP_STORAGE_BACKBLAZE_SECRET + - _APP_STORAGE_BACKBLAZE_REGION + - _APP_STORAGE_BACKBLAZE_BUCKET + - _APP_STORAGE_LINODE_ACCESS_KEY + - _APP_STORAGE_LINODE_SECRET + - _APP_STORAGE_LINODE_REGION + - _APP_STORAGE_LINODE_BUCKET + - _APP_STORAGE_WASABI_ACCESS_KEY + - _APP_STORAGE_WASABI_SECRET + - _APP_STORAGE_WASABI_REGION + - _APP_STORAGE_WASABI_BUCKET appwrite-worker-certificates: image: /: diff --git a/app/workers/builds.php b/app/workers/builds.php index 5f8ea9c4c..89aa22edb 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -20,6 +20,7 @@ use Utopia\Database\Database; use Utopia\Database\Query; use Utopia\Storage\Storage; use Utopia\Database\Validator\Authorization; +use Utopia\Storage\Device\Local; use Utopia\VCS\Adapter\Git\GitHub; require_once __DIR__ . '/../init.php'; @@ -248,22 +249,25 @@ class BuildsV1 extends Worker ); } - Console::execute('tar --exclude code.tar.gz -czf /tmp/builds/' . \escapeshellcmd($buildId) . '/code.tar.gz -C /tmp/builds/' . \escapeshellcmd($buildId) . '/code' . (empty($rootDirectory) ? '' : '/' . $rootDirectory) . ' .', '', $stdout, $stderr); + $tmpPath = '/tmp/builds/' . \escapeshellcmd($buildId); + $tmpPathFile = $tmpPath . '/code.tar.gz'; + + Console::execute('tar --exclude code.tar.gz -czf ' . $tmpPathFile . ' -C /tmp/builds/' . \escapeshellcmd($buildId) . '/code' . (empty($rootDirectory) ? '' : '/' . $rootDirectory) . ' .', '', $stdout, $stderr); $deviceFunctions = $this->getFunctionsDevice($project->getId()); - $fileName = 'code.tar.gz'; - $fileTmpName = '/tmp/builds/' . $buildId . '/code.tar.gz'; + $localDevice = new Local(); + $buffer = $localDevice->read($tmpPathFile); + $mimeType = $localDevice->getFileMimeType($tmpPathFile); - $path = $deviceFunctions->getPath($deployment->getId() . '.' . \pathinfo($fileName, PATHINFO_EXTENSION)); - - $result = $deviceFunctions->move($fileTmpName, $path); + $path = $deviceFunctions->getPath($deployment->getId() . '.' . \pathinfo('code.tar.gz', PATHINFO_EXTENSION)); + $result = $deviceFunctions->write($path, $buffer, $mimeType); if (!$result) { throw new \Exception("Unable to move file"); } - Console::execute('rm -rf /tmp/builds/' . \escapeshellcmd($buildId), '', $stdout, $stderr); + Console::execute('rm -rf ' . $tmpPath, '', $stdout, $stderr); $source = $path; diff --git a/docker-compose.yml b/docker-compose.yml index bd04c8a79..5b7e070e7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -418,6 +418,27 @@ services: - _APP_FUNCTIONS_MEMORY - _APP_OPTIONS_FORCE_HTTPS - _APP_DOMAIN + - _APP_STORAGE_DEVICE + - _APP_STORAGE_S3_ACCESS_KEY + - _APP_STORAGE_S3_SECRET + - _APP_STORAGE_S3_REGION + - _APP_STORAGE_S3_BUCKET + - _APP_STORAGE_DO_SPACES_ACCESS_KEY + - _APP_STORAGE_DO_SPACES_SECRET + - _APP_STORAGE_DO_SPACES_REGION + - _APP_STORAGE_DO_SPACES_BUCKET + - _APP_STORAGE_BACKBLAZE_ACCESS_KEY + - _APP_STORAGE_BACKBLAZE_SECRET + - _APP_STORAGE_BACKBLAZE_REGION + - _APP_STORAGE_BACKBLAZE_BUCKET + - _APP_STORAGE_LINODE_ACCESS_KEY + - _APP_STORAGE_LINODE_SECRET + - _APP_STORAGE_LINODE_REGION + - _APP_STORAGE_LINODE_BUCKET + - _APP_STORAGE_WASABI_ACCESS_KEY + - _APP_STORAGE_WASABI_SECRET + - _APP_STORAGE_WASABI_REGION + - _APP_STORAGE_WASABI_BUCKET appwrite-worker-certificates: entrypoint: worker-certificates