From 1422d96c80b78882507d1aaafd3a350cfba74f05 Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sat, 28 Aug 2021 19:28:15 +0000 Subject: [PATCH 01/16] tools (#31) fix fix fix fix fix fix fix put env tool tools Co-authored-by: Sieciech Reviewed-on: http://git.fufle.net/Community/CureNet/pulls/31 Co-Authored-By: Sieciech Co-Committed-By: Sieciech --- tools/putenv/env | 5 +++ tools/putenv/putenv.php | 80 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tools/putenv/env create mode 100644 tools/putenv/putenv.php diff --git a/tools/putenv/env b/tools/putenv/env new file mode 100644 index 0000000..d3123e4 --- /dev/null +++ b/tools/putenv/env @@ -0,0 +1,5 @@ +name=value +name2="value 2" +#name3=value3 +name4 = value4 +name5 = "value 5" \ No newline at end of file diff --git a/tools/putenv/putenv.php b/tools/putenv/putenv.php new file mode 100644 index 0000000..ae9698c --- /dev/null +++ b/tools/putenv/putenv.php @@ -0,0 +1,80 @@ +file = $argv[1]; + $this->key = $argv[2]; + $this->value = $argv[3]; + break; + + case 3: + $this->file = $argv[1]; + $this->key = $argv[2]; + $this->value = fgets(STDIN); + break; + + default: + echo "usage: + php8.0 putenv.php filename key value + echo value | php8.0 putenv filename key"; + throw new Exception("invalid params"); + } + if (!file_exists($this->file)) { + throw new Exception('File not found'); + } + $changed = 0; + $lineWasEmpty = false; + $key = $this->key; + $value = $this->value; + if (strpos($value, ' ') !== false) { + $value = '"' . addslashes($value) . '"'; + } + $this->content = file($this->file); + foreach ($this->content as $l => $line) { + if (strlen(trim($line)) < 1) { + if ($lineWasEmpty) { + $this->content[$l] = null; + } else { + $lineWasEmpty = true; + } + continue; + } + $lineWasEmpty = false; + if (!str_starts_with($line, $this->key)) { + continue; + } + $next = trim(substr($line, strlen($this->key))); + if (strlen($next) === 0 || $next[0] !== '=') { + continue; + } + $this->content[$l] = $key . '=' . $value; + $changed++; + } + if ($changed === 0) { + $this->content[] = $key . '=' . $value; + } else if ($changed > 1) { + echo "Key $key changed $changed times\n"; + } + $content = $this->content; + $this->content = []; + foreach ($content as $line) { + if ($line !== null) { + $this->content[] = $line; + } + } + $content = implode('', $this->content); + file_put_contents($this->file, $content); + } +} + +new PutEnv(); From 5180445f7c271be51a895183ceb9f424d460846c Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 09:03:19 +0200 Subject: [PATCH 02/16] fix putenv --- tools/putenv/putenv.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/putenv/putenv.php b/tools/putenv/putenv.php index ae9698c..43d0aa5 100644 --- a/tools/putenv/putenv.php +++ b/tools/putenv/putenv.php @@ -2,11 +2,15 @@ namespace Tools; +use Exception; + class PutEnv { + private string $file; private string $key; private string $value; private array $content; + public function __construct() { $argv = $_SERVER['argv']; $argc = sizeof($argv); From 178423d59e32175369237728b1916f61a350517d Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 09:13:54 +0200 Subject: [PATCH 03/16] fix putenv --- tools/putenv/putenv.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/putenv/putenv.php b/tools/putenv/putenv.php index 43d0aa5..37e50db 100644 --- a/tools/putenv/putenv.php +++ b/tools/putenv/putenv.php @@ -61,7 +61,7 @@ class PutEnv { if (strlen($next) === 0 || $next[0] !== '=') { continue; } - $this->content[$l] = $key . '=' . $value; + $this->content[$l] = $key . '=' . $value . PHP_EOF; $changed++; } if ($changed === 0) { From 605cb430f340e19265b63f0bd77faf2bb1e28470 Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 09:20:51 +0200 Subject: [PATCH 04/16] ns nl --- tools/putenv/putenv.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/putenv/putenv.php b/tools/putenv/putenv.php index 37e50db..c74f404 100644 --- a/tools/putenv/putenv.php +++ b/tools/putenv/putenv.php @@ -61,7 +61,7 @@ class PutEnv { if (strlen($next) === 0 || $next[0] !== '=') { continue; } - $this->content[$l] = $key . '=' . $value . PHP_EOF; + $this->content[$l] = $key . '=' . $value . \PHP_EOF; $changed++; } if ($changed === 0) { From 44c8481550bc70f2259cc37d1a370663de9f600e Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 09:29:44 +0200 Subject: [PATCH 05/16] eol --- tools/putenv/putenv.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/putenv/putenv.php b/tools/putenv/putenv.php index c74f404..1d81eee 100644 --- a/tools/putenv/putenv.php +++ b/tools/putenv/putenv.php @@ -61,7 +61,7 @@ class PutEnv { if (strlen($next) === 0 || $next[0] !== '=') { continue; } - $this->content[$l] = $key . '=' . $value . \PHP_EOF; + $this->content[$l] = $key . '=' . $value . \PHP_EOL; $changed++; } if ($changed === 0) { From e37815352b8e593ed8eacb746364c02f639dcd00 Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 09:49:27 +0200 Subject: [PATCH 06/16] new --- tools/putenv/putenv.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/putenv/putenv.php b/tools/putenv/putenv.php index 1d81eee..1f0833b 100644 --- a/tools/putenv/putenv.php +++ b/tools/putenv/putenv.php @@ -45,7 +45,8 @@ class PutEnv { } $this->content = file($this->file); foreach ($this->content as $l => $line) { - if (strlen(trim($line)) < 1) { + $this->content[$l] = $line = trim($line); + if (strlen($line) < 1) { if ($lineWasEmpty) { $this->content[$l] = null; } else { @@ -76,7 +77,7 @@ class PutEnv { $this->content[] = $line; } } - $content = implode('', $this->content); + $content = implode(PHP_EOL, $this->content); file_put_contents($this->file, $content); } } From b04b6103b942cc70534664fd31b015c73061473d Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 10:23:06 +0200 Subject: [PATCH 07/16] pipeline --- Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0a878bc..949e12f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,8 +74,8 @@ pipeline { stage('Backend') { steps { dir(path: 'src/backend') { - sh "APP_SECRET=`php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` && sed -i \"s/APP_SECRET=.*/APP_SECRET=${APP_SECRET}/g\" .env.test" - sh "sed -i \"s+DATABASE_URL=.*+DATABASE_URL=${DatabaseUrlTesting}+g\" .env.test" + sh "APP_SECRET=`php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` && echo $APP_SECRET | php8.0 ../../tools/putenv/putenv.php .env.test APP_SECRET" + sh "php8.0 ../../tools/putenv/putenv.php .env.test DATABASE_URL \"${DatabaseUrlTesting}\"" sh 'php8.0 /usr/local/bin/composer dump-env test' sh 'php8.0 bin/console doctrine:schema:update --force'; } @@ -123,8 +123,8 @@ pipeline { stage('Backend') { steps { dir(path: 'src/backend') { - sh "APP_SECRET=`php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` && sed -i \"s/APP_SECRET=.*/APP_SECRET=${APP_SECRET}/g\" .env" - sh "sed -i \"s+DATABASE_URL=.*+DATABASE_URL=${DatabaseUrl}+g\" .env" + sh "APP_SECRET=`php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` && echo $APP_SECRET | php8.0 ../../tools/putenv/putenv.php .env APP_SECRET" + sh "php8.0 ../../tools/putenv/putenv.php .env DATABASE_URL \"${DatabaseUrl}\"" sh 'php8.0 /usr/local/bin/composer dump-env prod' } From 79f2ff0b241084fb8bb1536ba69b89c0b929a9a5 Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 10:39:27 +0200 Subject: [PATCH 08/16] app secret --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 949e12f..032ea73 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,7 +74,7 @@ pipeline { stage('Backend') { steps { dir(path: 'src/backend') { - sh "APP_SECRET=`php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` && echo $APP_SECRET | php8.0 ../../tools/putenv/putenv.php .env.test APP_SECRET" + sh "echo `php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` | php8.0 ../../tools/putenv/putenv.php .env.test APP_SECRET" sh "php8.0 ../../tools/putenv/putenv.php .env.test DATABASE_URL \"${DatabaseUrlTesting}\"" sh 'php8.0 /usr/local/bin/composer dump-env test' sh 'php8.0 bin/console doctrine:schema:update --force'; From 921b8aaa63abf9503e3dc12d84acc3bbb13162ce Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 10:49:16 +0200 Subject: [PATCH 09/16] app secret --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 032ea73..b5691ea 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -123,7 +123,7 @@ pipeline { stage('Backend') { steps { dir(path: 'src/backend') { - sh "APP_SECRET=`php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` && echo $APP_SECRET | php8.0 ../../tools/putenv/putenv.php .env APP_SECRET" + sh "echo `php8.0 -r 'echo md5(\"branch=${BRANCH_NAME};\");'` | php8.0 ../../tools/putenv/putenv.php .env APP_SECRET" sh "php8.0 ../../tools/putenv/putenv.php .env DATABASE_URL \"${DatabaseUrl}\"" sh 'php8.0 /usr/local/bin/composer dump-env prod' } From b35695289b62d34a24732fbfec2778bb523a23ba Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 11:11:01 +0200 Subject: [PATCH 10/16] deploy --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index b5691ea..a6e3a13 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -164,7 +164,6 @@ pipeline { branch 'staging' branch 'beta' branch 'dev' - branch '29-profile-page' } } From be4dbf201a2f8335a806801829e9c12448422ace Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 11:24:23 +0200 Subject: [PATCH 11/16] migrate --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index a6e3a13..632de6c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -164,6 +164,7 @@ pipeline { branch 'staging' branch 'beta' branch 'dev' + branch '29-profile-page' } } @@ -188,6 +189,7 @@ pipeline { sh 'scp -r ./* web@fufle.net:${ProjectPath}/backend/' sh 'scp -r ./.env web@fufle.net:${ProjectPath}/backend/.env' sh 'ssh web@fufle.net chmod 777 ${ProjectPath}/backend/var -R' + sh 'ssh web@fufle.net cd ${ProjectPath} && php8.0 bin/console doctrine:schema:update --force' } } From 09916e134079e3eb4e5163b20c4aac4a8e4c94fa Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 12:05:04 +0200 Subject: [PATCH 12/16] migrate --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 632de6c..342541f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -189,7 +189,7 @@ pipeline { sh 'scp -r ./* web@fufle.net:${ProjectPath}/backend/' sh 'scp -r ./.env web@fufle.net:${ProjectPath}/backend/.env' sh 'ssh web@fufle.net chmod 777 ${ProjectPath}/backend/var -R' - sh 'ssh web@fufle.net cd ${ProjectPath} && php8.0 bin/console doctrine:schema:update --force' + sh 'ssh web@fufle.net bash -c "cd ${ProjectPath}/backend && php8.0 bin/console doctrine:schema:update --force"' } } From f3a3cdcad5a91ce5ba772aa0a9576f3920ea757b Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 12:34:59 +0200 Subject: [PATCH 13/16] migrate test --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 342541f..62d00a0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -189,7 +189,7 @@ pipeline { sh 'scp -r ./* web@fufle.net:${ProjectPath}/backend/' sh 'scp -r ./.env web@fufle.net:${ProjectPath}/backend/.env' sh 'ssh web@fufle.net chmod 777 ${ProjectPath}/backend/var -R' - sh 'ssh web@fufle.net bash -c "cd ${ProjectPath}/backend && php8.0 bin/console doctrine:schema:update --force"' + sh 'ssh web@fufle.net bash -c "cd ${ProjectPath}/backend && pwd && ls -la && php8.0 bin/console doctrine:schema:update --force"' } } From 4b0c634e28ef356b38f2b1f5407210502cd5f8f9 Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 13:02:56 +0200 Subject: [PATCH 14/16] migrate --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 62d00a0..d3ae483 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -189,7 +189,7 @@ pipeline { sh 'scp -r ./* web@fufle.net:${ProjectPath}/backend/' sh 'scp -r ./.env web@fufle.net:${ProjectPath}/backend/.env' sh 'ssh web@fufle.net chmod 777 ${ProjectPath}/backend/var -R' - sh 'ssh web@fufle.net bash -c "cd ${ProjectPath}/backend && pwd && ls -la && php8.0 bin/console doctrine:schema:update --force"' + sh 'ssh web@fufle.net bash -c "cd ${ProjectPath}/backend; pwd; ls -la; php8.0 bin/console doctrine:schema:update --force"' } } From 0802b3141e1542605721b2796fe70597f2fd6bab Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 13:28:29 +0200 Subject: [PATCH 15/16] migrate --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d3ae483..47bf0b1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -189,7 +189,7 @@ pipeline { sh 'scp -r ./* web@fufle.net:${ProjectPath}/backend/' sh 'scp -r ./.env web@fufle.net:${ProjectPath}/backend/.env' sh 'ssh web@fufle.net chmod 777 ${ProjectPath}/backend/var -R' - sh 'ssh web@fufle.net bash -c "cd ${ProjectPath}/backend; pwd; ls -la; php8.0 bin/console doctrine:schema:update --force"' + sh 'ssh web@fufle.net "cd ${ProjectPath}/backend; pwd; ls -la; php8.0 bin/console doctrine:schema:update --force"' } } From be0b8ef9f01faee28b95feeab10bfcbb8ebfb8d7 Mon Sep 17 00:00:00 2001 From: Sieciech Date: Sun, 29 Aug 2021 14:42:41 +0200 Subject: [PATCH 16/16] generate jwt keys --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 47bf0b1..465f46c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -189,7 +189,8 @@ pipeline { sh 'scp -r ./* web@fufle.net:${ProjectPath}/backend/' sh 'scp -r ./.env web@fufle.net:${ProjectPath}/backend/.env' sh 'ssh web@fufle.net chmod 777 ${ProjectPath}/backend/var -R' - sh 'ssh web@fufle.net "cd ${ProjectPath}/backend; pwd; ls -la; php8.0 bin/console doctrine:schema:update --force"' + sh 'ssh web@fufle.net "cd ${ProjectPath}/backend; php8.0 bin/console doctrine:schema:update --force"' + sh 'ssh web@fufle.net "cd ${ProjectPath}/backend; php8.0 bin/console lexik:jwt:generate-keypair --skip-if-exists"' } }