From 2087061af600ca768b22ae39c40612941324a434 Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Tue, 31 Dec 2019 12:04:09 +0100 Subject: [PATCH 1/7] The place where we have to work onto --- src/Helpers/Builds.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index 42d186c..22b7c18 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -60,6 +60,10 @@ $ret = array(); foreach ( $this->builds as $build ) { + + // TODO look into incremental + // TODO look into android_version + array_push( $ret, array( // CyanogenMod 'incremental' => $build->getIncremental(), -- GitLab From 1481464f71332e600c6b067874c0269927ae5e9b Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Fri, 3 Jan 2020 12:08:10 +0100 Subject: [PATCH 2/7] Return the update based on the same Android version of the current build --- .dockerignore | 2 ++ README.md | 23 +++++++++++++++++++++++ index.php | 2 +- src/Helpers/Builds.php | 19 ++++++++++++++----- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/.dockerignore b/.dockerignore index 331d387..4623ebb 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,4 @@ .git Dockerfile +builds/delta/*/*/*.zip +builds/full/*/*/*.zip diff --git a/README.md b/README.md index 12494f9..2af71a7 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,29 @@ Got a question? Not sure where it should be made? See [CONTRIBUTING](CONTRIBUTIN ## How to use +### Test + +``` +$ sudo docker stop lineageota \ + && sudo docker build -t e/lineageota . \ + && sudo docker run \ + -d \ + -p 80:80 \ + --rm \ + -v "${PWD}/builds/full:/var/www/html/builds/full" \ + --name lineageota \ + e/lineageota \ +``` + +Access to API via http://localhost/api/v1/\/\ + +Get logs with + +``` +$ sudo docker exec -ti lineageota tail -f LineageOTA.log +``` + + ### Composer ```shell diff --git a/index.php b/index.php index fbcef56..3e30e69 100644 --- a/index.php +++ b/index.php @@ -31,7 +31,7 @@ $protocol = 'https://'; $logger = new Logger('main'); - $logger->pushHandler(new StreamHandler('LineageOTA.log', Logger::WARNING)); + $logger->pushHandler(new StreamHandler('LineageOTA.log', Logger::INFO)); $app = new CmOta($logger); $app diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index 22b7c18..140a2c1 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -31,9 +31,9 @@ // This will contain the build list based on the current request private $builds = array(); - - private $postData = array(); - private $logger = null; + private $postData = array(); + private $logger = null; + private $currentBuild = null; /** * Constructor of the Builds class. @@ -61,8 +61,12 @@ foreach ( $this->builds as $build ) { - // TODO look into incremental - // TODO look into android_version + if (!is_null($this->currentBuild) && strcmp($this->currentBuild->getAndroidVersion(), $build->getAndroidVersion()) != 0) { + $this->logger->info($build->getIncremental().' ignored as Android version is not the same'); + continue; + } + + $this->logger->info($build->getIncremental().' is a new update'); array_push( $ret, array( // CyanogenMod @@ -175,6 +179,11 @@ if ( $build->isValid( $this->postData['params'] ) ) { array_push( $this->builds , $build ); + + if (strcmp($this->postData['params']['source_incremental'], $build->getIncremental()) == 0) { + $this->currentBuild = $build; + $this->logger->info($build->getIncremental().' is the current build'); + } } } } -- GitLab From eb6230adf51b6d371e1a7a71f94c1008d055d4ec Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Fri, 3 Jan 2020 14:52:19 +0100 Subject: [PATCH 3/7] Handle the case when the current build is not present. --- src/Helpers/Builds.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index 140a2c1..e12b681 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -189,5 +189,8 @@ } } } + + if (!empty($this->postData['params']['source_incremental']) && is_null($this->currentBuild)) + $this->currentBuild = $this->builds[1]; } } -- GitLab From d4619f31b6861480723cfc6fc545f85c42b0c581 Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Fri, 3 Jan 2020 14:55:10 +0100 Subject: [PATCH 4/7] Revert log level to warning --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 3e30e69..fbcef56 100644 --- a/index.php +++ b/index.php @@ -31,7 +31,7 @@ $protocol = 'https://'; $logger = new Logger('main'); - $logger->pushHandler(new StreamHandler('LineageOTA.log', Logger::INFO)); + $logger->pushHandler(new StreamHandler('LineageOTA.log', Logger::WARNING)); $app = new CmOta($logger); $app -- GitLab From 49c593835691e4f40ac0784b2e49cbd38dc554e3 Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Fri, 3 Jan 2020 14:57:09 +0100 Subject: [PATCH 5/7] Syntax --- src/Helpers/Builds.php | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index e12b681..f500f90 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -29,15 +29,15 @@ class Builds { - // This will contain the build list based on the current request + // This will contain the build list based on the current request private $builds = array(); private $postData = array(); private $logger = null; private $currentBuild = null; - /** - * Constructor of the Builds class. - */ + /** + * Constructor of the Builds class. + */ public function __construct($logger) { $this->logger = $logger; @@ -52,10 +52,10 @@ $this->getBuilds(); } - /** - * Return a valid response list of builds available based on the current request - * @return array An array preformatted with builds - */ + /** + * Return a valid response list of builds available based on the current request + * @return array An array preformatted with builds + */ public function get() { $ret = array(); @@ -92,21 +92,21 @@ return $ret; } - /** - * Set a custom set of POST data. Useful to hack the flow in case the data doesn't come within the body of the HTTP request - * @param array An array structured as POST data - * @return void - */ - public function setPostData( $customData ){ - $this->postData = $customData; - $this->builds = array(); - $this->getBuilds(); - } - - /** - * Return a valid response of the delta build (if available) based on the current request - * @return array An array preformatted with the delta build - */ + /** + * Set a custom set of POST data. Useful to hack the flow in case the data doesn't come within the body of the HTTP request + * @param array An array structured as POST data + * @return void + */ + public function setPostData( $customData ){ + $this->postData = $customData; + $this->builds = array(); + $this->getBuilds(); + } + + /** + * Return a valid response of the delta build (if available) based on the current request + * @return array An array preformatted with the delta build + */ public function getDelta() { $ret = false; @@ -134,7 +134,7 @@ return $ret; } - /* Utility / Internal */ + /* Utility / Internal */ private function getBuilds() { // Get physical paths of where the files resides -- GitLab From f613c0838a276e84e74ebf5c92567b69a063aaff Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Fri, 3 Jan 2020 16:31:59 +0100 Subject: [PATCH 6/7] Define docker tags --- .gitlab-ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 404c7a8..cb2308f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: docker:stable +image: docker:19.03.1 # When using dind, it's wise to use the overlayfs driver for # improved performance. @@ -7,9 +7,10 @@ variables: CONTAINER_IMAGE: registry.gitlab.e.foundation:5000/e/os/lineageota PUBLISH_USER: root PUBLISH_URL: ota.ecloud.global + DOCKER_TLS_CERTDIR: "/certs" services: -- docker:dind +- docker:19.03.1-dind before_script: - 'which ssh-agent || ( apk --update add openssh-client )' -- GitLab From 3f09c4ec9fb476a75ccd655a37b85006302859db Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Thu, 9 Jan 2020 16:21:38 +0100 Subject: [PATCH 7/7] Update documentation --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2af71a7..2e647c1 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,14 @@ Got a question? Not sure where it should be made? See [CONTRIBUTING](CONTRIBUTIN ### Test ``` -$ sudo docker stop lineageota \ - && sudo docker build -t e/lineageota . \ +$ sudo docker build -t e/lineageota . \ && sudo docker run \ -d \ -p 80:80 \ --rm \ -v "${PWD}/builds/full:/var/www/html/builds/full" \ --name lineageota \ - e/lineageota \ + e/lineageota ``` Access to API via http://localhost/api/v1/\/\ @@ -36,6 +35,7 @@ Get logs with $ sudo docker exec -ti lineageota tail -f LineageOTA.log ``` +You can also use this server with a device connected to the same network, specifying the correct IP (see below). ### Composer -- GitLab