Skip to content

Commit

Permalink
Merge pull request #29 from Samagra-Development/gitpod
Browse files Browse the repository at this point in the history
Fixes related to Gitpod
  • Loading branch information
ChakshuGautam authored Jun 11, 2022
2 parents 39ad2ad + 8ed92ae commit 8db3e16
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ redis-data
redis.conf
.DS_Store
node_modules/
pgdata
redisinsight
broker
.env
5 changes: 4 additions & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ tasks:
- name: YAUS Server
init: bash ./deploy.sh
env:
DATABASE_URL: "postgresql://postgresql:yoursupersecret@localhost:49153/shortdb?schema=public"
DATABASE_URL: "postgresql://postgresql:yoursupersecret@localhost:5432/shortdb?schema=public"

ports:
- port: 5432
Expand All @@ -21,5 +21,8 @@ ports:
onOpen: ignore
visibility: public
- port: 15672
onOpen: ignore
visibility: public
- port: 8088
onOpen: ignore
visibility: public
68 changes: 0 additions & 68 deletions apps/api/docker-compose.yml

This file was deleted.

37 changes: 34 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
#!/bin/sh

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

# Load NVM
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 16
nvm use 16

cp sample.env .env
cd apps/api
sudo apt-get install unzip
unzip pgdata.zip
docker-compose up -d shortdb gql yaus-broker shortnr-cache
npx nx serve api
rm -rf pgdata.zip
rm -rf __MACOSX

# Resolving permission errors
mkdir -p broker
mkdir -p redisinsight
sudo chown -R 1001:1001 broker
sudo chown -R 1001:1001 redisinsight

docker-compose -f docker-compose.gitpod.yml up -d

yarn install
npx prisma generate --schema=/workspace/yaus/apps/api/src/app/prisma/schema.prisma

# sleep for 15 seconds
sleep 30

# Starting Server - https://8888-
serverBaseURL=${GITPOD_WORKSPACE_URL:-default_value}
serverBaseURL="https://8088-${serverBaseURL:8}/add/?name=shortnr&host=shortnr-cache&port=6379"
curl "${serverBaseURL}"
echo "Open this URL in a the browser to add redis to redisInsight ${serverBaseURL}"

# start api server
npx nx serve api
67 changes: 67 additions & 0 deletions docker-compose.gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
version: '3'

services:
shortdb:
container_name: shortdb
image: postgres:12
env_file:
- .env
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
ports:
- 5432:5432
volumes:
- ./pgdata:/var/lib/postgresql/data

gql:
image: hasura/graphql-engine:v2.7.0
ports:
- 15003:8080
env_file:
- .env
environment:
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://postgresql:${POSTGRES_PASSWORD}@shortdb:5432/${POSTGRES_DB}
PG_DATABASE_URL: postgres://postgresql:${POSTGRES_PASSWORD}@shortdb:5432/${POSTGRES_DB}
HASURA_GRAPHQL_ENABLE_CONSOLE: "true" # set to "false" to disable console
HASURA_GRAPHQL_DEV_MODE: "true"
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_ADMIN_SECRET}
depends_on:
- shortdb
restart: always

yaus-broker:
container_name: yaus-broker
image: "docker.io/bitnami/rabbitmq:latest"
environment:
- RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD}
- RABBITMQ_USERNAME=${RABBITMQ_USERNAME}
ports:
- 4369:4369
- 5672:5672
- 25672:25672
- 15672:15672
volumes:
- ./broker:/bitnami

shortnr-cache:
container_name: shortnr-cache
restart: always
image: redis:latest
ports:
- "6381:6379"
command: ["redis-server", "--appendonly", "yes"]
hostname: redis
volumes:
- ./redis-data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf

redis-ui:
container_name: redis-ui
image: redislabs/redisinsight:latest
restart: always
volumes:
- ./redisinsight:/db
ports:
- 8088:8001
Binary file renamed apps/api/pgdata.zip → pgdata.zip
Binary file not shown.
29 changes: 4 additions & 25 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
### Setting Up Backend
## YAUS

```shell
cd apps/api
unzip pgdata.zip
docker-compose up -d shortdb gql yaus-broker shortnr-cache
npx nx serve api
```
### Contributing
It is recommended to develop on Gitpod since everything is coupled with a bunch of dependencies. To start your Gitpod session click on the button below.

### Setting up Frontend

```shell
npx nx server admin
```

### Try It
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Samagra-Development/yaus)

### TODO
- [x] Migrate to Fastify
- [x] Add all the routes that are not yet implemented
- [x] Prisma Schema Setup
- [x] Posthog integration -- (Discuss and add events)
- [x] Health Check APIs (https://docs.nestjs.com/recipes/terminus) -- (Add for Db, Hasura, Redis, RabbitMq)
- [] Admin APIs
- [x] Integrate Swagger --- (Pending: Add detailed descriptions for APIs)
- [x] Added interceptor for API execution time tracking
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Samagra-Development/yaus)
6 changes: 5 additions & 1 deletion sample.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
POSTGRES_DB=shortdb
POSTGRES_PASSWORD=yoursupersecret
REDIS_URI=redis://localhost:6381
GRAPHQL_URI=http://localhost:15003/v1/graphql
HASURA_ADMIN_SECRET=4GeEB2JCU5rBdLvQ4AbeqqrPGu7kk9SZDhJUZm7A
BASE_URL=https://www.yaus.xyz/
RABBITMQ_PASSWORD=password
RABBITMQ_USERNAME=username
RMQ_URL=amqp://username:password@localhost:5672
RMQ_QUEUE=clicks
RMQ_QUEUE_DURABLE=false
Expand All @@ -18,4 +22,4 @@ POSTHOG_FLUSH_INTERVAL=10000
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB (Preview).
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://postgresql:yoursupersecret@localhost:49153/shortdb?schema=public"
DATABASE_URL="postgresql://postgresql:yoursupersecret@localhost:5432/shortdb?schema=public"

0 comments on commit 8db3e16

Please sign in to comment.