Skip to content

Commit

Permalink
feat: Self hosting (#34)
Browse files Browse the repository at this point in the history
- New self-hosting support through Docker
- New customizable Wrapper block
- New remote transformers for Git integration
- Redesigned landing page
- Redesigned docs
- Improvements to the commenting system
- Bug fixes and stability improvements
  • Loading branch information
areknawo committed Sep 13, 2023
1 parent 4c5a9aa commit d8c9421
Show file tree
Hide file tree
Showing 264 changed files with 13,140 additions and 4,837 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules
node_modules
dist
npm-debug.log
.gitignore
90 changes: 58 additions & 32 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,38 +1,64 @@
# Database
MONGO_URL=
REDIS_URL=
DATABASE=
# Security
# Basic (required)
HOST=0.0.0.0
NODE_ENV=production

# Cookies (optional - multi-domain setup)
COOKIE_DOMAIN=

# Security (required - JWT)
SECRET=
# Domains
TOP_DOMAIN=
CALLBACK_DOMAIN=
# Serve
HOST=
# Email

# MongoDB (required)
MONGO_URL=mongodb://mongodb:27017/vrite

# Redis (required)
REDIS_URL=redis://redis:6379

# Email (required)
SENDER_EMAIL=hello@example.com
SENDER_NAME=Example

# One of following required:

# Email (SMTP)
SMTP_HOST=
SMTP_PORT=
SMTP_USER=
SMTP_PASS=
SMTP_SECURE=

# Email (SendGrid)
SENDGRID_API_KEY=
SENDGRID_EMAIL_VERIFICATION_TEMPLATE_ID=
SENDGRID_MAGIC_LINK_TEMPLATE_ID=
SENDGRID_PASSWORD_CHANGE_VERIFICATION_TEMPLATE_ID=
SENDGRID_WORKSPACE_INVITE_TEMPLATE_ID=
SENDGRID_EMAIL_CHANGE_VERIFICATION_TEMPLATE_ID=
EMAIL=
SENDER_NAME=
# S3
S3_BUCKET=
S3_ENDPOINT=
S3_REGION=
S3_ACCESS_KEY=
S3_SECRET_KEY=
# GitHub OAuth2

# S3 (required - file storage)
S3_BUCKET=vrite-images
S3_ENDPOINT=http://minio:9000
S3_REGION=us-east-1
S3_ACCESS_KEY=user
S3_SECRET_KEY=password
S3_FORCE_PATH_STYLE=true

# Service URLs (required)
PUBLIC_COLLAB_URL=http://localhost:5555
PUBLIC_APP_URL=http://localhost:3333
PUBLIC_API_URL=http://localhost:4444
PUBLIC_ASSETS_URL=http://localhost:8888

# GitHub OAuth2 (optional - GitHub sign in)
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

# GitHub App (optional - GitHub Git sync)
GITHUB_APP_ID=
GITHUB_APP_PRIVATE_KEY=
GITHUB_APP_WEBHOOK_SECRET=
GITHUB_APP_CLIENT_ID=
GITHUB_APP_CLIENT_SECRET=
# Frontend
PUBLIC_COLLAB_HOST=
PUBLIC_APP_HOST=
PUBLIC_API_HOST=
# Search
OPENAI_API_KEY=
OPENAI_ORGANIZATION=

# Search (optional - Search)
# WEAVIATE_API_KEY=password
# WEAVIATE_URL=http://weaviate:8080

# AI (optional - AI "Q&A" search)
# OPENAI_API_KEY=
# OPENAI_ORGANIZATION=
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
]
}
],
"camelcase": "off",
"no-undefined": "off",
"max-lines-per-function": "off",
"max-statements": "off",
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build & publish
on:
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./apps/backend/app/Dockerfile
image: vriteio/vrite/app
- dockerfile: ./apps/backend/api/Dockerfile
image: vriteio/vrite/api
- dockerfile: ./apps/backend/collaboration/Dockerfile
image: vriteio/vrite/collaboration
- dockerfile: ./apps/backend/assets/Dockerfile
image: vriteio/vrite/assets
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ matrix.image }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ yarn-error.log*

# turbo
.turbo

# React Email
.react-email
37 changes: 37 additions & 0 deletions apps/backend/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM node:18-alpine as base

FROM base AS builder
WORKDIR /app
RUN apk add --no-cache libc6-compat && npm install -g turbo

COPY . .

RUN turbo prune --scope=@vrite/api --docker


FROM base as installer
WORKDIR /app

RUN npm install -g pnpm@8.6.0
RUN npm install -g turbo

COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm i --frozen-lockfile

COPY --from=builder /app/out/full/ .

RUN pnpm rebuild -r
RUN turbo run build --filter=@vrite/api

FROM base AS runner
WORKDIR /app

# Install extra dependencies
RUN npm install saslprep
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 app

USER app
COPY --from=installer --chown=app:nodejs /app/apps/backend/api/dist .
CMD node index.js
6 changes: 3 additions & 3 deletions apps/backend/api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ const apiService = publicPlugin(async (fastify) => {
}

const { hostname } = new URL(origin);
const appHostname = new URL(fastify.config.PUBLIC_APP_URL).hostname;

if (
hostname === "localhost" ||
hostname.endsWith("vrite.io") ||
hostname.endsWith("swagger.io")
hostname.endsWith(appHostname) ||
(fastify.config.VRITE_CLOUD && hostname.endsWith("swagger.io"))
) {
// Request from localhost will pass
callback(null, true);

return;
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { createServer, appRouter } from "@vrite/backend";
const server = await createServer();

await server.register(apiService);
await server.get("/swagger.json", (req, res) => {
server.get("/swagger.json", (req, res) => {
res.send(
generateOpenApiDocument(appRouter, {
baseUrl: "https://api.vrite.io",
baseUrl: `https://${server.config.PUBLIC_API_HOST}`,
title: "Vrite API",
version: "2023.8.18"
version: "0.2.0"
})
);
});
Expand Down
37 changes: 37 additions & 0 deletions apps/backend/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM node:18-alpine as base

FROM base AS builder
WORKDIR /app
RUN apk add --no-cache libc6-compat && npm install -g turbo

COPY . .

RUN turbo prune --scope=@vrite/app --docker


FROM base as installer
WORKDIR /app

RUN npm install -g pnpm@8.6.0
RUN npm install -g turbo

COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm i --frozen-lockfile

COPY --from=builder /app/out/full/ .

RUN pnpm rebuild -r
RUN turbo run build --filter=@vrite/app

FROM base AS runner
WORKDIR /app

# Install extra dependencies
RUN npm install saslprep sharp
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 app

USER app
COPY --from=installer --chown=app:nodejs /app/apps/backend/app/dist .
CMD node index.js
14 changes: 12 additions & 2 deletions apps/backend/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
"start": "node ./dist/index.js"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.374.0",
"@fastify/multipart": "^7.7.3",
"@fastify/static": "^6.10.2",
"@fastify/view": "^8.0.0",
"@fastify/websocket": "^8.2.0",
"@types/mime-types": "^2.1.1",
"@vrite/backend": "workspace:*",
"axios": "^1.4.0"
"axios": "^1.4.0",
"fastify": "^4.20.0",
"handlebars": "^4.7.8",
"mime-types": "^2.1.35",
"nanoid": "^4.0.2",
"sharp": "^0.32.5"
},
"devDependencies": {
"@vrite/scripts": "workspace:*"
"@vrite/scripts": "workspace:*",
"@vrite/web": "workspace:*"
}
}

0 comments on commit d8c9421

Please sign in to comment.