diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 43249bea..ffb149a8 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -24,7 +24,8 @@ RUN sudo touch /var/log/apache2/other_vhosts_access.log \ && sudo chmod 666 /var/log/apache2/other_vhosts_access.log RUN sudo apt-get update -q \ - && sudo apt-get install -y rsync + && sudo apt-get install -y rsync \ + && sudo apt-get install -y grc RUN wget http://xdebug.org/files/xdebug-3.0.2.tgz \ && tar -xvzf xdebug-3.0.2.tgz \ @@ -41,7 +42,7 @@ RUN sudo bash -c ". /tmp/update-composer.sh" && rm /tmp/update-composer.sh # gitpod trick to bypass the docker caching mechanism for all lines below this one # just increment the value each time you want to bypass the cache system -ENV INVALIDATE_CACHE=123 +ENV INVALIDATE_CACHE=125 COPY --chown=gitpod:gitpod bash/utils.sh /tmp COPY --chown=gitpod:gitpod starter.ini /tmp diff --git a/.gitpod.yml b/.gitpod.yml index 2ca1c442..8a533214 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -24,15 +24,18 @@ tasks: if [ $(bash bash/helpers.sh is_inited) == 1 ]; then \ gp sync-done gitpod-inited fi; + . bash/third-party/spinner.sh UP=$(pgrep mysql | wc -l); \ if [ "$UP" -ne 1 ]; then \ - . bash/third-party/spinner.sh && start_spinner "Initializing MySql..." && gp await-port 3306 && stop_spinner $?; \ fi && gp await-port 3306 && - sleep 1 && + __server=$(bash bash/utils.sh parse_ini_value starter.ini development default_server); \ + start_spinner "Starting $__server web server when system is ready..." && + gp sync-await gitpod-inited && + stop_spinner $? && bash -i bash/helpers.sh start_server name: Web Server - openMode: split-top diff --git a/bash/before-tasks.sh b/bash/before-tasks.sh index ea0d6876..3edc77f6 100644 --- a/bash/before-tasks.sh +++ b/bash/before-tasks.sh @@ -23,17 +23,38 @@ log_silent () { # Rake tasks (will be written to ~/.rake). # Some rake tasks are dynamic and depend on the configuration in starter.ini -msg="Writing rake tasks" -log "$msg" && -bash bash/init-rake-tasks.sh +if [ "$(bash bash/utils.sh parse_ini_value starter.ini github-changelog-generator install)" ]; then + msg="Writing rake tasks" + log "$msg..." && + bash bash/init-rake-tasks.sh + if [ $? == 0 ]; then + log "SUCCESS: $msg" + else + log "ERROR: $msg" -e + fi +fi + # Aliases for git -msg="Writing git aliases" -log "$msg" && +msg="\ngit aliases have been written" bash bash/utils.sh add_file_to_file_after \\[alias\\] bash/snippets/emoji-log ~/.gitconfig && -bash bash/utils.sh add_file_to_file_after \\[alias\\] bash/snippets/git-aliases ~/.gitconfig -log "try: git a or: git aliases for a list your git aliases.\n" +bash bash/utils.sh add_file_to_file_after \\[alias\\] bash/snippets/git-aliases ~/.gitconfig && +log "$msg" && +log "\ntry: git a or: git aliases\nto see what is available.\n" + +# grc color configuration for apache logs +msg="Creating grc color configuration file for apache logs: ~/apache-log-colors.conf" +log "$msg..." && +cat bash/snippets/grc/apache-log-colors > ~/apache-log-colors.conf +if [ $? == 0 ]; then + log "SUCCESS: $msg" +else + log "ERROR: $msg" -e +fi +# Keep this at the bottom of the file +# Restores files marked as persistant +# See persist_file in bash/helpers.sh if [ $(bash bash/helpers.sh is_inited) == 1 ]; then bash bash/helpers.sh restore_persistent_files $GITPOD_REPO_ROOT fi \ No newline at end of file diff --git a/bash/init-gitpod.sh b/bash/init-gitpod.sh index 91c15fa9..98ac842f 100644 --- a/bash/init-gitpod.sh +++ b/bash/init-gitpod.sh @@ -30,18 +30,18 @@ stop_spinner $? # Move Laravel project files if they are not already in version control if [ ! -d "$GITPOD_REPO_ROOT/vendor" ]; then - msg="\nMoving Laravel project from ~/temp-app to $GITPOD_REPO_ROOT using rsync" + msg="\nrsync Laravel project from ~/temp-app to $GITPOD_REPO_ROOT" # TODO: replace spinner with a real progress bar for coreutils - log_silent "$msg" && start_spinner "$msg" + log_silent "$msg..." && start_spinner "$msg..." shopt -s dotglob rsync -rlptgoD --ignore-existing ~/test-app/ $GITPOD_REPO_ROOT err_code=$? if [ $err_code != 0 ]; then stop_spinner $err_code - log "ERROR: Failed to move Laravel project from ~/temp-app to $GITPOD_REPO_ROOT using rsync" -e + log "ERROR: Failed to rsync Laravel project from ~/temp-app to $GITPOD_REPO_ROOT" -e else stop_spinner $err_code - log "SUCCESS: moved Laravel project from ~/temp-app to $GITPOD_REPO_ROOT using rsync" + log "SUCCESS: rsync Laravel project from ~/temp-app to $GITPOD_REPO_ROOT" fi # BEGIN: parse configurations @@ -71,7 +71,7 @@ if [ ! -d "$GITPOD_REPO_ROOT/vendor" ]; then __laravel_db_exists=$(mysqlshow 2>/dev/null | grep laravel >/dev/null 2>&1 && echo "1" || echo "0") if [ $__laravel_db_exists == 0 ]; then __laravel_db_msg="laravel database did not exist in mysql. Creating database: laravel" - log_silent "$__laravel_db_msg" && start_spinner "$__laravel_db_msg" + log_silent "$__laravel_db_msg..." && start_spinner "$__laravel_db_msg..." mysql -e "CREATE DATABASE laravel;" err_code=$? if [ $err_code != 0 ]; then diff --git a/bash/init-rake-tasks.sh b/bash/init-rake-tasks.sh index 964ba6f6..9ee22417 100644 --- a/bash/init-rake-tasks.sh +++ b/bash/init-rake-tasks.sh @@ -30,12 +30,12 @@ EOF } # END: dynamic rake task functions -# BEGIN: conditionally add dynamic rake tasks -if [ "$(eval $parse github-changelog-generator install)" ]; then +# BEGIN: add rake tasks add_changelog_rake - [ $? != 0 ] && exit 1 -fi -# END: conditionally add dynamic rake tasks + if [ $? != 0 ]; then + exit 1 + fi +# END: add rake tasks diff --git a/bash/snippets/grc/apache-log-colors b/bash/snippets/grc/apache-log-colors new file mode 100644 index 00000000..fa31b2c7 --- /dev/null +++ b/bash/snippets/grc/apache-log-colors @@ -0,0 +1,41 @@ +# grc config file for apache log colors + +# ip number +regexp=^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} +colours=bold magenta +count=once +- +# everything in brackets +regexp=\[.+?\] +colours=cyan +count=once +- +# everything in "" +regexp=\".+?\" +colours=blue +count=more +- +# HTTP Method +regexp=(?:HEAD|GET|POST|PUT|DELETE) +colours=bold blue +count=once +- +# HTTP Path +regexp=\s/[^\s]+ +colours=bold green +count=once +- +# HTTP OK Status codes +regexp=\s(?:10[01]|20[02467]|30[0123457]) +colours=green +count=once +- +# HTTP Error status code +regexp=\s(?:40[1-9]|41[1-8]|42[2-9]|431|444|450|50[2-9]|599) +colours=bold red +count=once +- +# Request byte size +regexp=\s(?!(?:10[01]|20[02467]|30[0123457])|(?:40[1-9]|41[1-8]|42[2-9]|431|444|450|50[2-9]|599))\d+ +colours=yellow +count=once \ No newline at end of file diff --git a/bash/snippets/server-functions b/bash/snippets/server-functions index 5931dc21..b5d1ba99 100644 --- a/bash/snippets/server-functions +++ b/bash/snippets/server-functions @@ -1,19 +1,49 @@ -mtail_apache () { +mtail_apache() { multitail /var/log/apache2/access.log -I /var/log/apache2/error.log; } +tail_apache() { + # See bash/before-tasks.sh for setup of ~/apache-log-colors.conf + grc -c /home/gitpod/apache-log-colors.conf tail -f /var/log/apache2/access.log /var/log/apache2/error.log +} + start_apache() { apachectl start (( $? == 0 )) || return - mtail_apache + local log_monitor_type="$(bash \ + $GITPOD_REPO_ROOT/bash/utils.sh parse_ini_value starter.ini development apache_log_monitor)" + case "$log_monitor_type" in + 'tail') + tail_apache + ;; + 'multitail') + mtail_apache + ;; + *) + echo "ERROR start_apache: invalid apache_log_monitor type: $log_monitor_type. Check your starter.ini" + ;; + esac } stop_apache() { apachectl stop (( $? == 0 )) || return local pid - # The grep string here must match the command given in the function start_apache - pid=$(ps axf | grep 'multitail /var/log/apache2/access.log -I /var/log/apache2/error.log' | grep -v grep | awk '{print $1}' | sed 1q) + local log_monitor_type="$(bash \ + $GITPOD_REPO_ROOT/bash/utils.sh parse_ini_value starter.ini development apache_log_monitor)" + case "$log_monitor_type" in + 'tail') + # The grep string here must match the tail portion of the command given in the function start_apache + pid=$(ps axf | grep 'tail -f /var/log/apache2/access.log /var/log/apache2/error.log' | grep -v grep | awk '{print $1}' | sed 1q) + ;; + 'multitail') + # The grep string here must match the command given in the function start_apache + pid=$(ps axf | grep 'multitail /var/log/apache2/access.log -I /var/log/apache2/error.log' | grep -v grep | awk '{print $1}' | sed 1q) + ;; + *) + echo "ERROR start_apache: invalid apache_log_monitor type: $log_monitor_type. Check your starter.ini" + ;; + esac kill -2 $pid } diff --git a/starter.ini b/starter.ini index c48e0d4a..2ea7c9cf 100644 --- a/starter.ini +++ b/starter.ini @@ -10,6 +10,8 @@ [development] # Valid values: apache, php default_server=apache +# Valid values are tail (uses grc) and multitail +apache_log_monitor=multitail [.editorconfig] # valid values are: