diff --git a/.gitignore b/.gitignore index 49350986..93cb7bb0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ redis-data redis.conf .DS_Store node_modules/ +pgdata +redisinsight +broker .env \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml index 6b6221c5..1c6b60e7 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -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 @@ -21,5 +21,8 @@ ports: onOpen: ignore visibility: public - port: 15672 + onOpen: ignore + visibility: public + - port: 8088 onOpen: ignore visibility: public \ No newline at end of file diff --git a/apps/api/docker-compose.yml b/apps/api/docker-compose.yml deleted file mode 100644 index c4101361..00000000 --- a/apps/api/docker-compose.yml +++ /dev/null @@ -1,68 +0,0 @@ -version: '3' - -services: - short-nr: - build: ./src - image: short-nr - container_name: short-nr - restart: unless-stopped - env_file: - - src/.env - ports: - - 8888:8888 - - shortdb: - container_name: shortdb - image: postgres:12 - env_file: - - src/.env - ports: - - "5432" - volumes: - - ./pgdata:/var/lib/postgresql/data - - gql: - image: hasura/graphql-engine:v2.0.0-alpha.1 - env_file: - - src/.env - ports: - - "15003:8080" - 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 - - shortnr-redis-commander: - container_name: shortnr-redis-commander - hostname: redis-commander - image: rediscommander/redis-commander:latest - restart: always - environment: - - REDIS_HOSTS=local:shortnr-cache:6379 - ports: - - '8088:8081' \ No newline at end of file diff --git a/deploy.sh b/deploy.sh index efeefd7a..82891c8a 100644 --- a/deploy.sh +++ b/deploy.sh @@ -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 \ No newline at end of file +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 diff --git a/docker-compose.gitpod.yml b/docker-compose.gitpod.yml new file mode 100644 index 00000000..9651b97e --- /dev/null +++ b/docker-compose.gitpod.yml @@ -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 \ No newline at end of file diff --git a/apps/api/pgdata.zip b/pgdata.zip similarity index 92% rename from apps/api/pgdata.zip rename to pgdata.zip index 7b67e1d7..f9b84008 100644 Binary files a/apps/api/pgdata.zip and b/pgdata.zip differ diff --git a/readme.md b/readme.md index a74b6591..a3296d81 100644 --- a/readme.md +++ b/readme.md @@ -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 \ No newline at end of file +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Samagra-Development/yaus) \ No newline at end of file diff --git a/sample.env b/sample.env index 8229b10f..d8494e91 100644 --- a/sample.env +++ b/sample.env @@ -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 @@ -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" \ No newline at end of file +DATABASE_URL="postgresql://postgresql:yoursupersecret@localhost:5432/shortdb?schema=public" \ No newline at end of file