diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 00000000..09e84248 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,64 @@ +tasks: + - name: Initialize Backend + init: | + docker pull fauna/faunadb:4.15.0 & + docker pull eventyay/open-event-server:master & + docker pull postgis/postgis:12-3.0-alpine & + docker pull redis:3-alpine + command: | + cd gitpod-scripts + gp sync-await Dependencies_Check && sh startCloudDevBackend.sh + gp sync-done Initialization_of_Backend + cd .. + exit + - name: Initialize Next.js App + init: | + cd app + npm i + cd .. + command: | + gp sync-await Dependencies_Check && gp sync-done Initialization_of_NextJS_Packages + exit + + - name: Initialize Strapi App + init: | + cd cms + npm i + npm run build + cd .. + command: gp sync-await Dependencies_Check && sh gitpod-scripts/startCloudDevStrapi.sh + + - name: Start build + command: | + printf "⚑️ Please wait while we're initializing these tasks for you... ⚑️\n" + gp tasks list + printf "\n" + cd gitpod-scripts + sh startCloudDevEnv.sh + +ports: + - port: 3000 + visibility : public + onOpen: open-preview + name: RC4Conferences + description: Next.js app for RC4Conferences + - port: 1337 + onOpen: notify + name: Strapi + description: Strapi Dashboard + - port: 8084 + onOpen: ignore + - port: 8444 + onOpen: ignore + - port: 8443 + onOpen: ignore + +github: + prebuilds: + master: true + branches: true + pullRequests: true + pullRequestsFromForks: true + addCheck: true + addComment: true + addBadge: true diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..0c878f12 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "workbench.startupEditor": "none" +} diff --git a/README.md b/README.md index cf32b937..15831ccc 100644 --- a/README.md +++ b/README.md @@ -32,16 +32,32 @@ Got questions? Or want to discuss any idea for the project, feel free to drop by # Instant Setup ~1.5 minutes To try out the project within minutes, run the following two bash commands, and you will be good to go: +Gitpod Setup + +Well...there's no setup needed here, we've taken care of setting everything up so that you can directly work on the code while we push the configuration πŸ˜‰ + +Start developing and make changes to your code via a single click **Anytime-Anywhere**! + +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/RocketChat/RC4Conferences) + +__Well wait..what is Gitpod πŸ€”?__ + +[Gitpod](https://www.gitpod.io/docs/introduction/getting-started) is an Open Source Cloud Developer Environment, it's basically a pre-configured dev environment which we've setup for you! + +You can open RC4Conferences in Gitpod and work on [any IDE](https://www.gitpod.io/docs/references/ides-and-editors) of your choice ✨ + +Some *Recommendations* while using **Gitpod**: + +- Download the [gitpod browser extension](https://www.gitpod.io/docs/configure/user-settings/browser-extension) to start working on any branch, issue or PR via a single click in under a minute! +- To enjoy *BLAZINGLY FAST* startup times while developing on your forked branches, consider [enabling prebuilds by setting up a Project with your forked repository as a "Project"](https://www.gitpod.io/docs/configure/projects/prebuilds/#projects-and-prebuilds) + +--- Local Setup ```bash sh startdevenv.sh localhost sh startNext.sh localhost ``` -Gitpod Setup -```bash -sh startdevenv.sh localhost -sh startNextGp.sh localhost -``` + _Note: Please replace the "localhost" (127.0.0.1) with your static IP if you are doing environment setup on your VM. For e.g. `173.456.1.19`_ Now you can try out the following: diff --git a/app/components/menubar.js b/app/components/menubar.js index 1e356185..dea70ec4 100644 --- a/app/components/menubar.js +++ b/app/components/menubar.js @@ -31,7 +31,7 @@ export default function Menubar(props) { process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID && process.env.NEXT_PUBLIC_RC_URL; - if (!hasAllRequiredCreds) console.log("RC4Community is now using a dummy Auth Component! If you wish to use a robust Auth component, provide all the credentials first (https://github.com/RocketChat/RC4Community/tree/master/app/components/auth)") + if (!hasAllRequiredCreds) console.log("RC4Conferences is now using a dummy Auth Component! If you wish to use a robust Auth component, provide all the credentials first (https://github.com/RocketChat/RC4Community/tree/master/app/components/auth)") return ( @@ -105,7 +105,7 @@ export default function Menubar(props) { - RC4Community Profile + RC4Conferences Profile Profile diff --git a/app/package.json b/app/package.json index 71defb74..a26d888a 100644 --- a/app/package.json +++ b/app/package.json @@ -1,5 +1,5 @@ { - "name": "rc4community", + "name": "rc4conferences", "version": "0.3.0", "private": true, "scripts": { diff --git a/gitpod-scripts/startCloudContainers.sh b/gitpod-scripts/startCloudContainers.sh new file mode 100644 index 00000000..5d1fb203 --- /dev/null +++ b/gitpod-scripts/startCloudContainers.sh @@ -0,0 +1,39 @@ +#!/bin/sh +ERR_FILE=open-event-server/log/err_log.txt +INIT_DB=open-event-server/seed/init_db + +echo "--Starting the Open Event server--" +cd ../open-event-server +sh startOes.sh $1 $2 + +echo "--Starting Superprofile Backend--" +cd ../superprofile +sh initFaunaOnce.sh $1 $2 +cd ../gitpod-scripts + +OES_CONTAINER_ID=$( docker ps -q -f name=opev-web ) +FAUNA_CONTAINER_ID=$( docker ps -q -f name=faunadb ) + +if [ -s $ERR_FILE ];then + echo "\033[31m***Some error occurred while starting the Open Event Server please check open-event-server/$ERR_FILE , resolve them, and then re-run the init command***\e[0m" + exit 1 +fi +if [ -z $OES_CONTAINER_ID ]; then + echo "\033[31m***Open-event-server Docker container was unable to install and start, please rerun the script***\e[0m" + exit 1 +else + cd ../open-event-server + docker exec -it opev-postgres /bin/sh /var/log/seed/seed.sh + cd .. + if [ ! -e $INIT_DB ];then + echo "\033[31m***Open-event-server DB was not seeded with demo event, please check pg logs***\e[0m" + exit 1 + else + echo "--Successfully seeded the database with demo data--" + fi +fi +if [ -z $FAUNA_CONTAINER_ID ]; then + echo $FAUNA_CONTAINER_ID + echo "\033[31m***FaunaDB container was unable to install and start, please rerun the script***\e[0m" + exit 1 +fi diff --git a/gitpod-scripts/startCloudDevBackend.sh b/gitpod-scripts/startCloudDevBackend.sh new file mode 100644 index 00000000..31592dee --- /dev/null +++ b/gitpod-scripts/startCloudDevBackend.sh @@ -0,0 +1,15 @@ +#!/bin/sh +watchtimer=0 + +sh startCloudContainers.sh $1 $2 + +while [ $? -ne 0 ] && [ $watchtimer -lt 5 ] +do + watchtimer=$((watchtimer+1)) + sh startCloudContainers.sh $1 $2 +done + +if [ $? -eq 1 ];then + echo "\033[31m***Unable to successfully launch the superprofile or open-event-server container, please view the logs for more info and resolve&rerun the script***\e[0m" + exit 1 +fi diff --git a/gitpod-scripts/startCloudDevEnv.sh b/gitpod-scripts/startCloudDevEnv.sh new file mode 100644 index 00000000..5c1f5d2b --- /dev/null +++ b/gitpod-scripts/startCloudDevEnv.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +trap_ctrlc () +{ + # perform cleanup here + echo "--performing clean up--" + chmod +x cleanup.sh + ls + sh cleanup.sh + + # exit shell script with error code 2 + # if omitted, shell script will continue execution + exit 2 +} + +# initialise trap to call trap_ctrlc function +# when signal 2 (SIGINT) is received +trap "trap_ctrlc" 2 + +version() { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } + +echo "--Verifying the pre-requisites in the environment--" + +if ! which node > /dev/null; then + echo "\033[31m***NodeJS is not installed, please install and try again\e[31m" + exit 1 +fi + +if ! which npm > /dev/null; then + echo "\033[31m***npm is not installed, please install and try again\e[31m" + exit 1 +fi + +echo "--Checking Node version--" +NODE_VER=$( node -v | cut -c 2-9 ) +if [ $(version $NODE_VER) -ge $(version "16.0.0") ]; then + echo "***Node version is up to date" +else + echo "\033[31m***NodeJS version >= 16 is required for the application to work\e[31m" + exit 1 +fi + +gp sync-done Dependencies_Check + +sh startCloudNext.sh \ No newline at end of file diff --git a/gitpod-scripts/startCloudDevStrapi.sh b/gitpod-scripts/startCloudDevStrapi.sh new file mode 100644 index 00000000..39fc6d2d --- /dev/null +++ b/gitpod-scripts/startCloudDevStrapi.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +counter=0 +STRAPI_PORT=1337 +watchdog=5 + +DOMAIN="localhost" +if [ ! -z "$1" ]; then DOMAIN="$1"; fi + +check_and_set_strapi_port() { + if lsof -Pi :$STRAPI_PORT -sTCP:LISTEN -t >/dev/null && [ "$counter" -lt $watchdog ]; then + echo "Strapi port $STRAPI_PORT already occupied, changing to the next consecutive port" + STRAPI_PORT=$((STRAPI_PORT+1)) + counter=$((counter+1)) + check_and_set_strapi_port + elif [ "$counter" -ge $watchdog ]; then + echo "\033[31m Unable to allocate an empty port for Strapi, the last tried port was $STRAPI_PORT\e[0m" + echo "Please either change the $STRAPI_PORT to an other random number or to an unused port number" + exit 1 + else + echo "πŸš€ An empty port found for StrapiπŸš€" + fi +} + +check_and_set_strapi_port + +printf '\nNEXT_PUBLIC_STRAPI_API_URL'="http://$DOMAIN:$STRAPI_PORT" >> app/.env +printf '\nNEXT_PUBLIC_EVENT_SPK_MAIL'="dhgysfmedomihkzkwv@kvhrr.com" >> app/.env +printf '\nNEXT_PUBLIC_EVENT_ANON_MAIL'="anon@pikapii.com" >> app/.env + +cd cms +export PORT=$STRAPI_PORT +INITIALIZE_DATA=true npm run develop \ No newline at end of file diff --git a/startNextGp.sh b/gitpod-scripts/startCloudNext.sh similarity index 70% rename from startNextGp.sh rename to gitpod-scripts/startCloudNext.sh index 040586c6..9b3c7f3f 100644 --- a/startNextGp.sh +++ b/gitpod-scripts/startCloudNext.sh @@ -1,4 +1,13 @@ +#!/bin/sh + NEXTJS_PORT=3000 +counter=0 +watchdog=5 + +DOMAIN="localhost" +if [ ! -z "$1" ]; then DOMAIN="$1"; fi + +cd .. check_and_set_next_port() { if lsof -Pi :$NEXTJS_PORT -sTCP:LISTEN -t >/dev/null && [ "$counter" -lt $watchdog ]; then @@ -12,21 +21,26 @@ check_and_set_next_port() { echo "After changes re-run the script" exit 1 else - echo "πŸš€ An empty port found for NextJS πŸš€" + printf "πŸš€ An empty port found for NextJS πŸš€ \n" fi } + check_and_set_next_port + +gp ports await 1337 +gp sync-await Initialization_of_Backend && + export NEXT_PUBLIC_API_URL=$(gp url 3000) export NEXT_PUBLIC_FAUNA_DOMAIN=$(gp url 8084)/graphql gp ports visibility 8084:public export NEXT_PUBLIC_EVENT_BACKEND_URL=$(gp url 8080) gp ports visibility 8080:public - - export NEXT_PUBLIC_PORT=$NEXTJS_PORT printf '\nNEXT_PUBLIC_API_URL'="http://$1:$NEXTJS_PORT" >> app/.env +printf "\nPlease wait while we initialize strapi for development....πŸš€\n" + +printf "\nPlease wait while we initialize the backend....πŸš€\n" cd app -npm i -npm run dev \ No newline at end of file +gp sync-await Initialization_of_NextJS_Packages && npm run dev \ No newline at end of file diff --git a/open-event-server/startOes.sh b/open-event-server/startOes.sh index e7995717..c67cfe21 100644 --- a/open-event-server/startOes.sh +++ b/open-event-server/startOes.sh @@ -4,6 +4,9 @@ ERR_FILE="log/err_log.txt" INIT_FLAG="log/init_flag" OES_CONTAINER_ID=$( docker ps -q -f name=opev-web ) +DOMAIN="localhost" +if [ ! -z "$1" ]; then DOMAIN="$1"; fi + if [ -e $INIT_FLAG ] && [ ! -z $OES_CONTAINER_ID ]; then echo "-- Open Event Server is already up and running --" exit 0 diff --git a/superprofile/initFaunaOnce.sh b/superprofile/initFaunaOnce.sh index 19f77eb7..9149804a 100644 --- a/superprofile/initFaunaOnce.sh +++ b/superprofile/initFaunaOnce.sh @@ -3,6 +3,12 @@ waittime=30 ALREADY_INITIALIZED="log/init_key_flag" +counter=0 +watchdog=6 + +DOMAIN="localhost" +if [ ! -z "$1" ]; then DOMAIN="$1"; fi + FAUNA_CONTAINER_ID=$( docker ps -q -f name=faunadb ) if [ -e $ALREADY_INITIALIZED ] && [ ! -z $FAUNA_CONTAINER_ID ]; then @@ -19,7 +25,7 @@ else docker-compose -f docker-compose-dev.yml up -d echo "--Starting the development build of Superprofile--" echo "--Copying default environment variables to app/.env--" - printf '\nNEXT_PUBLIC_FAUNA_DOMAIN'="http://$1:8084/graphql" >> ../app/.env + printf '\nNEXT_PUBLIC_FAUNA_DOMAIN'="http://$DOMAIN:8084/graphql" >> ../app/.env fi echo "Waiting $waittime seconds for container to get shipped..." @@ -27,20 +33,33 @@ sleep $waittime DBF="log/init_key_flag" container_name="faunadb" -healthy="healthy" -container_state="$( docker inspect -f '{{ .State.Health.Status }}' ${container_name} )" +constainer_health_status="starting" -if [ "$container_state" != $healthy ]; then - echo "Docker container needs extra startup time, please increase the \$waittlist value in initFaunaOnce.sh" - echo "Process ended with health status of Container: $container_state" -else - docker exec -it faunadb /bin/sh /var/log/faunadb/initialize.sh $1 - if [ -f log/dbkey ] && [ ! -f log/init_key_flag ]; then - echo "Copying over secrets to ../app/.env" - printf '\nNEXT_PUBLIC_FAUNA_SECRET=' | cat - ./log/dbkey >> ../app/.env - touch $DBF && - echo "-- All set, superprofile launch πŸš€" +check_and_start_fauna_container() { + container_state="$( docker inspect -f '{{ .State.Health.Status }}' ${container_name} )" + + if [ "$container_state" == $constainer_health_status ]; then + if [ "$counter" -lt $watchdog ]; then + counter=$((counter+1)) + waittime=$((waittime+5)) + echo "Increased wait time to $waittime seconds..." + sleep 5 + check_and_start_fauna_container + elif [ "$counter" -ge $watchdog ]; then + echo "Docker container needs extra startup time, please increase the \$waittlist value in initFaunaOnce.sh" + echo "Process ended with health status of Container: $container_state" + fi else - echo "-- Env variables are already copied, no need to copy over twice πŸ˜‰ --" + docker exec -it faunadb /bin/sh /var/log/faunadb/initialize.sh $1 + if [ -f log/dbkey ] && [ ! -f log/init_key_flag ]; then + echo "Copying over secrets to ../app/.env" + printf '\nNEXT_PUBLIC_FAUNA_SECRET=' | cat - ./log/dbkey >> ../app/.env + touch $DBF && + echo "-- All set, superprofile launch πŸš€" + else + echo "-- Env variables are already copied, no need to copy over twice πŸ˜‰ --" + fi fi -fi \ No newline at end of file +} + +check_and_start_fauna_container \ No newline at end of file