-
-
Save grimen/6858545 to your computer and use it in GitHub Desktop.
Automaticall generate unique/predicatable/consistent $PORT for each project based on fingerprinting of `.powder` and make Pow Proxy aware of it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# custom ENV variables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo "[.powenv]: PORT: $PORT" | |
echo "[.powenv]: project path: $(pwd)" | |
# Detect ".env" file path. | |
if [ -z $ENV_FILE ] | |
then ENV_FILE="./.env" | |
fi | |
echo "[.powenv]: project .env: $ENV_FILE" | |
# Load ".env" file. | |
if [ -f $ENV_FILE ] | |
then source $ENV_FILE | |
fi | |
# Detect unique project file to generate default PORT based on. | |
for project_id_file in "./.powder" "./package.json" | |
do | |
if [ -f "$project_id_file" ] | |
then | |
PROJECT_ID_FILE=$project_id_file | |
break | |
fi | |
done | |
echo "[.powenv]: project .env PORT: $PORT" | |
# Generate default PORT for this project. | |
if [ -f $PROJECT_ID_FILE ] | |
then | |
# PROJECT_BODY=`cat $PROJECT_ID_FILE | grep -v '^$'` | |
PROJECT_MD5=`cat $PROJECT_ID_FILE | grep -v '^$' | md5sum | cut -f1 -d" "` | |
PROJECT_NUMBER=`echo $(( 0x${PROJECT_MD5%% *} )) | cut -f2 -d"-"` &>/dev/null | |
PROJECT_PORT_RANGE_FROM=3000 | |
PROJECT_PORT_RANGE_TO=9999 | |
PROJECT_PORT_DEFAULT=`expr $PROJECT_PORT_RANGE_FROM + $PROJECT_NUMBER % $(expr $PROJECT_PORT_RANGE_TO - $PROJECT_PORT_RANGE_FROM)` | |
PROJECT_PORT_OVERRIDE=0 | |
echo "[.powenv]: project ID FILE: $PROJECT_ID_FILE" | |
# echo "[.powenv]: project ID BODY: $PROJECT_BODY" | |
echo "[.powenv]: project ID MD5: $PROJECT_MD5" | |
echo "[.powenv]: project ID NUMBER: $PROJECT_NUMBER" | |
if [ $PROJECT_PORT_OVERRIDE -gt 0 ] | |
then | |
echo "[.powenv]: override PORT: $PORT => $PROJECT_PORT_DEFAULT" | |
PORT=$PROJECT_PORT_DEFAULT | |
else | |
if [ -z $PORT ] | |
then | |
echo "[.powenv]: undefined PORT: $PORT => $PROJECT_PORT_DEFAULT" | |
PORT=$PROJECT_PORT_DEFAULT | |
else | |
echo "[.powenv]: defined PORT: $PORT" | |
fi | |
fi | |
fi | |
# Pow environment. | |
export POW_PROXY_HOST=localhost | |
export POW_PROXY_PORT=$PORT | |
# Log | |
echo "[.powenv]: PROJECT_PORT_DEFAULT: $PROJECT_PORT_DEFAULT" | |
echo "[.powenv]: POW_PROXY_HOST: $POW_PROXY_HOST" | |
echo "[.powenv]: POW_PROXY_PORT: $POW_PROXY_PORT" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ -f "$rvm_path/scripts/rvm" ] && [ -f ".rvmrc" ]; then | |
source "$rvm_path/scripts/rvm" | |
source ".rvmrc" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
rvm use 1.9.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
source 'https://rubygems.org' | |
# https://github.com/Rodreegez/powder | |
gem 'powder' | |
# See: https://github.com/spagalloco/pow_proxy | |
gem 'pow_proxy' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: clean install proxy | |
install: | |
make clean \ | |
&& npm install \ | |
&& ./node_modules/bower/bin/bower install \ | |
&& gem install bundler \ | |
&& bundle install \ | |
&& powder link | |
update: | |
npm update \ | |
&& ./node_modules/bower/bin/bower update | |
&& bundle update | |
clean: | |
if [ -e ./node_modules ]; then rm -rf ./node_modules; fi \ | |
&& if [ -e ./.sass-cache ]; then rm -rf ./.sass-cache; fi \ | |
&& if [ -e ./.tmp ]; then rm -rf ./.tmp; fi \ | |
&& if [ -e ./app/components ]; then rm -rf ./app/components; fi \ | |
&& if [ -e ./dist ]; then rm -rf ./dist; fi \ | |
&& if [ -e ./tmp ]; then rm -rf ./tmp; fi | |
server: | |
grunt server | |
build: | |
grunt build | |
open: | |
powder open | |
static: | |
make pow-static | |
proxy: | |
make pow-proxy \ | |
&& make server | |
pow-static: | |
if [ -e ./public ]; then rm -f ./public; fi \ | |
&& if [ ! -d ./dist ]; then mkdir ./dist; fi \ | |
&& ln -sf ./dist ./public \ | |
&& if [ ! -f ./public/index.html ]; then echo "$(PWD)/public/index.html" > ./public/index.html; fi \ | |
&& if [ -e ./config.ru ]; then rm -f ./config.ru; fi \ | |
&& tree -LC 1 \ | |
&& powder restart | |
pow-proxy: | |
if [ -e ./public ]; then rm -f ./public; fi \ | |
&& if [ -f ./config.ru ]; then rm -f ./config.ru; fi \ | |
&& if [ ! -e ./config.ru ]; then ln -sf ./.config.ru ./config.ru; fi \ | |
&& source ./.powenv \ | |
&& if [ ! -e ./.env ]; then touch ./.env; fi \ | |
&& sed -e 's/PORT\=.*//g' ./.env > ./.env.old \ | |
&& echo "PORT=$$POW_PROXY_PORT" > ./.env.new \ | |
&& cat ./.env.old >> ./.env.new \ | |
&& cat ./.env.new | grep -v '^$$' > ./.env \ | |
&& rm ./.env.* \ | |
&& tree -LC 1 \ | |
&& powder restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment