Skip to content

Commit

Permalink
chore(build): issues/339 local run linux updates (#340)
Browse files Browse the repository at this point in the history
* docs, contributing.md filled in gaps on getting started
* build, package.json npm scripts switched to bash
* build, dev.chrome.sh, expire check, recursive copy, dotenv write
* build, proxy.api.sh, expire check, separate darwin vs run.sh
  • Loading branch information
cdcabrera committed Jul 13, 2020
1 parent c08e9b9 commit 85e2faa
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 35 deletions.
36 changes: 35 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Before developing you'll need to install:
* [NodeJS and NPM](https://nodejs.org/)
* [Docker](https://docs.docker.com/engine/installation/)
* And [Yarn](https://yarnpkg.com)

### OS Support
A large percentage of front-end tooling is `Mac OSX` centered. The tooling for Curiosity is no exception, and is also `Mac OSX` focused.

While some aspects of the tooling have been expanded for Linux there may still be issues. It is encouraged that OS tooling
changes are contributed back while maintaining existing `Mac OSX` functionality.

If you are unable to test additional OS support it is imperative that code reviews take place before integrating/merging build changes.

### Docker & Mac
Setting Docker up on a Mac? Install the appropriate package and you should be good to go. To check if everything installed correctly you can try these steps.
Expand Down Expand Up @@ -263,7 +271,12 @@ If you're having trouble getting an accurate code coverage report, or it's faili
```

## Typical Development Workflow
After setting up the repository...
1. Confirm you've installed all recommended tooling
1. Confirm you've installed resources through yarn
1. Create a local dotenv file called `.env.local` and add the following contents
```
REACT_APP_DEBUG_MIDDLEWARE=true
```
1. Confirm you have access to the network
1. Make sure Docker is running
1. Open a couple of instances of Terminal and run...
Expand All @@ -276,3 +289,24 @@ After setting up the repository...
```
1. Make sure your browser opened around the domain `https://*.foo.redhat.com/`
1. Start developing...

### Local Run Development Workflow
1. Confirm you've installed all recommended tooling
1. Confirm you've installed resources through yarn
1. Create a local dotenv file called `.env.local` and add the following contents
```
REACT_APP_DEBUG_MIDDLEWARE=true
REACT_APP_DEBUG_ORG_ADMIN=true
REACT_APP_DEBUG_PERMISSION_RESOURCE=*
REACT_APP_DEBUG_PERMISSION_OPERATION=*
```
1. Open a couple of instances of Terminal and run...
```
$ yarn start
```
and, optionally,
```
$ yarn test:dev
```
1. Make sure your browser opened around the domain `https://localhost:3000/`
1. Start developing...
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
"scripts": {
"api:dev": "mock -p 5000 -w ./src/services",
"api:docs": "node ./scripts/openapi.docs.js",
"api:proxy-hosts": "sh ./scripts/proxy.api.sh -s",
"api:proxy": "sh ./scripts/proxy.api.sh -d \"https://ci.foo.redhat.com/beta/subscriptions/\" -p 443 -c \"$(pwd)/config/spandx.config.js\"",
"api:proxyClean": "sh ./scripts/proxy.api.sh -u",
"api:proxy-hosts": "bash ./scripts/proxy.api.sh -s",
"api:proxy": "bash ./scripts/proxy.api.sh -d \"https://ci.foo.redhat.com/beta/subscriptions/\" -p 443 -c \"$(pwd)/config/spandx.config.js\"",
"api:proxyClean": "bash ./scripts/proxy.api.sh -u",
"build": "run-s -l build:pre build:js build:post test:integration",
"build:js": "react-scripts build",
"build:post": "bash ./scripts/post.sh",
"build:pre": "bash ./scripts/pre.sh",
"dev:chrome": "sh ./scripts/dev.chrome.sh -b master",
"dev:chrome": "bash ./scripts/dev.chrome.sh -b master",
"release": "standard-version",
"start": "run-s dev:chrome; run-p -l api:dev start:js",
"start:js": "react-scripts start",
Expand Down
19 changes: 12 additions & 7 deletions scripts/dev.chrome.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ gitRepo()
rm -rf $DIR/temp
rm -rf $DIR_REPO/.git

echo $(date -v +10d "+%s") > $DIR/expire.txt
if [ "$(uname)" = "Darwin" ]; then
echo $(date -v +10d "+%s") > $DIR/expire.txt
else
echo $(date -d "+10 days" "+%s" ) > $DIR/expire.txt
fi

printf "${GREEN}SUCCESS${NOCOLOR}\n"

Expand Down Expand Up @@ -90,21 +94,22 @@ buildChrome()
printf "\n${YELLOW}Setting up local chrome ...${NOCOLOR}"

mkdir -p $DIR_PUBLIC
cp -R $DIR_REPO/build/ $DIR_PUBLIC
cp -R $DIR_REPO/build/* $DIR_PUBLIC

printf "${YELLOW}dotenv includes ...${NOCOLOR}"

HEADER_CONTENT_STR="require('fs').readFileSync('${SNIPPET_HEAD}').toString().replace(/\n/g, '').concat('<style>"
HEADER_CONTENT_STR+=".pf-c-page__sidebar * {display:none !important;}"
HEADER_CONTENT_STR+=".pf-m-user.pf-m-user-skeleton * {display:none;}"
HEADER_CONTENT_STR+=".pf-m-user.pf-m-user-skeleton:before {content:\"Development\";}"
HEADER_CONTENT_STR+="</style>')"
HEADER_CONTENT_STR="${HEADER_CONTENT_STR}.pf-c-page__sidebar * {display:none !important;}"
HEADER_CONTENT_STR="${HEADER_CONTENT_STR}.pf-m-user.pf-m-user-skeleton * {display:none;}"
HEADER_CONTENT_STR="${HEADER_CONTENT_STR}.pf-m-user.pf-m-user-skeleton:before {content:\"Development\";}"
HEADER_CONTENT_STR="${HEADER_CONTENT_STR}</style>')"

HEADER_CONTENT=$(node -pe "${HEADER_CONTENT_STR}")
BODY_CONTENT=$(node -pe "require('fs').readFileSync('${SNIPPET_BODY}').toString().replace(/\n/g,'')")

if [[ ! -z "$HEADER_CONTENT" ]] && [[ ! -z "$BODY_CONTENT" ]]; then
echo "\nREACT_APP_INCLUDE_CONTENT_HEADER=${HEADER_CONTENT}\nREACT_APP_INCLUDE_CONTENT_BODY=${BODY_CONTENT}\n" > ./.env.development.local
echo "REACT_APP_INCLUDE_CONTENT_HEADER=${HEADER_CONTENT}" > ./.env.development.local
echo "REACT_APP_INCLUDE_CONTENT_BODY=${BODY_CONTENT}" >> ./.env.development.local
printf "${GREEN}SUCCESS${NOCOLOR}\n\n"
else
printf "\n${RED}ERROR, include content doesn't exist${NOCOLOR}\n"
Expand Down
100 changes: 77 additions & 23 deletions scripts/proxy.api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ gitRepo()
rm -rf $DIR/temp
rm -rf $DIR_REPO/.git

echo $(date -v +10d "+%s") > $DIR/expire.txt
if [ "$(uname)" = "Darwin" ]; then
echo $(date -v +10d "+%s") > $DIR/expire.txt
else
echo $(date -d "+10 days" "+%s" ) > $DIR/expire.txt
fi

printf "${GREEN}SUCCESS${NOCOLOR}\n"

Expand Down Expand Up @@ -74,13 +78,16 @@ updateHosts()

printf "${YELLOW}Confirm hosts updated ...${NOCOLOR}"

if [ $(cat /private/etc/hosts | grep -c "redhat.com") -eq 4 ]; then
if [ $(cat /etc/hosts | grep -c "redhat.com") -ge 4 ]; then
printf "${GREEN}SUCCESS${NOCOLOR}\n\n"
else
printf "${RED}ERROR${NOCOLOR}\n"
printf "${RED}Updating hosts... you may need to \"allow write access\"...${NOCOLOR}\n"
sh $PROXYDIR_REPO/scripts/patch-etc-hosts.sh || sudo sh $PROXYDIR_REPO/scripts/patch-etc-hosts.sh

mkdir -p $PROXYDIR
echo "Hosts file updated $(date)" >> $PROXYDIR/hosts.txt

printf "${GREEN}Hosts file updated${NOCOLOR}\n\n"
fi
}
Expand Down Expand Up @@ -120,43 +127,83 @@ checkContainerRunning()
#
runProxy()
{
local RUN_CONTAINER=$1
local RUN_NAME=$2
local RUN_DOMAIN=$3
local RUN_PORT=$4
local RUN_CONFIG=$5
local DIR=$6
local DIR=$1
local RUN_CONTAINER=$2
local RUN_NAME=$3
local RUN_DOMAIN=$4
local RUN_PORT=$5
local RUN_CONFIG=$6
local PROXYDIR_REPO=$7
local CURRENT_DATE=$(date "+%s")
local EXPIRE=$(head -n 1 $DIR/expire-docker.txt)
local EXPIRE=$(head -n 1 $DIR/expireDocker.txt)

docker stop -t 0 $RUN_NAME >/dev/null

if [ -z "$(docker images -q $RUN_CONTAINER)" ] || [ "${EXPIRE:-0}" -lt "${CURRENT_DATE}" ]; then
printf "${YELLOW}Setting up development Docker proxy container...${NOCOLOR}\n"
docker pull $RUN_CONTAINER
echo $(date -v +10d "+%s") > $DIR/expire-docker.txt

mkdir -p $DIR

if [ "$(uname)" = "Darwin" ]; then
echo $(date -v +10d "+%s") > $DIR/expireDocker.txt
else
echo $(date -d "+10 days" "+%s" ) > $DIR/expireDocker.txt
fi
fi

if [ -z "$(docker ps | grep $RUN_CONTAINER)" ]; then
echo "Starting development proxy..."

if [ ! -z "$RUN_CONFIG" ]; then
RUN_CONFIG="-e CUSTOM_CONF=true -v ${RUN_CONFIG}:/config/spandx.config.js"
fi
if [ "$(uname)" = "Darwin" ]; then
if [ ! -z "$RUN_CONFIG" ]; then
RUN_CONFIG="-e CUSTOM_CONF=true -v ${RUN_CONFIG}:/config/spandx.config.js"
fi

docker run -d --rm -p $RUN_PORT:$RUN_PORT $RUN_CONFIG -e PLATFORM -e PORT -e LOCAL_API -e SPANDX_HOST -e SPANDX_PORT=$RUN_PORT --name $RUN_NAME $RUN_CONTAINER >/dev/null
fi
docker run -d --rm -p $RUN_PORT:$RUN_PORT $RUN_CONFIG -e PORT -e LOCAL_API -e SPANDX_HOST -e SPANDX_PORT=$RUN_PORT --name $RUN_NAME $RUN_CONTAINER >/dev/null

checkContainerRunning $RUN_NAME

if [ ! -z "$(docker ps | grep $RUN_CONTAINER)" ]; then
printf " ${YELLOW}Container: $(docker ps | grep $RUN_CONTAINER | cut -c 1-50)${NOCOLOR}\n"
echo " Development proxy running on ${RUN_PORT}: ${RUN_DOMAIN}"
printf " To stop: $ ${YELLOW}docker stop ${RUN_NAME}${NOCOLOR}\n"

open "${RUN_DOMAIN}"
fi

checkContainerRunning $RUN_NAME
exit 0
else
printf " ${YELLOW}This requires Python 2 to work correctly.${NOCOLOR}\n"
if [ "$(uname)" = "Linux" ]; then
xdg-open "${RUN_DOMAIN}"
fi

if [ ! -z "$(docker ps | grep $RUN_CONTAINER)" ]; then
printf " ${YELLOW}Container: $(docker ps | grep $RUN_CONTAINER | cut -c 1-50)${NOCOLOR}\n"
echo " Development proxy running on ${RUN_PORT}: ${RUN_DOMAIN}"
printf " To stop: $ ${YELLOW}docker stop ${RUN_NAME}${NOCOLOR}\n"
open "${RUN_DOMAIN}"
export SPANDX_PORT=$RUN_PORT
export SPANDX_CONFIG=$RUN_CONFIG
sh $PROXYDIR_REPO/scripts/run.sh
fi
fi
}
#
#
# Check docker permissions
#
sudoCheck()
{
local RUN_CONTAINER=$1
local RUN_NAME=$2
local RUN_DOMAIN=$3
local RUN_PORT=$4
local RUN_CONFIG=$5

CHECK=$(docker ps || 'SUDO REQUIRED::')

exit 0
if [ ! -z "$($CHECK | grep "SUDO REQUIRED:::")" ]; then
printf "\n${YELLOW}Container failed to setup, sudo required.${NOCOLOR}\n"
printf " ${YELLOW}Run the platform proxy script.${NOCOLOR}\n\n"
exit 0
fi
}
#
#
Expand Down Expand Up @@ -194,6 +241,13 @@ runProxy()
esac
done

if [ -z "$(docker -v)" ]; then
printf "\n${RED}Docker missing, confirm installation and running.${NOCOLOR}\n"
exit 1
fi

sudoCheck

if [ -z "$DOMAIN" ]; then
if (( $PORT % 2 )); then
DOMAIN="https://localhost:$PORT"
Expand All @@ -219,5 +273,5 @@ runProxy()
printf "${YELLOW}The proxy environment requires being able to access secure resources at runtime.${NOCOLOR}\n"

cleanLocalDotEnv
runProxy $CONTAINER $CONTAINER_NAME $DOMAIN $PORT $CONFIG $DATADIR
runProxy $DATADIR $CONTAINER $CONTAINER_NAME $DOMAIN $PORT $CONFIG $DATADIR_REPO
}

0 comments on commit 85e2faa

Please sign in to comment.