Skip to content

Commit 52d1ddc

Browse files
chore(backend): add docker compose (#229)
* chore(backend): move to docker inside its own package * chore: add husky & lint-staged * chore: dockerize ui * reduce size of docker containers * make it all work together * fix lintstaged * chore(docs): add demo vid to README * update thumbnail * update thumbnail * update border * Add workflow to deploy prisma migrations
1 parent d65a081 commit 52d1ddc

24 files changed

+338
-26
lines changed

.dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ examples
44
public
55
.gitignore
66
README.md
7-
packages/client
87
packages/react
98
packages/js
109
packages/vue

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SERVER_PORT=
2+
PGSQL_URL=
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Deploy prisma
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
# paths:
8+
# - packages/prisma/**
9+
10+
jobs:
11+
deploy-prisma:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v2
17+
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version: 17
22+
- name: Install Fern
23+
run: npm install -g fern-api
24+
25+
- name: Install Dependencies
26+
run: yarn install
27+
28+
- name: Deploy prisma migrations
29+
run: yarn workspace @revertdotdev/backend db-deploy
30+
env:
31+
PGSQL_URL: ${{ secrets.PGSQL_URL }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ npm-debug.log*
7272
*.code-workspace
7373
*.log
7474
!.yarnrc.yml
75+
!docker-compose*.yml
7576
.pnp.*
7677
.yarn/*
7778
!.yarn/patches

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
yarn lint

.lintstagedrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packages/**/*.{js,ts,tsx,json}": [
3+
"prettier --ignore-path ./.prettierignore --write"
4+
]
5+
}

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.13
1+
16.19.1

.yarn/install-state.gz

16.3 KB
Binary file not shown.

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99
[Get started](https://revert.dev) · [Docs](https://docs.revert.dev/) · [Issues](https://github.com/revertinc/revert/issues) · [Discord](https://discord.gg/q5K5cRhymW) · [Get in touch](mailto:[email protected])
1010

1111
</h2>
12-
<br />
13-
<img width="100%" style="border-radius:75px;" src="https://res.cloudinary.com/dfcnic8wq/image/upload/v1689828148/Revert/github_o27jvk.png"/>
1412

1513
</p>
1614

1715
# About Revert
1816

1917
Revert makes it easier to build integrations with go-to-market tools like CRM's.
2018

19+
<a href="http://www.youtube.com/watch?feature=player_embedded&v=1aXXx66LKnY
20+
" target="_blank">
21+
<img src="https://res.cloudinary.com/dfcnic8wq/image/upload/v1694089822/Revert/Screenshot_2023-09-07_at_6.00.00_PM_xz7edr.png"
22+
alt="Revert Quick demo" border="2"/>
23+
<em>Revert Quick demo</em>
24+
</a>
25+
2126
Visit: https://revert.dev to sign up for an account or read our docs [here](https://docs.revert.dev) !
2227

2328
### What makes us faster and reliable.

docker-compose.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: '3.8'
2+
3+
services:
4+
db:
5+
image: postgres:15
6+
ports:
7+
- '5432:5432'
8+
volumes:
9+
- pgdata:/var/lib/postgresql/data
10+
restart: on-failure
11+
environment:
12+
POSTGRES_DB: ${POSTGRES_DATABASE:-postgres}
13+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
14+
healthcheck:
15+
test: ["CMD-SHELL", "pg_isready -U postgres"]
16+
interval: 10s
17+
timeout: 5s
18+
retries: 5
19+
ui:
20+
build:
21+
dockerfile: packages/client/Dockerfile
22+
context: "./"
23+
env_file:
24+
- packages/client/.env
25+
ports:
26+
- 3000:3000
27+
api:
28+
build:
29+
dockerfile: packages/backend/Dockerfile
30+
context: "./"
31+
args:
32+
PGSQL_URL: postgresql://postgres:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DATABASE}
33+
SERVER_PORT: ${SERVER_PORT}
34+
env_file:
35+
- packages/backend/.env
36+
ports:
37+
- 4001:4001
38+
depends_on:
39+
db:
40+
condition: service_healthy # Wait for db service to be healthy
41+
42+
volumes:
43+
pgdata:

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
],
77
"devDependencies": {
88
"fern-api": "0.12.0",
9+
"husky": "^8.0.3",
10+
"lint-staged": "^10.5.4",
911
"prettier": "2.5.1",
1012
"pretty-quick": "3.1.3",
1113
"typescript": "^4.8.4"
1214
},
1315
"scripts": {
1416
"fern": "fern generate --log-level debug --group local",
1517
"fern-docs": "fern generate --group external",
16-
"build": "yarn workspaces foreach run build"
18+
"build": "yarn workspaces foreach run build",
19+
"prepare": "husky install",
20+
"lint": "lint-staged"
1721
},
1822
"prisma": {
1923
"schema": "packages/backend/prisma/schema.prisma",

packages/backend/.dockerignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
examples
3+
public
4+
.gitignore
5+
README.md
6+
packages/client
7+
packages/react
8+
packages/js
9+
packages/vue

packages/backend/.env.example

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
SERVER_PORT=4001
2+
REDIS_SERVER_URL=
3+
HUBSPOT_CLIENT_ID=
4+
HUBSPOT_CLIENT_SECRET=
5+
ZOHOCRM_CLIENT_ID=
6+
ZOHOCRM_CLIENT_SECRET=
7+
PGSQL_URL=
8+
SFDC_CLIENT_ID=
9+
SFDC_CLIENT_SECRET=
10+
OAUTH_REDIRECT_BASE=http://localhost:3000/oauth-callback
11+
PORT=4001
12+
SLACK_HOOK_URL=
13+
SENTRY_DSN=
14+
SVIX_AUTH_TOKEN=
15+
SHORTLOOP_AUTH_KEY=
16+
SVIX_ENDPOINT_SECRET=
17+
FERN_TOKEN=
18+
PIPEDRIVE_CLIENT_ID=
19+
PIPEDRIVE_CLIENT_SECRET=
20+
AES_ENCRYPTION_SECRET=

Dockerfile packages/backend/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM node:alpine AS BUILD_IMAGE
22
WORKDIR /app/
3-
COPY ./fern/ /app/fern/
43

4+
COPY ./fern/ /app/fern/
55
COPY ./packages/backend /app/packages/backend
66
COPY ./yarn.lock /app/yarn.lock
77
COPY ./package.json /app/package.json

packages/backend/config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Svix } from 'svix';
44
dotenv.config();
55

66
const config = {
7-
PORT: process.env.SERVER_PORT,
7+
PORT: process.env.SERVER_PORT || 4001,
88
DATABASE: process.env.MONGO_DATABASE,
99
REDIS_URL: process.env.REDIS_SERVER_URL,
1010
HUBSPOT_CLIENT_ID: process.env.HUBSPOT_CLIENT_ID,
@@ -22,7 +22,7 @@ const config = {
2222
SVIX_AUTH_TOKEN: process.env.SVIX_AUTH_TOKEN,
2323
SHORTLOOP_AUTH_KEY: process.env.SHORTLOOP_AUTH_KEY!,
2424
SVIX_ENDPOINT_SECRET: process.env.SVIX_ENDPOINT_SECRET!,
25-
svix: new Svix(process.env.SVIX_AUTH_TOKEN!),
25+
svix: process.env.SVIX_AUTH_TOKEN ? new Svix(process.env.SVIX_AUTH_TOKEN!) : undefined,
2626
WHITE_LISTED_DOMAINS: process.env.WHITE_LISTED_DOMAINS?.split(','),
2727
AES_ENCRYPTION_SECRET: process.env.AES_ENCRYPTION_SECRET!,
2828
};

packages/backend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Codebase to run revert-backend",
55
"private": true,
66
"scripts": {
7-
"build": "mkdir -p ./dist/generated && cp -r ./generated/ ./dist/generated && tsc && yarn migration:generate",
7+
"build": "mkdir -p ./dist/generated && cp -r ./generated/ ./dist/generated && tsc",
88
"watch": "tsc -w",
99
"start": "NODE_ENV=production node ./dist/index.js",
1010
"start:prod": "yarn db-deploy && NODE_ENV=production node ./dist/index.js",

packages/backend/routes/v1/crm/auth.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ authRouter.get('/oauth-callback', async (req, res) => {
8080
appId: account?.apps[0].id,
8181
},
8282
});
83-
config.svix.message.create(svixAppId, {
83+
config.svix?.message.create(svixAppId, {
8484
eventType: 'connection.added',
8585
payload: {
8686
eventType: 'connection.added',
@@ -162,7 +162,7 @@ authRouter.get('/oauth-callback', async (req, res) => {
162162
tp_refresh_token: result.data.refresh_token,
163163
},
164164
});
165-
config.svix.message.create(svixAppId, {
165+
config.svix?.message.create(svixAppId, {
166166
eventType: 'connection.added',
167167
payload: {
168168
eventType: 'connection.added',
@@ -243,7 +243,7 @@ authRouter.get('/oauth-callback', async (req, res) => {
243243
app_client_secret: clientSecret || config.SFDC_CLIENT_SECRET,
244244
},
245245
});
246-
config.svix.message.create(svixAppId, {
246+
config.svix?.message.create(svixAppId, {
247247
eventType: 'connection.added',
248248
payload: {
249249
eventType: 'connection.added',
@@ -321,7 +321,7 @@ authRouter.get('/oauth-callback', async (req, res) => {
321321
appId: account?.apps[0].id,
322322
},
323323
});
324-
config.svix.message.create(svixAppId, {
324+
config.svix?.message.create(svixAppId, {
325325
eventType: 'connection.added',
326326
payload: {
327327
eventType: 'connection.added',

packages/backend/services/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class AuthService {
246246
})
247247
);
248248
// Create Svix application for this account if it doesn't exist.
249-
await config.svix.application.getOrCreate({
249+
await config.svix?.application.getOrCreate({
250250
name: accountId,
251251
uid: accountId,
252252
});

packages/backend/services/connection.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const connectionService = new ConnectionService({
107107
},
108108
});
109109
if (deleted) {
110-
config.svix.message.create(svixAppId, {
110+
config.svix?.message.create(svixAppId, {
111111
eventType: 'connection.deleted',
112112
payload: {
113113
eventType: 'connection.deleted',
@@ -131,7 +131,7 @@ const connectionService = new ConnectionService({
131131
});
132132
const svixAppId = environment?.accountId!;
133133
const secret = `whsec_${Buffer.from(uuidv4()).toString('base64')}`;
134-
const webhook = await config.svix.endpoint.create(svixAppId, {
134+
const webhook = await config.svix!.endpoint.create(svixAppId, {
135135
url: webhookUrl,
136136
version: 1,
137137
description: `Connection Webhook for tenant ${tenantId}`,
@@ -167,7 +167,7 @@ const connectionService = new ConnectionService({
167167
},
168168
});
169169
const svixAppId = environment?.accountId!;
170-
const webhook = await config.svix.endpoint.get(svixAppId, String(tenantId));
170+
const webhook = await config.svix!.endpoint.get(svixAppId, String(tenantId));
171171
res.send({ status: 'ok', webhook: webhook });
172172
} catch (error: any) {
173173
logError(error);
@@ -190,7 +190,7 @@ const connectionService = new ConnectionService({
190190
},
191191
});
192192
const svixAppId = environment?.accountId!;
193-
await config.svix.endpoint.delete(svixAppId, webhookId);
193+
await config.svix!.endpoint.delete(svixAppId, webhookId);
194194
res.send({ status: 'ok' });
195195
} catch (error: any) {
196196
logError(error);

packages/client/.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
examples
3+
public
4+
.gitignore
5+
README.md
6+
**/node_modules
7+
packages/react
8+
packages/js
9+
packages/vue
10+
packages/backend
11+
packages/client/node_modules

packages/client/.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
REACT_APP_REVERT_BASE_API_URL=http://localhost:4001
2+
REACT_APP_SLACK_CLIENT_ID=
3+
REACT_APP_SLACK_CLIENT_SECRET=
4+
REACT_APP_CLERK_PUBLISHABLE_KEY=
5+
REACT_APP_SENTRY_DSN=

packages/client/Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Use an official Node.js runtime as the base image
2+
FROM node:14-alpine AS builder
3+
4+
# Set the working directory in the container
5+
WORKDIR /app
6+
7+
# Copy the package.json and yarn.lock files to the container
8+
COPY package.json yarn.lock ./
9+
# Copy the entire project directory into the container
10+
COPY . .
11+
12+
# Copy the .env file into the container
13+
COPY ./packages/client/.env ./app/packages/client/.env
14+
15+
# Install project dependencies using Yarn
16+
RUN yarn install --check-cache
17+
# Build the React app
18+
RUN yarn workspace @revertdotdev/revert-ui build
19+
20+
# Bundle static assets with nginx
21+
FROM nginx:1.21.0-alpine as production
22+
ENV NODE_ENV production
23+
# Copy built assets from builder
24+
COPY --from=builder /app/packages/client/build /usr/share/nginx/html
25+
# Add your nginx.conf
26+
COPY ./packages/client/nginx.conf /etc/nginx/conf.d/default.conf
27+
# Expose port
28+
EXPOSE 3000
29+
# Start nginx
30+
CMD ["nginx", "-g", "daemon off;"]

packages/client/nginx.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
server {
2+
listen 3000;
3+
4+
location / {
5+
root /usr/share/nginx/html/;
6+
include /etc/nginx/mime.types;
7+
try_files $uri $uri/ /index.html;
8+
}
9+
}

0 commit comments

Comments
 (0)