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

Gitpodified RC4Conferences 🍊 #75

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
4a226a9
rc4community-->rc4conf
Palanikannan1437 Dec 29, 2022
c7c0a29
settings to prevent unncessary popups during startup added
Palanikannan1437 Dec 29, 2022
e0c7343
added increase waittime logic incase gitpod requires more time to start
Palanikannan1437 Dec 31, 2022
1860d5c
added init gitpod scripts
Palanikannan1437 Dec 31, 2022
2f13781
fixed wrong shell script imports
Palanikannan1437 Dec 31, 2022
b0ebb8c
cd added
Palanikannan1437 Dec 31, 2022
cd46c6b
fixed wrong paths and missing variables
Palanikannan1437 Jan 5, 2023
1c6ece0
removed wrong changing directory step
Palanikannan1437 Jan 5, 2023
1c94654
Added synchronization for cleanup and package dependency checks
Palanikannan1437 Jan 5, 2023
ab8e0e1
removed deadlock
Palanikannan1437 Jan 5, 2023
41ebdbf
fixed deadlock along with wrong directory
Palanikannan1437 Jan 5, 2023
f6dea04
exiting from gitpod-scripts directory to fix env variables exports
Palanikannan1437 Jan 5, 2023
d85f41a
changed visibility of port 3000 to public
Palanikannan1437 Jan 5, 2023
8dcde16
gp urls not initiliazed bug fixed
Palanikannan1437 Jan 5, 2023
017d0d1
fixing domain for localhost
Palanikannan1437 Jan 5, 2023
57e3021
added exit to close terminals after execution
Palanikannan1437 Jan 5, 2023
85d635f
exit in command
Palanikannan1437 Jan 5, 2023
84ea213
Merge branch 'RocketChat:main' into gitpod-script
Palanikannan1437 Jan 6, 2023
a9ccb16
Added readme for gitpod
Palanikannan1437 Jan 6, 2023
800d3af
Merge branch 'RocketChat:main' into gitpod-script
Palanikannan1437 Mar 31, 2023
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
64 changes: 64 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"workbench.startupEditor": "none"
}
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<ins>Gitpod Setup</ins>

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)

---
<ins>Local Setup</ins>
```bash
sh startdevenv.sh localhost
sh startNext.sh localhost
```
<ins>Gitpod Setup</ins>
```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:
Expand Down
4 changes: 2 additions & 2 deletions app/components/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Container fluid className="border-bottom ">
<Navbar expand="lg" className=" bg-white mx-4 my-2">
Expand Down Expand Up @@ -105,7 +105,7 @@ export default function Menubar(props) {
<Dropdown align="end" className={styles.dropdown_menu}>
<Dropdown.Toggle as={CustomToggle} />
<Dropdown.Menu size="sm" title="">
<Dropdown.Header>RC4Community Profile</Dropdown.Header>
<Dropdown.Header>RC4Conferences Profile</Dropdown.Header>
<Dropdown.Item>
<Link href={`/profile/${userCookie}`}>
<a className={styles.dropdown_menu_item}>Profile</a>
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "rc4community",
"name": "rc4conferences",
"version": "0.3.0",
"private": true,
"scripts": {
Expand Down
39 changes: 39 additions & 0 deletions gitpod-scripts/startCloudContainers.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions gitpod-scripts/startCloudDevBackend.sh
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions gitpod-scripts/startCloudDevEnv.sh
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions gitpod-scripts/startCloudDevStrapi.sh
Original file line number Diff line number Diff line change
@@ -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'="[email protected]" >> app/.env
printf '\nNEXT_PUBLIC_EVENT_ANON_MAIL'="[email protected]" >> app/.env

cd cms
export PORT=$STRAPI_PORT
INITIALIZE_DATA=true npm run develop
24 changes: 19 additions & 5 deletions startNextGp.sh → gitpod-scripts/startCloudNext.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
gp sync-await Initialization_of_NextJS_Packages && npm run dev
3 changes: 3 additions & 0 deletions open-event-server/startOes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 34 additions & 15 deletions superprofile/initFaunaOnce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,28 +25,41 @@ 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..."
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
}

check_and_start_fauna_container