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

Environment Sync, Dev to Test (CI/QA-beta to CI/QA-stable) PF4 requested updates #334

Merged
merged 11 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ REACT_APP_SERVICES_RHSM_VERSION=/api/rhsm-subscriptions/v1/version
REACT_APP_SERVICES_RHSM_REPORT=/api/rhsm-subscriptions/v1/tally/products/
REACT_APP_SERVICES_RHSM_CAPACITY=/api/rhsm-subscriptions/v1/capacity/products/
REACT_APP_SERVICES_RHSM_INVENTORY=/api/rhsm-subscriptions/v1/hosts/products/
REACT_APP_SERVICES_RHSM_INVENTORY_GUESTS=/api/rhsm-subscriptions/v1/hosts/{0}/guests
REACT_APP_SERVICES_RHSM_OPTIN=/api/rhsm-subscriptions/v1/opt-in
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ REACT_APP_SERVICES_RHSM_VERSION=http://localhost:5000/api/rhsm-subscriptions/v1/
REACT_APP_SERVICES_RHSM_REPORT=http://localhost:5000/api/rhsm-subscriptions/v1/tally/products/
REACT_APP_SERVICES_RHSM_CAPACITY=http://localhost:5000/api/rhsm-subscriptions/v1/capacity/products/
REACT_APP_SERVICES_RHSM_INVENTORY=http://localhost:5000/api/rhsm-subscriptions/v1/hosts/products/
REACT_APP_SERVICES_RHSM_INVENTORY_GUESTS=//localhost:5000/api/rhsm-subscriptions/v1/hosts/{0}/guests
REACT_APP_SERVICES_RHSM_OPTIN=http://localhost:5000/api/rhsm-subscriptions/v1/opt-in
1 change: 1 addition & 0 deletions .env.proxy
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ REACT_APP_SERVICES_RHSM_VERSION=/api/rhsm-subscriptions/v1/version
REACT_APP_SERVICES_RHSM_REPORT=/api/rhsm-subscriptions/v1/tally/products/
REACT_APP_SERVICES_RHSM_CAPACITY=/api/rhsm-subscriptions/v1/capacity/products/
REACT_APP_SERVICES_RHSM_INVENTORY=/api/rhsm-subscriptions/v1/hosts/products/
REACT_APP_SERVICES_RHSM_INVENTORY_GUESTS=/api/rhsm-subscriptions/v1/hosts/{0}/guests
REACT_APP_SERVICES_RHSM_OPTIN=/api/rhsm-subscriptions/v1/opt-in
49 changes: 48 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 @@ -192,6 +200,19 @@ Once you have made the dotenv file and/or changes, like the below "debug" flags,

*Any changes you make to the `.env.local` file should be ignored with `.gitignore`.*


##### Local CSS/Styling display vs Environments
The default context for starting the local development run with
```
$ yarn start
```
Comes with a caveat, it uses the [Platform Chrome](https://github.com/RedHatInsights/insights-chrome) CI/master branch as its basis. What
this means is that potential styling changes will affect it, or not depending on recent updates. If styling is looking odd/off, or you
simply want to use the production styling update the NPM script branch parameter, line 63. Simply change `master` to something like `prod-stable`.
```
"dev:chrome": "sh ./scripts/dev.chrome.sh -b master"
```

##### Graph display
You can apply a date override during **local development** (using `$ yarn start`) by adding the following line to your `.env.local` file.
```
Expand Down Expand Up @@ -250,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 @@ -263,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...
32 changes: 16 additions & 16 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",
"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 All @@ -76,15 +76,15 @@
"test:local": "react-scripts test --env=jsdom --roots=./src"
},
"dependencies": {
"@patternfly/patternfly": "2.71.6",
"@patternfly/react-charts": "5.3.19",
"@patternfly/react-core": "3.153.13",
"@patternfly/react-icons": "3.15.16",
"@patternfly/react-styles": "3.7.13",
"@patternfly/react-tokens": "2.8.13",
"@redhat-cloud-services/frontend-components": "1.0.24",
"@redhat-cloud-services/frontend-components-notifications": "1.0.3",
"@redhat-cloud-services/frontend-components-utilities": "1.0.3",
"@patternfly/patternfly": "4.16.7",
"@patternfly/react-charts": "6.5.4",
"@patternfly/react-core": "4.23.1",
"@patternfly/react-icons": "4.4.2",
"@patternfly/react-styles": "4.4.2",
"@patternfly/react-tokens": "4.5.2",
"@redhat-cloud-services/frontend-components": "2.1.3",
"@redhat-cloud-services/frontend-components-notifications": "2.1.1",
"@redhat-cloud-services/frontend-components-utilities": "2.1.0",
"axios": "^0.19.2",
"c3": "^0.7.15",
"classnames": "^2.2.6",
Expand All @@ -108,9 +108,9 @@
"redux-promise-middleware": "^6.1.2",
"redux-thunk": "^2.3.0",
"reselect": "^4.0.0",
"victory": "^34.3.11",
"victory-core": "^34.3.8",
"victory-legend": "^34.3.8"
"victory": "^34.3.12",
"victory-core": "^34.3.12",
"victory-legend": "^34.3.12"
},
"devDependencies": {
"apidoc-mock": "^3.0.2",
Expand Down
10 changes: 0 additions & 10 deletions public/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@
"tourTitleImageAlt": "Ready to get started example graph.",
"tourDescription": "We'll walk you through each step, and include insight into how Red Hat collects and uses subscription data."
},
"curiosity-tour": {
"emptyStateIconAlt": "{{appName}} logo",
"emptyStateTitle": "{{appName}} is an early access beta",
"emptyStateDescription": "{{appName}} helps you understand your total subscription usage and capacity over time.",
"emptyStateDescriptionTour": "Take a quick tour to learn more.",
"emptyStateDescriptionExtended": "If you are interested in trying {{appName}}, your Red Hat account team can help.",
"emptyStateButton": "Take a tour",
"emptyStateLinkLearnMore": "Learn more",
"emptyStateLinkContactUs": "Contact us"
},
"curiosity-view": {
"openshift": "Red Hat OpenShift",
"rhel": "Red Hat Enterprise Linux"
Expand Down
24 changes: 18 additions & 6 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,15 +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=$(node -pe "require('fs').readFileSync('${SNIPPET_HEAD}').toString().replace(/\n/g, '').concat('<style>.pf-c-page__sidebar .ins-c-skeleton,.pf-c-page__sidebar .ins-c-navigation__header{display:none}</style>')")
BODY_CONTENT=$(node -pe "require('fs').readFileSync('${SNIPPET_BODY}').toString().replace(/\n/g,'').replace(/Logging in\.\.\./i, 'Development')")
HEADER_CONTENT_STR="require('fs').readFileSync('${SNIPPET_HEAD}').toString().replace(/\n/g, '').concat('<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 All @@ -125,9 +136,10 @@ buildChrome()
HEAD=./public/apps/chrome/snippets/head.html
BODY=./public/apps/chrome/snippets/body.html

while getopts u option;
while getopts b:u option;
do
case $option in
b ) BRANCH="$OPTARG";;
u ) UPDATE=true;;
esac
done
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
}
2 changes: 1 addition & 1 deletion src/components/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { NotificationsPortal } from '@redhat-cloud-services/frontend-components-notifications';
import { NotificationsPortal } from '@redhat-cloud-services/frontend-components-notifications/cjs';
import { connectRouter, reduxActions } from '../redux';
import { helpers } from '../common/helpers';
import { I18n } from './i18n/i18n';
Expand Down
Loading