From 50dc96ab9a364b0cfe52d7b00038c068d9607c27 Mon Sep 17 00:00:00 2001 From: MatteoGheza Date: Tue, 16 Mar 2021 09:49:49 +0000 Subject: [PATCH 1/5] Fully automate dev setup with Gitpod This commit implements a fully-automated development setup using Gitpod.io, an online IDE for GitLab, GitHub, and Bitbucket that enables Dev-Environments-As-Code. This makes it easy for anyone to get a ready-to-code workspace for any branch, issue or pull request almost instantly with a single click. --- .gitpod.Dockerfile | 5 +++++ .gitpod.yml | 34 ++++++++++++++++++++++++++++++++++ README.md | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .gitpod.Dockerfile create mode 100644 .gitpod.yml diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile new file mode 100644 index 0000000..77206d7 --- /dev/null +++ b/.gitpod.Dockerfile @@ -0,0 +1,5 @@ +#Inspired from https://github.com/koel/koel/blob/master/.gitpod.dockerfile + +FROM gitpod/workspace-mysql:latest + +ENV APACHE_DOCROOT_IN_REPO="server" \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..e4c2bb2 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,34 @@ +#Inspired from + +image: + file: .gitpod.dockerfile +ports: + - port: 8001 + onOpen: open-preview + - port: 3306 + onOpen: ignore +tasks: + - name: Apache + command: > + touch /var/log/apache2/error.log; + touch /var/log/apache2/access.log; + multitail /var/log/apache2/error.log -I /var/log/apache2/access.log + - name: Allerta + init: > + cd server; + composer install; + composer update; + cd resources; + npm install; + npm run prod; + cd ../..; + command: > + cd server/install; + WORKSPACE_URL=$(gp url 8001 | sed -E s/\\/$//); + mysql -e "CREATE DATABASE IF NOT EXISTS allerta"; + mysql -e "CREATE USER 'allerta'@'localhost' IDENTIFIED BY 'allerta_pwd';"; + mysql -e "GRANT ALL PRIVILEGES ON * . * TO 'allerta'@'localhost';"; + mysqladmin reload; + php install.php config -n "allerta" -u "allerta" -a "allerta_pwd" -o "127.0.0.1" -r "DEV_ENV"; + php install.php populate -m "admin" -b -s "password" -w "owner" -e "mail@mailserver.local"; + apachectl start; \ No newline at end of file diff --git a/README.md b/README.md index 205e44f..0c87b13 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # allerta-vvf -[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fallerta-vvf%2Fallerta-vvf.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fallerta-vvf%2Fallerta-vvf?ref=badge_shield) ![PHP Code Testing](https://github.com/allerta-vvf/allerta-vvf/workflows/PHP%20Code%20Testing/badge.svg) ![Languages count](https://img.shields.io/github/languages/count/allerta-vvf/allerta-vvf) ![Top language](https://img.shields.io/github/languages/top/allerta-vvf/allerta-vvf) ![GitHub issues](https://img.shields.io/github/issues-raw/allerta-vvf/allerta-vvf) ![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/allerta-vvf/allerta-vvf) ![GitHub stars](https://img.shields.io/github/stars/allerta-vvf/allerta-vvf?style=social) +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fallerta-vvf%2Fallerta-vvf.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fallerta-vvf%2Fallerta-vvf?ref=badge_shield) ![PHP Code Testing](https://github.com/allerta-vvf/allerta-vvf/workflows/PHP%20Code%20Testing/badge.svg) ![Languages count](https://img.shields.io/github/languages/count/allerta-vvf/allerta-vvf) ![Top language](https://img.shields.io/github/languages/top/allerta-vvf/allerta-vvf) ![GitHub issues](https://img.shields.io/github/issues-raw/allerta-vvf/allerta-vvf) ![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/allerta-vvf/allerta-vvf) ![GitHub stars](https://img.shields.io/github/stars/allerta-vvf/allerta-vvf?style=social) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/allerta-vvf/allerta-vvf) **Coming soon, stay tuned!** :thumbsup: From 8f3c7adc28d91df5bb8e8cf6f942dafcd93d4cb4 Mon Sep 17 00:00:00 2001 From: Matteo Gheza Date: Tue, 16 Mar 2021 11:06:06 +0100 Subject: [PATCH 2/5] Rename .gitpod.Dockerfile to .gitpod.dockerfile --- .gitpod.Dockerfile => .gitpod.dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .gitpod.Dockerfile => .gitpod.dockerfile (75%) diff --git a/.gitpod.Dockerfile b/.gitpod.dockerfile similarity index 75% rename from .gitpod.Dockerfile rename to .gitpod.dockerfile index 77206d7..2008184 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.dockerfile @@ -2,4 +2,4 @@ FROM gitpod/workspace-mysql:latest -ENV APACHE_DOCROOT_IN_REPO="server" \ No newline at end of file +ENV APACHE_DOCROOT_IN_REPO="server" From c822ddfe4b8eccebd51789767258cc8d0ab13547 Mon Sep 17 00:00:00 2001 From: MatteoGheza Date: Tue, 16 Mar 2021 11:10:38 +0000 Subject: [PATCH 3/5] Fixes --- .gitignore | 1 + .gitpod.yml | 25 +++++++++++++++++-------- server/install/installHelper.php | 19 +++++++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 901db68..7377c24 100644 --- a/.gitignore +++ b/.gitignore @@ -521,6 +521,7 @@ sw.js !/server/cypress/videos/.gitkeep deployment_remotes.php +adminer.php /server/resources/images/logo.png /server/resources/images/owner.png \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index e4c2bb2..7c00d22 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,5 +1,3 @@ -#Inspired from - image: file: .gitpod.dockerfile ports: @@ -10,9 +8,12 @@ ports: tasks: - name: Apache command: > - touch /var/log/apache2/error.log; - touch /var/log/apache2/access.log; - multitail /var/log/apache2/error.log -I /var/log/apache2/access.log + mkdir /tmp/apache; + touch /tmp/apache/error.log; + touch /tmp/apache/access.log; + export APACHE_PID_FILE="/tmp/apache/PID" APACHE_RUN_USER="gitpod" APACHE_RUN_GROUP="gitpod" APACHE_SERVER_NAME="localhost" APACHE_LOG_DIR="/tmp/apache"; + apache2; + multitail /tmp/apache/error.log -I /tmp/apache/access.log; - name: Allerta init: > cd server; @@ -29,6 +30,14 @@ tasks: mysql -e "CREATE USER 'allerta'@'localhost' IDENTIFIED BY 'allerta_pwd';"; mysql -e "GRANT ALL PRIVILEGES ON * . * TO 'allerta'@'localhost';"; mysqladmin reload; - php install.php config -n "allerta" -u "allerta" -a "allerta_pwd" -o "127.0.0.1" -r "DEV_ENV"; - php install.php populate -m "admin" -b -s "password" -w "owner" -e "mail@mailserver.local"; - apachectl start; \ No newline at end of file + php install.php config -n "allerta" -u "allerta" -a "allerta_pwd" -o $WORKSPACE_URL -r "DEV_ENV"; + php install.php populate -m "admin" -b -d -s "password" -w "owner" -e "mail@mailserver.local"; + cd ..; + wget https://github.com/vrana/adminer/releases/download/v4.8.0/adminer-4.8.0.php; + mv adminer-4.8.0.php adminer.php +vscode: + extensions: + - gruntfuggly.todo-tree@0.0.205:sbsZJOTJzKZtMVHQuS2iPw== + - coenraads.bracket-pair-colorizer-2@0.1.4:+JUeb/jFYZt2/0MS/gUllA== + - shelex.vscode-cy-helper@1.1.0:U9ok2y1bSmqn17OMuRMOfw== + - hookyqr.beautify@1.4.11:n9DJEUFbYD/YHaBXxm+pYw== \ No newline at end of file diff --git a/server/install/installHelper.php b/server/install/installHelper.php index f3903d4..d82bc2e 100644 --- a/server/install/installHelper.php +++ b/server/install/installHelper.php @@ -461,7 +461,7 @@ function full_path() return $url; } -function initOptions($name, $visible, $developer, $password, $report_email, $owner) +function initOptions($name, $visible, $developer, $password, $report_email, $owner, $url=null) { try{ include_once "../config.php"; @@ -508,7 +508,10 @@ INSERT INTO `".$prefix."_profiles` (`id`, `hidden`) VALUES (NULL, :hidden);".$qu $prep->bindValue(':hidden', ($visible ? 0 : 1), PDO::PARAM_INT); $prep->bindValue(':report_email', $report_email, PDO::PARAM_STR); $prep->bindValue(':owner', $owner, PDO::PARAM_STR); - $prep->bindValue(':web_url', str_replace("install/install.php", "", full_path()), PDO::PARAM_STR); + if(is_null($url)){ + $url = str_replace("install/install.php", "", full_path()); + } + $prep->bindValue(':web_url', $url, PDO::PARAM_STR); $prep->bindValue(':cron_job_code', str_replace(".", "", bin2hex(random_bytes(10)).base64_encode(openssl_random_pseudo_bytes(30))), PDO::PARAM_STR); $prep->bindValue(':cron_job_time', "01;00:00", PDO::PARAM_STR); $prep->execute(); @@ -564,11 +567,13 @@ function cli_helper($action, $options) case "populate": $name = validate_arg($options, "name", "admin"); $visible = array_key_exists("visible", $options); + $developer = array_key_exists("developer", $options); $password = validate_arg($options, "password", "password"); $report_email = validate_arg($options, "report_email", "postmaster@localhost.local"); $owner = validate_arg($options, "owner", "Owner"); + $url = validate_arg($options, "url", "htp://localhost/"); initDB(); - initOptions($name, $visible, $password, $report_email, $owner); + initOptions($name, $visible, $developer, $password, $report_email, $owner, $url); t("DB Populated successful"); finalInstallationHelperStep(); exit(0); @@ -612,6 +617,9 @@ function run_cli() \GetOpt\Option::create('b', 'visible', \GetOpt\GetOpt::NO_ARGUMENT) ->setDescription(t("Is admin visible?", false)) ->setArgumentName(t("Is admin visible?", false)), + \GetOpt\Option::create('d', 'developer', \GetOpt\GetOpt::NO_ARGUMENT) + ->setDescription(t("Enable devmode per the user", false)) + ->setArgumentName(t("Enable devmode per the user", false)), \GetOpt\Option::create('s', 'password', \GetOpt\GetOpt::OPTIONAL_ARGUMENT) ->setDescription(t("Admin password", false)) ->setArgumentName(t("Admin password", false)), @@ -620,7 +628,10 @@ function run_cli() ->setArgumentName(t("Owner", false)), \GetOpt\Option::create('e', 'report_email', \GetOpt\GetOpt::OPTIONAL_ARGUMENT) ->setDescription(t("Report email", false)) - ->setArgumentName(t("Report email", false)) + ->setArgumentName(t("Report email", false)), + \GetOpt\Option::create('u', 'url', \GetOpt\GetOpt::OPTIONAL_ARGUMENT) + ->setDescription(t("App url", false)) + ->setArgumentName(t("App url", false)), ] )->setDescription( t("Populate Allerta database", false) . "." . PHP_EOL . From 55e3ac3bfb236e2c77e243e2bfbcad9e7cdbe3c8 Mon Sep 17 00:00:00 2001 From: MatteoGheza Date: Tue, 16 Mar 2021 11:18:08 +0000 Subject: [PATCH 4/5] fix --- .gitpod.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitpod.yml b/.gitpod.yml index 7c00d22..3885f3a 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -30,8 +30,8 @@ tasks: mysql -e "CREATE USER 'allerta'@'localhost' IDENTIFIED BY 'allerta_pwd';"; mysql -e "GRANT ALL PRIVILEGES ON * . * TO 'allerta'@'localhost';"; mysqladmin reload; - php install.php config -n "allerta" -u "allerta" -a "allerta_pwd" -o $WORKSPACE_URL -r "DEV_ENV"; - php install.php populate -m "admin" -b -d -s "password" -w "owner" -e "mail@mailserver.local"; + php install.php config -n "allerta" -u "allerta" -a "allerta_pwd" -o "127.0.0.1" -r "DEV_ENV"; + php install.php populate -m "admin" -b -d -s "password" -w "owner" -e "mail@mailserver.local" -u $WORKSPACE_URL; cd ..; wget https://github.com/vrana/adminer/releases/download/v4.8.0/adminer-4.8.0.php; mv adminer-4.8.0.php adminer.php From 492e7f15a7c74a03b4eaa838e51204b226a68958 Mon Sep 17 00:00:00 2001 From: MatteoGheza Date: Tue, 16 Mar 2021 13:51:37 +0000 Subject: [PATCH 5/5] Fixes --- .gitpod.dockerfile | 6 ++++++ .gitpod.yml | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile index 2008184..b5d5fc9 100644 --- a/.gitpod.dockerfile +++ b/.gitpod.dockerfile @@ -3,3 +3,9 @@ FROM gitpod/workspace-mysql:latest ENV APACHE_DOCROOT_IN_REPO="server" + +USER root +RUN apt-get remove composer -y \ + && php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ + && php composer-setup.php --install-dir=/usr/local/bin --filename=composer +USER gitpod \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index 3885f3a..b207875 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -2,7 +2,7 @@ image: file: .gitpod.dockerfile ports: - port: 8001 - onOpen: open-preview + onOpen: ignore - port: 3306 onOpen: ignore tasks: @@ -32,12 +32,13 @@ tasks: mysqladmin reload; php install.php config -n "allerta" -u "allerta" -a "allerta_pwd" -o "127.0.0.1" -r "DEV_ENV"; php install.php populate -m "admin" -b -d -s "password" -w "owner" -e "mail@mailserver.local" -u $WORKSPACE_URL; + touch runInstall.php; + gp await-port 8001; gp preview "$(gp url 8001)"; cd ..; wget https://github.com/vrana/adminer/releases/download/v4.8.0/adminer-4.8.0.php; mv adminer-4.8.0.php adminer.php vscode: extensions: - gruntfuggly.todo-tree@0.0.205:sbsZJOTJzKZtMVHQuS2iPw== - - coenraads.bracket-pair-colorizer-2@0.1.4:+JUeb/jFYZt2/0MS/gUllA== - shelex.vscode-cy-helper@1.1.0:U9ok2y1bSmqn17OMuRMOfw== - hookyqr.beautify@1.4.11:n9DJEUFbYD/YHaBXxm+pYw== \ No newline at end of file