Skip to content

Commit

Permalink
Merge branch 'dev' into amos
Browse files Browse the repository at this point in the history
  • Loading branch information
gvelez17 authored Nov 25, 2024
2 parents a74aaac + 35b8010 commit 0261536
Show file tree
Hide file tree
Showing 39 changed files with 7,868 additions and 4,803 deletions.
28 changes: 28 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Description

Please provide a brief summary of the changes in this PR.

## Type of Change

- [ ] Bug fix
- [ ] New feature
- [ ] Test case
- [ ] Documentation update
- [ ] Other (please describe)

## Checklist

- [ ] I have added tests that prove my fix is effective or that my feature works (optional)
- [ ] I have added necessary documentation (if applicable)

## 4- steps to test ?

Please provide a brief summary of the steps required to test the changes in this PR.

## 5- results ?

Please provide a brief summary of the results after testing the changes in this PR.

## 7- screenshots ?

Please provide screenshots of the results after testing the changes in this PR.
2 changes: 1 addition & 1 deletion .github/workflows/webhook.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Call Webhook on Push or PR Merge to Master
name: Call Webhook on Push or PR Merge to Dev

on:
push:
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ RUN apt-get install -y openssl
WORKDIR /app

COPY package.json ./
COPY package-lock.json ./
COPY yarn.lock ./

COPY ./prisma ./prisma

COPY ./.env ./

RUN npm install
RUN yarn
RUN npx prisma generate

EXPOSE 9000
Expand Down
5 changes: 2 additions & 3 deletions README-alt-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ACCESS_SECRET=dPEBknfdAcx5bir34KnX2mATWZnvM4xF
REFRESH_SECRET=opdC0LNGrZWWF0jLrPJwhLPF8aew4l3L
```

then run
then run

`npm run dev`

Expand All @@ -27,8 +27,7 @@ run from within an IDE such as webstorm with simple configuration such as

<img width="852" alt="image" src="https://user-images.githubusercontent.com/798887/232255771-e3cf52db-ece2-48b0-b67f-cd8edec39776.png">


------------
---

you may also have to copy .env to .env.dev

Expand Down
64 changes: 38 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Linked Trust Backend

This is an implementation of the OpenTrustClaims schema from https://github.com/blueskyCommunity/OpenTrustClaims/blob/main/open_trust_claim.yaml, and is the backend powering https://live.linkedtrust.us and [dev server](https://live.linkedtrust.us)
This is an implementation of the OpenTrustClaims schema from https://github.com/blueskyCommunity/OpenTrustClaims/blob/main/open_trust_claim.yaml, and is the backend powering https://live.linkedtrust.us and [dev server](https://dev.linkedtrust.us)

trust_claim_backend is a Node application for adding Claims, and for presenting Nodes and Edges derived from claims in it

Expand All @@ -9,8 +9,8 @@ To generate Nodes and Edges from Claims it is also necessary to run [trust-claim
## Concepts

Claim: a signed set of structured data with the raw claim or attestation, often signed on front end by the user's DID
Node: an entity that a claim is about. This is created in the app as a view of what a claim is about.
Edge: a representation of a claim that relates to a Node or connects two Nodes. Created in the app as a view of a claim.
Node: an entity that a claim is about. This is created in the app as a view of what a claim is about.
Edge: a representation of a claim that relates to a Node or connects two Nodes. Created in the app as a view of a claim.

## CICD Pipeline with Jenkins

Expand All @@ -20,11 +20,11 @@ And for Auth Details to the pipeline, kindly refer to vault [jenkins logins](htt

For SSH Access into the dev server, kindly refer to this creds in the vault [dev server ssh creds](https://vault.whatscookin.us/app/passwords/view/cbe52954-3f7a-4e5d-9bb7-039389acc42c) this would help you ssh into the dev serverm while inside, the files would be in the `/data/trust_claim_backend` directory and configured with nginx

*NB: The production version of this is available on [live.linkedtrust.us](live.linkedtrust.us)*
_NB: The production version of this is available on [live.linkedtrust.us](live.linkedtrust.us)_

## Run the application locally

Running the application in docker is only important if you don't want to set up postgresql server in your pc. If you choose to not use docker in development, then set the postgresql db url and env variables in `.env` file. Check [Env variables](#env-variables). section.
Running the application in docker is only important if you don't want to set up postgresql server in your pc. If you choose to not use docker in development, then set the postgresql db url and env variables in `.env` file. Check [Env variables](#env-variables). section.

Then running below command is sufficient.

Expand All @@ -43,7 +43,7 @@ npm run build

You will need docker installed in your computer. For help with installation, ask in slack.

Build the docker containers and run it. Two options are available
Build the docker containers and run it. Two options are available

### Option 1: Without the data pipeline - for viewing only

Expand Down Expand Up @@ -89,8 +89,8 @@ Database is handled with the help of prisma orm.

#### Apply migration

*** NOTE NOTE NOTE : the migrations in prod server are currently NOT working automatically 8/1/2024 ***
*** the migration in the prisma/migrations folder was applied manually ***
**_ NOTE NOTE NOTE : the migrations in prod server are currently NOT working automatically 8/1/2024 _**
**_ the migration in the prisma/migrations folder was applied manually _**

If migration is not for docker container then run

Expand Down Expand Up @@ -135,7 +135,6 @@ For descrip column:
CREATE INDEX idx_descrip ON "Node" USING GIN ("descrip" gin_trgm_ops);
```


These steps ensure your local DB mirrors production's text search optimizations.

#### To check the database, use the goodness of prisma studio
Expand All @@ -155,13 +154,17 @@ npm run prisma:studio
After running this command prisma studio opens in port 5555.

#### Integrated seeding with Prisma Migrate:

Database seeding happens in two ways with Prisma: manually with prisma db seed and automatically in prisma migrate dev.

Run
Run

```
npx prisma db seed
```

or

```
npm i
prisma migrate dev
Expand All @@ -173,50 +176,55 @@ When you want to use prisma migrate dev without seeding, you can pass the --skip

Create a `.env` file in project root. If running with docker an additional `.env.dev` file is needed. Refer to below example for env variables:

```
```bash
PORT=9000
DATABASE_URL="postgresql://postgres:postgres@postgres:5432/claim"
ACCESS_SECRET=**add_your_secret_keys_here**
REFRESH_SECRET=**add_your_secret_keys_here**

ACCESS_SECRET='...'
REFRESH_SECRET='...'
AWS_ACCESS_KEY_ID='...'
AWS_SECRET_ACCESS_KEY='...'
AWS_STORAGE_BUCKET_NAME='...'
AWS_S3_REGION_NAME='...'

```

In `.env.dev`, change `DATABASE_URL` like below, everything else can be exactly like `.env`.

```
```bash
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/claim"
```

Value for `ACCESS_SECRET` and `REFRESH_SECRET` can be anything.

<a name="Review"></a>
## To review the server files

SSH into the server with the private key. If you don't have the key, ask for it in slack.

```
Check vault for ssh creds, url is inserted above
```
## Prod deployment is manual

cd into the project
SSH into the server with the private key. If you don't have the key, ask for it in slack.

```
cd /data/trust_claim_backend
Check vault for ssh creds to live.linkedtrust.us
```

inspect the running file
inspect the running file

```
pm2 status index
pm2 logs index
```

Run this command to check for possible changes in packages, and install changed packages.
### Update from git and install dependencies

```
cd /data/trust_claim_backend
git pull
npm i
```

If there is any database migration, it is a good idea to backup the database.
### If required, database migration

If there is any database migration, it is a good idea to backup the database, otherwise you may skip this step.

```
sudo su postgres
Expand All @@ -230,13 +238,17 @@ npx prisma generate
npx prisma migrate deploy
```

### Rebuild with changes

Then, building the project is enough, because `pm2` is watching for changes.

```
npm run build
```

NOTE: Run this ONLY when the server is down
### DONE. Troubleshooting:

NOTE: Run this ONLY when the server is down

```
pm2 start index.js --watch
Expand Down
Loading

0 comments on commit 0261536

Please sign in to comment.