Skip to content

Commit

Permalink
Merge pull request #337 from captableinc/debug
Browse files Browse the repository at this point in the history
feat: getting deployable version ready with docker and env changes
  • Loading branch information
dahal authored May 20, 2024
2 parents 3e7831a + 194c453 commit c9455d7
Show file tree
Hide file tree
Showing 125 changed files with 1,252 additions and 2,153 deletions.
31 changes: 7 additions & 24 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@
# Next.js environment variables
NODE_ENV="development"
NEXT_PUBLIC_NODE_ENV="development"
BASE_URL="http://localhost:3000"
NEXT_PUBLIC_BASE_URL="http://localhost:3000"

# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry
# Uncomment the following line to disable telemetry at run time
NEXT_TELEMETRY_DISABLED=1
# Disable telemetry at run time
NEXT_TELEMETRY_DISABLED=1 # Injected in Dockerfile

# Prisma
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
DATABASE_URL="postgres://captable:[email protected]:54321/captable"
DATABASE_URL="postgres://captable:password@pg:5432/captable"

# Next Auth
# You can generate a new secret on the command line with:
# https://next-auth.js.org/configuration/options#secret

# openssl rand -base64 32
# Run `openssl rand -base64 32` to generate a new secret
NEXTAUTH_SECRET="xxxxxxxxxx"
NEXTAUTH_URL="http://localhost:3000"

Expand All @@ -36,24 +30,13 @@ GOOGLE_CLIENT_ID="xxxxxxxxxx"
GOOGLE_CLIENT_SECRET="xxxxxxxxxx"

# SMTP
EMAIL_SERVER_HOST="localhost"
EMAIL_SERVER_PORT=1025
EMAIL_SERVER_USERNAME="captable"
EMAIL_SERVER_PASSWORD="password"
EMAIL_SERVER_SECURE=0
# EMAIL_SERVER=smtp://captable:[email protected]:2500
EMAIL_FROM=[email protected]
EMAIL_FROM="'Captable, Inc.' <[email protected]>"
EMAIL_SERVER=smtp://captable:password@localhost:1025

# Uploads
UPLOAD_PROVIDER="s3"
UPLOAD_ENDPOINT="http://127.0.0.1:9002"
NEXT_PUBLIC_UPLOAD_DOMAIN="http://127.0.0.1:9002"

# value should be 'auto' while using r2
UPLOAD_REGION="us-east-1"
UPLOAD_REGION="us-east-1" # value should be 'auto' while using r2
UPLOAD_ACCESS_KEY_ID="captable"
UPLOAD_SECRET_ACCESS_KEY="password"

UPLOAD_BUCKET_PUBLIC="captable-public-bucket"
UPLOAD_BUCKET_PRIVATE="captable-private-bucket"

1 change: 0 additions & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ tasks:
pnpm install &&
cp .env.example .env &&
export NEXTAUTH_SECRET="$(openssl rand -base64 32)" &&
export BASE_URL="$(gp url 3000)" &&
export NEXT_PUBLIC_BASE_URL="$(gp url 3000)" &&
export EMAIL_SERVER_PORT=2500
command: pnpm db:migrate && pnpm dx
Expand Down
88 changes: 87 additions & 1 deletion SELF-HOSTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,90 @@ If you like to self-host Captable, Inc., please schedule a call with us, and we

- **Official Docker Images**:
- <a href="https://hub.docker.com/r/captable/captable" target="_blank">Docker hub</a>
- <a href="https://github.com/captableinc/captable/pkgs/container/captable" target="_blank">Github registry</a>
<!-- - <a href="https://github.com/captableinc/captable/pkgs/container/captable" target="_blank">Github registry</a> -->

- **Environment Variables**:\
Following envrionment variables are required

```bash
NODE_ENV="production"
DATABASE_URL="postgres://user:password@host:port/dbname"
NEXTAUTH_SECRET="xxx" # Generated by `openssl rand -base64 32`
NEXTAUTH_URL="https://your-domain.com"
NEXT_PUBLIC_BASE_URL="https://your-domain.com"

# Email server environment variables
EMAIL_FROM="[email protected]"

# Please use encrypted/TLS connection for SMTP server.
EMAIL_SERVER="smtp://username:password@host:port"

# File uplod environment variables
UPLOAD_REGION="us-west-1" # auto when using Cloudflare R2
UPLOAD_ENDPOINT="https://xxx.r2.cloudflarestorage.com"
UPLOAD_ACCESS_KEY_ID="xxx"
UPLOAD_SECRET_ACCESS_KEY="xxx"
UPLOAD_BUCKET_PUBLIC="public-bucket-name"
UPLOAD_BUCKET_PRIVATE="private-bucket-name"
```

- **Run the docker container**:

```bash
docker run -d \
-e NODE_ENV="replace" \
-e DATABASE_URL="replace" \
-e NEXTAUTH_SECRET="replace" \
-e NEXTAUTH_URL="replace" \
-e NEXT_PUBLIC_BASE_URL="replace" \
-e EMAIL_FROM="replace" \
-e EMAIL_SERVER="replace" \
-e UPLOAD_REGION="replace" \
-e UPLOAD_ENDPOINT="replace" \
-e UPLOAD_ACCESS_KEY_ID="replace" \
-e UPLOAD_SECRET_ACCESS_KEY="replace" \
-e UPLOAD_BUCKET_PUBLIC="replace" \
-e UPLOAD_BUCKET_PRIVATE="replace" \
-p 3000:3000 \
captable/captable
```

- **Setup CORS for file uploads**:\
Some of the services including Cloudflare R2 may require you to setup CORS for file uploads.\

> Here is an sample CORS configuration for Cloudflare R2.
```json
[
{
"AllowedOrigins": [
"https://your-domain.com"
],
"AllowedMethods": [
"HEAD",
"GET",
"POST",
"PUT",
"DELETE"
],
"AllowedHeaders": [
"*"
]
}
]
```

- **Run database migrations**:

```bash
docker exec -it <container_id> npx prisma migrate deploy
```

<!-- Ready -->
- **Access the application**:\
Open your browser and navigate to `https://your-domain.com`

- **Questions?**\
If you have any questions, please schedule a call with us, and we will help you set up your own instance.

<a href="https://captable.inc/schedule/"><img alt="Book us" src="https://cal.com/book-with-cal-dark.svg" /></a>
1 change: 1 addition & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- POSTGRES_USER=captable
- POSTGRES_PASSWORD=password
- POSTGRES_DB=captable
- POSTGRES_EXTENSIONS=pgcrypto
ports:
- 54321:5432
volumes:
Expand Down
6 changes: 5 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED 1

ENV DOCKER_OUTPUT 1
Expand All @@ -63,12 +62,17 @@ COPY --from=builder --chown=nextjs:nodejs /app/scripts/migrate.sh ./scripts/migr
COPY --from=builder --chown=nextjs:nodejs /app/prisma/schema.prisma ./prisma/schema.prisma
COPY --from=builder --chown=nextjs:nodejs /app/prisma/migrations ./prisma/migrations


USER nextjs

EXPOSE 3000

ENV PORT 3000

# Run the migration script
# RUN chmod +x ./scripts/migrate.sh
# ENTRYPOINT [ "./scripts/migrate.sh" ]

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD HOSTNAME="0.0.0.0" node server.js
2 changes: 1 addition & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cpus = 1

[deploy]
strategy = "canary"
release_command = "sh ./scripts/migrate.sh"
# release_command = "sh ./scripts/migrate.sh"

[env]
NODE_ENV = "production"
Loading

0 comments on commit c9455d7

Please sign in to comment.