Skip to content

Commit

Permalink
Merge pull request #3 from apolopena/development-rsync
Browse files Browse the repository at this point in the history
Development gitpod rsync, gitpod timing, gitpod conditional scaffolding, and QnA project fixes
  • Loading branch information
apolopena authored Mar 3, 2021
2 parents 6413f53 + 021b8c0 commit fc2636e
Show file tree
Hide file tree
Showing 15 changed files with 929 additions and 588 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ indent_size = 4
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
indent_size = 2
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ yarn-error.log
/public/js
/public/css
/public/build
/public/mix-manifest.json
/public/mix-manifest.json
50 changes: 31 additions & 19 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,47 @@ FROM gitpod/workspace-mysql

USER gitpod

# 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=131

RUN sudo touch /var/log/workspace-image.log \
&& sudo chmod 666 /var/log/workspace-image.log
&& sudo chmod 666 /var/log/workspace-image.log

RUN sudo touch /var/log/workspace-init.log \
&& sudo chmod 666 /var/log/workspace-init.log
&& sudo chmod 666 /var/log/workspace-init.log

RUN sudo touch /var/log/xdebug.log \
&& sudo chmod 666 /var/log/xdebug.log
&& sudo chmod 666 /var/log/xdebug.log

RUN sudo mkdir /var/log/apache2 \
&& sudo chmod 755 /var/log/apache2

RUN sudo touch /var/log/apache2/access.log \
&& sudo chmod 666 /var/log/apache2/access.log

RUN sudo touch /var/log/apache2/error.log \
&& sudo chmod 666 /var/log/apache2/error.log

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 php-dev
&& sudo apt-get install -y rsync

RUN wget http://xdebug.org/files/xdebug-3.0.2.tgz \
&& tar -xvzf xdebug-3.0.2.tgz \
&& cd xdebug-3.0.2 \
&& phpize \
&& ./configure --enable-xdebug \
&& make \
&& sudo cp modules/xdebug.so /usr/lib/php/20190902/xdebug.so \
&& sudo bash -c "echo -e '\nzend_extension = /usr/lib/php/20190902/xdebug.so\n[XDebug]\nxdebug.client_host = 127.0.0.1\nxdebug.client_port = 9009\nxdebug.log = /var/log/xdebug.log\nxdebug.mode = debug\nxdebug.start_with_request = trigger\n' >> /etc/php/7.4/cli/php.ini" \
&& sudo bash -c "echo -e '\nzend_extension = /usr/lib/php/20190902/xdebug.so\n[XDebug]\nxdebug.client_host = 127.0.0.1\nxdebug.client_port = 9009\nxdebug.log = /var/log/xdebug.log\nxdebug.mode = debug\nxdebug.start_with_request = trigger\n' >> /etc/php/7.4/apache2/php.ini"
&& tar -xvzf xdebug-3.0.2.tgz \
&& cd xdebug-3.0.2 \
&& phpize \
&& ./configure --enable-xdebug \
&& make \
&& sudo cp modules/xdebug.so /usr/lib/php/20190902/xdebug.so \
&& sudo bash -c "echo -e '\nzend_extension = /usr/lib/php/20190902/xdebug.so\n[XDebug]\nxdebug.client_host = 127.0.0.1\nxdebug.client_port = 9009\nxdebug.log = /var/log/xdebug.log\nxdebug.mode = debug\nxdebug.start_with_request = trigger\n' >> /etc/php/7.4/cli/php.ini" \
&& sudo bash -c "echo -e '\nzend_extension = /usr/lib/php/20190902/xdebug.so\n[XDebug]\nxdebug.client_host = 127.0.0.1\nxdebug.client_port = 9009\nxdebug.log = /var/log/xdebug.log\nxdebug.mode = debug\nxdebug.start_with_request = trigger\n' >> /etc/php/7.4/apache2/php.ini"

COPY --chown=gitpod:gitpod bash/update-composer.sh /tmp
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=121

COPY --chown=gitpod:gitpod bash/utils.sh /tmp
COPY --chown=gitpod:gitpod starter.ini /tmp
COPY --chown=gitpod:gitpod bash/scaffold-project.sh /tmp
Expand All @@ -40,6 +52,6 @@ RUN sudo bash -c ". /tmp/scaffold-project.sh" && rm /tmp/scaffold-project.sh
COPY --chown=gitpod:gitpod bash/snippets/server-functions /tmp
COPY --chown=gitpod:gitpod bash/snippets/browser-functions /tmp
RUN echo "# BEGIN: custom code (not internal to gitpod)" \
&& cat /tmp/server-functions >> ~/.bashrc \
&& echo -e "\n" | cat /tmp/browser-functions >> ~/.bashrc \
&& echo "# END: custom code (not internal to gitpod)"
&& cat /tmp/server-functions >> ~/.bashrc \
&& echo -e "\n" | cat /tmp/browser-functions >> ~/.bashrc \
&& echo "# END: custom code (not internal to gitpod)"
13 changes: 11 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
image:
file: .gitpod.Dockerfile

ports:
- port: 8001
onOpen: ignore
Expand All @@ -16,10 +16,14 @@ tasks:
init: |
bash bash/init-gitpod.sh &&
bash bash/init-optional-scaffolding.sh &&
bash bash/init-project.sh &&
bash bash/init-complete.sh
name: Startup
- openMode: split-left
command: |
if [ $(bash bash/helpers.sh is_inited) == 1 ]; then \
gp sync-done gitpod-inited
fi;
UP=$(pgrep mysql | wc -l); \
if [ "$UP" -ne 1 ]; then \
. bash/third-party/spinner.sh &&
Expand All @@ -33,7 +37,12 @@ tasks:
name: Web Server
- openMode: split-top
command: |
default_server=$(bash bash/utils.sh parse_ini_value starter.ini development default_server); open_preview $default_server
. bash/third-party/spinner.sh &&
start_spinner "Opening preview when system is ready..."
gp sync-await gitpod-inited &&
default_server=$(bash bash/utils.sh parse_ini_value starter.ini development default_server); \
open_preview $default_server &&
stop_spinner $?
name: Main Terminal

vscode:
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ class Answer extends Model
'description',
'question_id'
];

public function question()
{
return $this->belongsTo(Question::class);
}
}
5 changes: 3 additions & 2 deletions bash/init-complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ echo -e "\e[38;5;194mIf everything looks good in the above results then push the
# Persist the workspace-init.log since the .gitpod.Dockerfile will wipe it out and it wont come back after the first run
bash bash/helpers.sh persist_file /var/log/workspace-init.log

# Set initialized flag - Keep this at the bottom of the file
bash bash/helpers.sh mark_as_inited
# Keep this code in sequence and at the bottom of this file
bash bash/helpers.sh mark_as_inited
gp sync-done gitpod-inited
63 changes: 54 additions & 9 deletions bash/init-gitpod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ start_spinner "Initializing MySql..." &&
gp await-port 3306 &&
stop_spinner $?

# Bootstrap scaffolding
if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
msg="\nMoving Laravel project from ~/temp-app to $GITPOD_REPO_ROOT"
# BEGIN: Bootstrap Laravel scaffolding

# 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"
# TODO: replace spinner with a real progress bar for coreutils
log_silent "$msg" && start_spinner "$msg"
shopt -s dotglob
mv --no-clobber ~/test-app/* $GITPOD_REPO_ROOT
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" -e
log "ERROR: Failed to move Laravel project from ~/temp-app to $GITPOD_REPO_ROOT using rsync" -e
else
stop_spinner $err_code
log "SUCCESS: moved Laravel project from ~/temp-app to $GITPOD_REPO_ROOT"
log "SUCCESS: moved Laravel project from ~/temp-app to $GITPOD_REPO_ROOT using rsync"
fi

# BEGIN: parse configurations
Expand All @@ -64,6 +66,34 @@ if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
[ -e .env ] && url=$(gp url 8000); sed -i'' "s#^APP_URL=http://localhost*#APP_URL=$url\nASSET_URL=$url#g" .env
# END: parse configurations

# Create laravel database if it does not exist
# TODO: think more about making this dynamic as per .env
__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"
mysql -e "CREATE DATABASE laravel;"
err_code=$?
if [ $err_code != 0 ]; then
stop_spinner $err_code
log "ERROR: Failed to move createe mysql database: laravel" -e
else
stop_spinner $err_code
log "SUCCESS: created mysql database: laravel"
fi
fi
# Install node packages if needed, in case the Laravel Ui front end is already in version control
if [[ -f "package.json" && ! -d "node_modules" ]]; then
log "Found a package.json but there are no node modules installed"
log " --> Assume that there is Laravel ui frontend scaffolding already installed"
log " --> Installing node packages..."
yarn install
log " --> Node packages installed"
log " --> Running Laravel Mix..."
yarn run dev
log " --> Running Laravel Mix complete"
fi

# BEGIN: Optional configurations
# Super user account for phpmyadmin
installed_phpmyadmin=$(. bash/utils.sh parse_ini_value starter.ini phpmyadmin install)
Expand All @@ -79,6 +109,20 @@ if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
else
stop_spinner $err_code
fi
if [ ! -d 'public/phpmyadmin/node_modules' ]; then
log "phpmyadmin node modules have not yet been installed, installing now..."
cd public/phpmyadmin && yarn install && cd ../../
if [ $? == 0 ]; then
__pmaurl=$(gp url 8001)/phpmyadmin
log "phpmyadmin node modules installed."
log "To login to phpmyadmin:"
log " --> 1. Make sure you are serving it with apache"
log " --> 2. In the browser go to $__pmaurl"
log " --> 3. You should be able to login here using the default account. user: pmasu, pw: 123456"
else
log "ERROR: installing phpmyadmin node modules. Try installing them manually." -e
fi
fi
fi
# Install https://github.com/github-changelog-generator/github-changelog-generator
installed_changelog_gen=$(bash bash/utils.sh parse_ini_value starter.ini github-changelog-generator install)
Expand All @@ -90,11 +134,12 @@ if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
fi
# END: Optional configurations

# Move and or merge necessary failes then cleanup
(echo; cat ~/test-app/.gitignore) >> $GITPOD_REPO_ROOT/.gitignore && rm ~/test-app/.gitignore
# Move and merge necessary files, then cleanup
#(echo; cat ~/test-app/.gitignore) >> $GITPOD_REPO_ROOT/.gitignore && rm ~/test-app/.gitignore
mv ~/test-app/README.md $GITPOD_REPO_ROOT/README_LARAVEL.md
rmdir ~/test-app
rm -rf ~/test-app
fi
# END: Bootstrap Laravel scaffolding

# Messages for github_changelog_generator
[ "$installed_changelog_gen" == 1 ] &&
Expand Down
108 changes: 65 additions & 43 deletions bash/init-optional-scaffolding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@ install_bootstrap=$(eval $parse bootstrap install)
# BEGIN: Install Laravel ui if needed
if [[ $install_react == 1 || $install_bootstrap == 1 ]]; then
log "Optional installations that require laravel/ui scaffolding were found"
log "Installing laravel/ui scaffolding"
composer require laravel/ui:^3.2.0
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: laravel/ui scaffolding installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev

# Assume we are using composer 2, check if the laravel/ui package has already been installed
composer show | grep laravel/ui >/dev/null && __ui=1 || __ui=0

if [ "$__ui" == 1 ]; then
log "However it appears that laravel/ui has already been installed, skipping this installation."
else
log "ERROR $err_code: There was a problem installing laravel/ui" -e
log "Installing laravel/ui scaffolding"
composer require laravel/ui:^3.2.0
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: laravel/ui scaffolding installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev
else
log "ERROR $err_code: There was a problem installing laravel/ui" -e
fi
fi
fi
# END: Install Laravel ui if needed
Expand All @@ -48,29 +56,34 @@ fi
if [ "$install_react" == 1 ]; then
version=$(eval $parse react version)
auth=$(eval $parse react auth)
__installed=$(bash bash/utils.sh node_package_exists react)
[ -z "$version" ] && version_msg='' || version_msg=" version $version"
[ "$auth" != 1 ] && auth_msg='' || auth_msg=' with --auth'
log "React/React DOM install directive found in starter.ini"
log "Installing React and React DOM"
if [ "$auth" == 1 ]; then
php artisan ui react --auth
if [ "$__installed" == 1 ]; then
log "However it appears that React/React DOM has already been installed, skipping this installation."
else
php artisan ui react
fi
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: React and React DOM$version_msg$auth_msg has been installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev && sleep 1 && yarn run dev
if [ ! -z "$version" ]; then
log "Setting react and react-dom to$version_msg"
# TODO: validate semver and valid version for the package so users cant pass in junk
yarn upgrade react@$version react-dom@$version
log "Installing React and React DOM"
if [ "$auth" == 1 ]; then
php artisan ui react --auth
else
php artisan ui react
fi
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: React and React DOM$version_msg$auth_msg have been installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev && sleep 1 && yarn run dev
if [ ! -z "$version" ]; then
log "Setting react and react-dom to$version_msg"
# TODO: validate semver and valid version for the package so users cant pass in junk
yarn upgrade react@$version react-dom@$version
fi
[ "$install_bootstrap" == 1 ] && log "Bootstrap install directive found but ignored. Already installed"
[ "$install_vue" == 1 ] && log "Vue install directive found but ignored. The install of react superceded this"
else
log "ERROR $err_code: There was a problem installing React/React DOM$version_msg$auth_msg" -e
fi
[ "$install_bootstrap" == 1 ] && log "Bootstrap install directive found but ignored. Already installed"
[ "$install_vue" == 1 ] && log "Vue install directive found but ignored. The install of react superceded this"
else
log "ERROR $err_code: There was a problem installing React/React DOM$version_msg$auth_msg" -e
fi
fi
# END: Optional react and react-dom install
Expand All @@ -79,32 +92,41 @@ fi
if [[ "$install_vue" == 1 && "$install_react" == 0 ]]; then
version=$(eval $parse vue version)
auth=$(eval $parse vue auth)
__installed=$(bash bash/utils.sh node_package_exists vue)
[ -z "$version" ] && version_msg='' || version_msg=" version $version"
[ "$auth" != 1 ] && auth_msg='' || auth_msg=' with --auth'
log "Vue install directive found in starter.ini"
log "Installing Vue..."
if [ "$auth" == 1 ]; then
php artisan ui vue --auth
if [ "$__installed" == 1 ]; then
log "However it appears that Vue has already been installed, skipping this installation."
else
php artisan ui vue
fi
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: Vue$version_msg$auth_msg has been installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev && sleep 1 && yarn run dev
if [ ! -z "$version" ]; then
log "Setting vue to$version_msg"
# TODO: validate semver and valid version for the package so users cant pass in junk
yarn upgrade vue@$version
log "Installing Vue..."
if [ "$auth" == 1 ]; then
php artisan ui vue --auth
else
php artisan ui vue
fi
err_code=$?
if [ $err_code == 0 ]; then
log "SUCCESS: Vue$version_msg$auth_msg has been installed"
log "Compiling fresh scaffolding and running Laravel Mix"
yarn install && yarn run dev && sleep 1 && yarn run dev
if [ ! -z "$version" ]; then
log "Setting vue to$version_msg"
# TODO: validate semver and valid version for the package so users cant pass in junk
yarn upgrade vue@$version
fi
[ "$install_bootstrap" == 1 ] && log "Bootstrap install directive found but ignored. Already installed."
else
log "ERROR $err_code: There was a problem installing Vue$version_msg$auth_msg" -e
fi
[ "$install_bootstrap" == 1 ] && log "Bootstrap install directive found but ignored. Already installed."
else
log "ERROR $err_code: There was a problem installing Vue$version_msg$auth_msg" -e
fi
fi
# END: Optional vue install

# TODO: test bootstrap install without any detection for an existing install.
# If nothing is affected like app.js then install wont need to be skipped.
# otherwise implement the same fix for existing installs that we have for react and vue.

# BEGIN: Optional bootstrap install
if [[ $install_bootstrap == 1 && $install_react == 0 && $install_vue == 0 ]]; then
version=$(eval $parse bootstrap version)
Expand Down
Loading

0 comments on commit fc2636e

Please sign in to comment.