Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features #31 and #32, Fixes #30 #33

Merged
merged 71 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
e739c14
🤖 TEST: test before command
apolopena Feb 7, 2021
880c42e
🤖 TEST: test before command
apolopena Feb 7, 2021
69acc88
🤖 TEST: approach to fixing https://github.com/apolopena/gitpod-larave…
apolopena Feb 7, 2021
8b62a5e
🤖 TEST: fix 30
apolopena Feb 7, 2021
a54dce4
🤖 TEST: fix 30
apolopena Feb 7, 2021
73bafa3
🐛 FIX: persistent rake tasks #30
apolopena Feb 7, 2021
06a8bcc
🤖 TEST: finiky
apolopena Feb 7, 2021
1329e29
Format: added a linebreak
apolopena Feb 7, 2021
2c72f05
🐛 FIX: dialing in https://github.com/apolopena/gitpod-laravel8-starte…
apolopena Feb 7, 2021
3bc52db
🐛 FIX: before-tasks.sh
apolopena Feb 7, 2021
2d3b7e2
🐛 FIX: before-tasks.sh
apolopena Feb 7, 2021
64048b2
🐛 FIX: before-tasks.sh
apolopena Feb 7, 2021
136393e
🤖 TEST: culprit spinner
apolopena Feb 7, 2021
654b4e3
🤖 TEST: persistance hack
apolopena Feb 7, 2021
1279b12
🤖 TEST: persistance hack
apolopena Feb 7, 2021
4a2ed78
🐛 FIX: persistant init flag for the project
apolopena Feb 8, 2021
ea507d6
🤖 TEST: persisting log files
apolopena Feb 8, 2021
d2469bc
🐛 FIX: typo line 131
apolopena Feb 8, 2021
adafb75
🤖 TEST: file persistance
apolopena Feb 8, 2021
9935531
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
519dab4
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
231d06d
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
42de1bb
🐛 FIX: type
apolopena Feb 8, 2021
d4da83f
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
d477a97
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
cfe86b6
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
9e97c9e
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
c354481
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
df1aae0
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
ce00fa4
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
459cc54
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
39c532a
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
26a83b4
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
e52a398
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
6e57411
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
9e164c6
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
5424cd1
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
b7b6e33
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
ccbd682
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
f0dbb67
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
f370226
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
769765f
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
8effd64
🤖 TEST: are GITPOD envs ready in the before phase?
apolopena Feb 8, 2021
1557b3e
🤖 TEST: are GITPOD envs ready in the before phase?
apolopena Feb 8, 2021
bca5734
🤖 TEST: are GITPOD envs ready in the before phase?
apolopena Feb 8, 2021
0b2b5d8
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
09358d7
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
741b81f
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
18515e1
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
c0b5641
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
0b59563
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
d01029f
🤖 TEST: file persistance for image-init.log
apolopena Feb 8, 2021
67b2288
🐛 FIX: file persistance hack works! removing sudo
apolopena Feb 8, 2021
36034ae
🐛 FIX: remove traces
apolopena Feb 8, 2021
8077a4b
🤖 TEST: trying it all with loging to the now persistent init log from…
apolopena Feb 8, 2021
9a019d1
👌 IMPROVE: it all works, commands that log to init log will write in …
apolopena Feb 8, 2021
1e88150
🐛 FIX: persistant to persistent
apolopena Feb 8, 2021
3d1caeb
🐛 FIX: linebreak
apolopena Feb 8, 2021
6025b55
🐛 FIX: refactor gitpod init sequence
apolopena Feb 8, 2021
f3f7816
📖 DOC: comments
apolopena Feb 8, 2021
e680439
🐛 FIX: typo in init command
apolopena Feb 8, 2021
089f33d
🐛 FIX: typo in init command
apolopena Feb 8, 2021
3403934
🐛 FIX: fine tuning
apolopena Feb 8, 2021
903a861
🐛 FIX: mtail_apache function
apolopena Feb 8, 2021
f61e6b6
🤖 TEST: force workspace image build
apolopena Feb 8, 2021
ffd0475
🐛 FIX: improve readability
apolopena Feb 8, 2021
48505f8
🐛 FIX: improve readability
apolopena Feb 8, 2021
459da2d
👌 IMPROVE: Pretty results of initialization https://github.com/apolop…
apolopena Feb 8, 2021
9942376
👌 IMPROVE: Pretty results of initialization https://github.com/apolop…
apolopena Feb 8, 2021
d85d090
📖 DOC: formatting
apolopena Feb 8, 2021
54a970a
📖 DOC: log writing rake tasks
apolopena Feb 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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=120
ENV INVALIDATE_CACHE=121

COPY --chown=gitpod:gitpod bash/utils.sh /tmp
COPY --chown=gitpod:gitpod starter.ini /tmp
Expand Down
23 changes: 12 additions & 11 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ ports:
onOpen: ignore

tasks:
- init: |
. bash/third-party/spinner.sh &&
start_spinner "Initializing MySql..." &&
gp await-port 3306 &&
stop_spinner $? &&
- before: bash bash/before-tasks.sh
init: |
bash bash/init-gitpod.sh &&
source ~/.bash_profile &&
url=$(gp url 8000); sed -i'' "s#^APP_URL=http://localhost*#APP_URL=$url\nASSET_URL=$url#g" .env &&
bash bash/init-optional-scaffolding.sh &&
bash bash/init-complete.sh
name: Init
name: Startup
- openMode: split-left
command: |
bash bash/clear-term.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
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.5 &&
sleep 1 &&
bash -i bash/helpers.sh start_server
name: Web Server
- openMode: split-left
- openMode: split-top
command: |
default_server=$(bash bash/utils.sh parse_ini_value starter.ini development default_server); open_preview $default_server
name: Main Terminal
Expand Down
39 changes: 39 additions & 0 deletions bash/before-tasks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Gitpod currently does not persist files in the home directory so we must write them
# in everytime the workspace starts. We do this in the -before task in .gitpod.yml

# Log to the console and a file
log () {
if [ -z "$2" ]; then
bash bash/utils.sh log "$1" /var/log/workspace-init.log
else
bash bash/utils.sh log "$1" /var/log/workspace-init.log -e
fi
}

# Log only to a file
log_silent () {
if [ -z "$2" ]; then
bash bash/utils.sh log_silent "$1" /var/log/workspace-init.log
else
bash bash/utils.sh log_silent "$1" /var/log/workspace-init.log -e
fi
}

# 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

# Aliases for git
msg="Writing git aliases"
log "$msg" &&
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"

if [ $(bash bash/helpers.sh is_inited) == 1 ]; then
bash bash/helpers.sh restore_persistent_files $GITPOD_REPO_ROOT
fi
66 changes: 66 additions & 0 deletions bash/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,72 @@ add_global_rake_task() {
echo -e "$1" > "$root/$file"
}

# show_first_run_logs
# Description:
# Outputs a summarized and colorized dump of /var/log/workspace-image.log
# and /var/log/workspace-init.log
#
# Usage:
# show_first_run_summary
show_first_run_summary() {
workspace_log='/var/log/workspace-image.log'
init_log='/var/log/workspace-init.log'
echo -e "\n\e[38;5;171mSUMMARY 👀\e[0m\n"
echo -en "\e[38;5;194mResults of building the workspace image\e[0m \e[38;5;34m$workspace_log\e[0m ➥\n\e[38;5;183m"
cat $workspace_log
echo -en "\e[0m"
echo ''
echo -en "\e[38;5;194mResults of the gitpod initialization\e[0m \e[38;5;34m$init_log\e[0m ➥\e[38;5;39m"
echo ''
cat $init_log
echo -en "\e[0m"
echo -en "\n\e[38;5;171mALL DONE 🚀\e[0m\n"
}

# Begin: persistance hacks
get_store_root() {
echo "/workspace/$(basename $GITPOD_REPO_ROOT)--store"
}

persist_file() {
local err="helpers.sh: persist: error:"
local store=$(get_store_root)
local dest="$store/$(dirname ${1#/})"
local file="$dest/$(basename "$1")"
mkdir -p $store && mkdir -p $dest
[ -f $1 ] && cp $1 $file || echo "$err $1 does not exist"
}

# For some reason $GITPOD_REPO_ROOT is not avaialable when this is called (from before task)
# So just pass it in from there as $1
restore_persistent_files() {
local err="helpers.sh: restore_persistent_files: error:"
# TODO make this dynamic
local init_log_orig=/var/log/workspace-init.log
local store="/workspace/$(basename $1)--store"
local init_log="$store$init_log_orig"
[ -e $init_log ] && cp $init_log $init_log_orig || echo "$err $init_log NOT FOUND"
}

inited_file () {
echo "$(get_store_root)/is_inited.lock"
}

mark_as_inited() {
local file=$(inited_file)
local store=$(get_store_root)
mkdir -p $(get_store_root)
[ ! -e $file ] && touch $file
}

is_inited() {
[ -e $(inited_file) ] && echo 1 || echo 0
}
# End: persistance hacks




# Call functions from this script gracefully
if declare -f "$1" > /dev/null
then
Expand Down
23 changes: 11 additions & 12 deletions bash/init-complete.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash

workspace_log='/var/log/workspace-image.log'
init_log='/var/log/workspace-init.log'
echo -e "\n\e[38;5;171mSUMMARY 📃\e[0m\n"
echo -en "\e[38;5;194mResults of building the workspace image\e[0m \e[38;5;34m$workspace_log\e[0m ➥\n\e[38;5;183m"
cat $workspace_log
echo -en "\e[0m"
echo ''
echo -en "\e[38;5;194mResults of the gitpod initialization\e[0m \e[38;5;34m$init_log\e[0m ➥\e[38;5;39m"
cat $init_log
echo -en "\e[0m"
echo -en "\n\e[38;5;171mALL DONE 🚀\e[0m\n"
echo -e "\e[38;5;194mIf everything looks good in the above results then push the newly created\n project files to your git repo and get started coding your project\e[0m"
# Note: always call this file last from the init command in .gitpod.yml

# Summarize results
bash bash/helpers.sh show_first_run_summary
echo -e "\e[38;5;194mIf everything looks good in the above results then push the newly created\n project files to your git repo and get started coding your project\e[0m"

# 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
26 changes: 10 additions & 16 deletions bash/init-gitpod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ log_silent () {
fi
}


# Load spinner
. bash/third-party/spinner.sh

# Let the user know there will a wait, then begin once MySql is initialized.
start_spinner "Initializing MySql..." &&
gp await-port 3306 &&
stop_spinner $?

# Bootstrap scaffolding
if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
# Todo replacespinner with a real progress bar for coreutils
msg="\nMoving 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"
shopt -s dotglob
mv --no-clobber ~/test-app/* $GITPOD_REPO_ROOT
Expand All @@ -37,9 +41,11 @@ if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
stop_spinner $err_code
log "SUCCESS: moved Laravel project from ~/temp-app to $GITPOD_REPO_ROOT"
fi
# configure Laravel to use gitpod urls
[ -e .env ] && url=$(gp url 8000); sed -i'' "s#^APP_URL=http://localhost*#APP_URL=$url\nASSET_URL=$url#g" .env
# BEGIN: Optional configurations
# Super user account for phpmyadmin
installed_phpmyadmin=$(. /tmp/utils.sh parse_ini_value /tmp/starter.ini phpmyadmin install)
installed_phpmyadmin=$(. bash/utils.sh parse_ini_value starter.ini phpmyadmin install)
if [ "$installed_phpmyadmin" == 1 ]; then
msg="Creating phpmyadmin superuser: pmasu"
log_silent "$msg" && start_spinner "$msg"
Expand Down Expand Up @@ -69,20 +75,8 @@ if [ ! -d "$GITPOD_REPO_ROOT/bootstrap" ]; then
rmdir ~/test-app
fi

# Rake tasks (will be written to ~/.rake).
# Some rake tasks are dynamic and depend on the configuration in starter.ini
bash bash/init-rake-tasks.sh

# Aliases for git
msg="Writing git aliases"
log_silent "$msg" && start_spinner "$msg" &&
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 &&
stop_spinner $?
log "try: git a or: git aliases for a list your git aliases.\n"

# Messages for github_changelog_generator
[ "$installed_changelog_gen" == 1 ] &&
log "You may auto generate a CHANGELOG.md from github commits by running the command:\nrake changelog [...options]\n" &&
log "See starter.ini (github_changelog_generator section) for configurable options" &&
log "For a full list of options see the github-changelog-generator repository on github"
log "For a full list of options see the github-changelog-generator repository on github"
2 changes: 2 additions & 0 deletions bash/init-rake-tasks.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

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

# BEGIN: dynamic rake task functions
add_changelog_rake() {
local rake='changelog'
Expand Down Expand Up @@ -32,6 +33,7 @@ EOF
# BEGIN: conditionally add dynamic rake tasks
if [ "$(eval $parse github-changelog-generator install)" ]; then
add_changelog_rake
[ $? != 0 ] && exit 1
fi
# END: conditionally add dynamic rake tasks

Expand Down
6 changes: 5 additions & 1 deletion bash/snippets/server-functions
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
mtail_apache () {
multitail /var/log/apache2/access.log -I /var/log/apache2/error.log;
}

start_apache() {
apachectl start
(( $? == 0 )) || return
multitail /var/log/apache2/access.log -I /var/log/apache2/error.log;
mtail_apache
}

stop_apache() {
Expand Down