Skip to content

Commit

Permalink
🚀 RELEASE: Version 1.3.0 (#144)
Browse files Browse the repository at this point in the history
* 👌 IMPROVE: #138 Add -<port number> and --help options to op command

* 🤖 TEST: force docker

* 💡 UPDATE COMMENTS: fix inacurate info in the header

* ➕ ADD: download react typescript skeleton

* ➕ ADD: react typescript example

* 🐛 FIX: tar --overwrite

* 🐛 FIX: all zeros not working

* 🤖 TEST: run laravel mix to avoid saas warnings

* 🤖 TEST: remove previous test

* 🤖 TEST: disable typescript example init

* 🐛 FIX: temp workaround for third party saas bug: #140

* ✏️ FIX TYPO: sass not saas

* 🐛 FIX: workaround tthird party bug #140

* 🐛 FIX: workaround third party bug #140

* 🐛 FIX: workaround third party bug #140

* 🐛 FIX: #140

* 👌 IMPROVE: hotfix #140

* ✏️ FIX TYPO: 140 not 130

* 🐛 FIX: #141

* 🐛 FIX: #142

* ♻️ REFACTOR: improve all_zeros regexp

* 🐛 FIX: hard coded version bump for upcomming release

* 🐛 FIX: #142

* 🐛 FIX: #142

* 🤖 TEST: fix vue material dashboard example: reload after login triggers runtime error

* 🐛 FIX: restore code from previous test

* 🐛 FIX: #142

* 📖 DOC: #139 and #142
  • Loading branch information
apolopena committed May 22, 2021
1 parent 8059324 commit c1f9224
Show file tree
Hide file tree
Showing 15 changed files with 320 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,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=183
ENV INVALIDATE_CACHE=184

COPY --chown=gitpod:gitpod .gp/conf/apache/apache2.conf /etc/apache2/apache2.conf
COPY --chown=gitpod:gitpod .gp/conf/nginx/nginx.conf /etc/nginx/nginx.conf
Expand Down
4 changes: 2 additions & 2 deletions .gp/bash/.bash_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ alias lint-starter='f(){ bash "$GITPOD_REPO_ROOT"/.gp/bash/lint-scripts.sh "$1";
alias update-pma-pws='bash $GITPOD_REPO_ROOT/.gp/bash/change-passwords.sh phpmyadmin'
# Shows help for update_pma_pws
alias update-pma-pws-help='echo -e "$(cat "$GITPOD_REPO_ROOT/.gp/snippets/messages/update-pma-pws-help.txt")"'
# opens or refreshes the preview browser to the web root
alias op='f(){ bash "$GITPOD_REPO_ROOT"/.gp/bash/open-preview.sh "$1"; unset -f f; }; f'
# opens or refreshes the preview browser. Try op --help
alias op='f(){ bash "$GITPOD_REPO_ROOT"/.gp/bash/open-preview.sh "$@"; unset -f f; }; f'
2 changes: 1 addition & 1 deletion .gp/bash/change-passwords.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ phpmyadmin() {
local name="change-passwords.sh phpmyadmin"
local err="$name ERROR:"
local config_file="public/phpmyadmin/config.inc.php"
local all_zeros='^0$|^0*0$'
local all_zeros='^[0]+$'
local exit_codes
local values

Expand Down
110 changes: 110 additions & 0 deletions .gp/bash/examples/change-passwords.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
#
# SPDX-License-Identifier: MIT
# Copyright © 2021 Apolo Pena
#
# change-passwords.sh
# Description:
# Changes passwords for phpmyadmin from the defaults in version control to the values set in .starter.env
#
# Notes:
# This script should be always run at least once by the user as an mandatory additional layer of security
# This script requires the file .starter.env to exist along will all the key value pairs set.
#
# See:
# example.starter.ini

# Load spinner
. .gp/bash/spinner.sh

phpmyadmin() {
[ ! -d public/phpmyadmin ] && echo "No installation of phpmyadmin was found. Process aborted. " && exit 1
# Keep keys in sequence. Add new keys to the end of the array
local keys=(PHPMYADMIN_SUPERUSER_PW PHPMYADMIN_CONTROLUSER_PW)

local name="change-passwords.sh phpmyadmin"
local err="$name ERROR:"
local config_file="public/phpmyadmin/config.inc.php"
local all_zeros='^[0]+$'
local exit_codes
local values

for key in "${keys[@]}"; do
local value
value="$(bash .gp/bash/helpers.sh get_starter_env_val "$key")"
values+=("$(bash .gp/bash/helpers.sh get_starter_env_val "$key")")
local code=$?
exit_codes+=$code
# show error message of called function
[ $code != 0 ] && echo "$value"
done

if [[ ! $(echo "${exit_codes[@]}" | tr -d '[:space:]') =~ $all_zeros ]]; then
echo "$err retrieving values, no passwords were changed."
exit 1
fi

# Values have been set and there are no errors so far so change passwords
i=0
for key in "${keys[@]}"; do
case $key in
"${keys[0]}")
msg="Changing password for phpmyadmin user 'pmasu' to the value found in .starter.env"
start_spinner "$msg"
mysql -e "ALTER USER 'pmasu'@'%' IDENTIFIED BY '${values[$i]}'; FLUSH PRIVILEGES;"
stop_spinner $?
;;
"${keys[1]}")
msg="Changing password for phpmyadmin user 'pma' to the value found in .starter.env"
start_spinner "$msg"
mysql -e "ALTER USER 'pma'@'localhost' IDENTIFIED BY '${values[$i]}'; FLUSH PRIVILEGES;"
err_code=$?
stop_spinner $err_code
if [ $err_code == 0 ]; then
msg="Updating control user password in $config_file"
line="\$cfg['Servers'][\$i]['controlpass'] ="
_edit="\$cfg['Servers'][\$i]['controlpass'] = '${values[$i]}';"
start_spinner "$msg"
# The shellcheck SC2026 was not designed for awk so bypass it
# shellcheck disable=2026
# Match the line where the password for the controluser is set
line_num=$(awk '/^\$cfg.*'controlpass'.*=.*;$/ {print FNR}' $config_file)
if [ -z "$line_num" ]; then
stop_spinner 1
echo -e "ERROR: No line found beginning with: $line \n\tin the file: $config_file"
echo "You will need to manually update the control user password in $config_file"
else
sed -i "$line_num c\\$_edit" $config_file
err_code=$?
stop_spinner $err_code
unset _edit
[ $err_code == 0 ] &&
echo -e "\e[38;5;171mPROCESS COMPLETE\e[0m" &&
echo -e "\e[1;33mCheck the console output for any possible failures.\e[0m" &&
echo -en "\e[1;36m" &&
echo "If you are logged into phpmyadmin, log out and log back in." &&
echo "For additional security you can delete .starter.env" &&
echo "Just make sure you remember your passwords from that file." &&
echo "If you ever loose your passwords you may always set them again" &&
echo "using this script and new values set in .starter.env" &&
echo -e "\e[0m"
fi
fi
;;
*)
echo "$err unidentified key $value"
;;
esac
((i++))
done
}

# Call functions from this script gracefully
if declare -f "$1" > /dev/null
then
# call arguments verbatim
"$@"
else
echo "utils.sh: '$1' is not a known function name." >&2
exit 1
fi
14 changes: 4 additions & 10 deletions .gp/bash/examples/init-react-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@
. .gp/bash/workspace-init-logger.sh

declare -a exit_codes=()
all_zeros='^0$|^0*0$'
all_zeros='^[0]+$'
task_msg="Setting up React example: Questions and Answers"

log "$task_msg"
curl -LJO https://github.com/apolopena/QnA-demo-skeleton/archive/refs/tags/1.0.0.tar.gz
curl -LJO https://github.com/apolopena/qna-demo-skeleton/archive/refs/tags/1.1.0.tar.gz
exit_codes+=($?)
tar -xvzf QnA-demo-skeleton-1.0.0.tar.gz --strip-components=1
tar --overwrite -xvzf qna-demo-skeleton-1.1.0.tar.gz --strip-components=1
exit_codes+=($?)
rm QnA-demo-skeleton-1.0.0.tar.gz
exit_codes+=($?)
php artisan migrate
exit_codes+=($?)
php artisan db:seed
exit_codes+=($?)
yarn run mix
rm qna-demo-skeleton-1.1.0.tar.gz
exit_codes+=($?)

if [[ $(echo "${exit_codes[@]}" | tr -d '[:space:]') =~ $all_zeros ]]; then
Expand Down
33 changes: 33 additions & 0 deletions .gp/bash/examples/init-react-typescript-example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
#
# SPDX-License-Identifier: MIT
# Copyright © 2021 Apolo Pena
#
# init-react-typescript-example.sh
# Description:
# Initial setup for the gitpod-laravel-starter React Typescript example.

# Load logger
. .gp/bash/workspace-init-logger.sh

declare -a exit_codes=()

task_msg="Downloading React Typescript example: Questions and Answers"

log "$task_msg"
curl -LJO https://github.com/apolopena/qna-typescript-demo-skeleton/archive/refs/tags/1.1.0.tar.gz
exit_codes+=($?)
tar --overwrite -xvzf qna-typescript-demo-skeleton-1.1.0.tar.gz --strip-components=1
exit_codes+=($?)
rm qna-typescript-demo-skeleton-1.1.0.tar.gz
exit_codes+=($?)

if [[ $(echo "${exit_codes[@]}" | tr -d '[:space:]') =~ ^[0]+$ ]]; then
log "SUCCESS: $task_msg"
else
log -e "ERROR: $task_msg"
fi




42 changes: 12 additions & 30 deletions .gp/bash/examples/init-vue-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,21 @@
# SPDX-License-Identifier: MIT
# Copyright © 2021 Apolo Pena
#
# init-react-example.sh
# init-vue-example.sh
# Description:
# Initial setup for the gitpod-laravel-starter Vue example.

# Load logger
. .gp/bash/workspace-init-logger.sh

lvm=$(bash .gp/bash/helpers.sh laravel_major_version)
# Failsafe for unsupported versions
(( lvm < 6 )) && exit 1

declare -a exit_codes=()
all_zeros='^0$|^0*0$'
task_msg="Setting up Vue example: Material Dashboard"

log "$task_msg"

if (( lvm > 6 )); then
composer require laravel-frontend-presets/material-dashboard
else
composer require laravel-frontend-presets/material-dashboard v1.0.9
fi
exit_codes+=($?)
php artisan ui material
exit_codes+=($?)
composer dump-autoload
exit_codes+=($?)
php artisan migrate
exit_codes+=($?)
php artisan migrate --seed

if [[ $(echo "${exit_codes[@]}" | tr -d '[:space:]') =~ $all_zeros ]]; then
log "SUCCESS: $task_msg"
else
log -e "ERROR: $task_msg"
fi
main () {
local src="$GITPOD_REPO_ROOT"/.gp/snippets/projects/material-dashboard-example.sh
local dest="$GITPOD_REPO_ROOT"/.gp/bash/init-project.sh
if [[ -f $src ]]; then
cp -f "$src" "$dest"
else
log -e "ERROR: Preparing EXAMPLE $EXAMPLE, missing $src"
fi
}

main
4 changes: 2 additions & 2 deletions .gp/bash/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
gls_version() {
local hard version title file
hard="1.2.0"
hard="1.3.0"
title="Gitpod Laravel Starter Framework"
file="$GITPOD_REPO_ROOT"/.gp/CHANGELOG.md
if [[ -f $file ]]; then
Expand Down Expand Up @@ -320,7 +320,7 @@ has_installs() {
has_frontend_scaffolding_install() {
local result scaff_installs
result=$(get_installs | grep -oP '\d' | tr -d '[:space:]')
local all_zeros='^0$|^0*0$'
local all_zeros='^[0]+$'
# Trim the first character from the string (this is the phpmyadmin value)
local installs="${result:1}"
# Trim the next three characters in the string (there are only three possible front end scaffolding)
Expand Down
46 changes: 46 additions & 0 deletions .gp/bash/init-optional-scaffolding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@
# Load spinner
. .gp/bash/spinner.sh

# Workaround third party sass bug: https://github.com/apolopena/gitpod-laravel-starter/issues/140
hotfix140 () {
local exit_code msg="Applying hotfix 140"
log_silent "$msg..." && start_spinner "$msg"
yes | npx add-dependencies sass@1.32.12 --dev 2> >(grep -v warning 1>&2) > /dev/null 2>&1
exit_code=$?
if [[ $exit_code == 0 ]]; then
stop_spinner 0
log_silent "SUCCESS: $msg"
else
stop_spinner 1
log_silent -e "ERROR: $msg"
fi
}

parse="bash .gp/bash/utils.sh parse_ini_value starter.ini"

install_react=$(eval "$parse" react install)
Expand Down Expand Up @@ -49,6 +64,22 @@ if [[ -n $EXAMPLE ]]; then
install_react_router_dom=1
rrd_ver='^5.2.0'
;;
3)
example_title="React Typescript Example with phpMyAdmin - Questions and Answers"
init_react_typescript_example=".gp/bash/examples/init-react-typescript-example.sh"
install_react=1
install_phpmyadmin=1
install_react_router_dom=1
rrd_ver='^5.2.0'
;;
4)
example_title="React Typescript Example without phpMyAdmin - Questions and Answers"
init_react_typescript_example=".gp/bash/examples/init-react-typescript-example.sh"
install_react=1
install_phpmyadmin=0
install_react_router_dom=1
rrd_ver='^5.2.0'
;;
10)
example_title="Vue Example with phpMyAdmin and extras - Material Dashboard"
init_vue_example=".gp/bash/examples/init-vue-example.sh"
Expand Down Expand Up @@ -118,6 +149,7 @@ fi # end check laravel/ui already in vcs but needs composer install
# Cleanup (since we use yarn)
[ -f package-lock.json ] && rm package-lock.json
# END: Install Laravel ui if needed

# BEGIN: Optional react, react-dom and react-router-dom installs
if [ $install_react == 1 ]; then
version=$(eval "$parse" react version)
Expand Down Expand Up @@ -154,6 +186,7 @@ if [ $install_react == 1 ]; then
log -e "ERROR: $sub_msg"
fi
fi
hotfix140
log " --> Installing node modules and running Laravel Mix"
yarn install && npm run dev
npm run dev
Expand Down Expand Up @@ -187,6 +220,7 @@ if [[ $install_vue == 1 && $install_react != 1 ]]; then
fi
err_code=$?
if [[ $err_code == 0 ]]; then
hotfix140
log "SUCCESS: Vue$auth_msg has been installed"
log " --> Installing node modules and running Laravel Mix"
yarn install && npm run dev
Expand All @@ -212,6 +246,7 @@ if [[ $install_bootstrap == 1 && $install_react != 1 && $install_vue != 1 ]]; th
fi
err_code=$?
if [[ $err_code == 0 ]]; then
hotfix140
log "SUCCESS: Bootstrap$version_msg$auth_msg has been installed"
log " --> Installing node modules and running Laravel Mix"
yarn install && npm run dev
Expand All @@ -233,6 +268,7 @@ else
fi
# END: Optional bootstrap install
# END: optional frontend scaffolding installations

# BEGIN: optional example setup
# Initialize optional react example project
if [[ -n $init_react_example ]];then
Expand All @@ -244,6 +280,16 @@ if [[ -n $init_react_example ]];then
. "$init_react_example" 2>/dev/null || log_silent -e "ERROR: $(. $init_react_example 2>&1 1>/dev/null)"
exit
fi
# Initialize optional react typescript example project
if [[ -n $init_react_typescript_example ]];then
[[ $laravel_major_ver -ne 8 ]] \
&& log -e "WARNING: React examples are only supported by Laravel version 8. Your Laravel version is $laravel_major_ver" \
&& log -e "WARNING: Ignoring the example requested: $example_title" \
&& exit
# shellcheck source=.gp/bash/examples/init-react-example.sh
. "$init_react_typescript_example" 2>/dev/null || log_silent -e "ERROR: $(. $init_react_typescript_example 2>&1 1>/dev/null)"
exit
fi
# Initialize optional vue example project
if [[ -n $init_vue_example ]];then
# shellcheck source=.gp/bash/examples/init-vue-example.sh
Expand Down
2 changes: 1 addition & 1 deletion .gp/bash/init-phpmyadmin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
. .gp/bash/spinner.sh

# regexp pattern for checking an array of exit codes
all_zeros_reg='^0$|^0*0$'
all_zeros_reg='^[0]+$'

# BEGIN: Boostrap phpMyAdmin
# If the docker image has cached the directive to not install phpmyadmin, install it now.
Expand Down

0 comments on commit c1f9224

Please sign in to comment.