Skip to content

Commit

Permalink
feat: cleanup env variales for docker setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dahal committed May 19, 2024
1 parent 6f99d30 commit 5969034
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 43 deletions.
11 changes: 3 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ NEXTAUTH_URL="http://localhost:3000"
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 server
EMAIL_FROM="Captable <[email protected]>"
EMAIL_SERVER=smtp://captable:password@localhost:2500

# Uploads
UPLOAD_PROVIDER="s3"
Expand Down
48 changes: 47 additions & 1 deletion SELF-HOSTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,50 @@ 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
BASE_URL="https://your-domain.com"
DATABASE_URL="postgres://user:password@host:port/dbname"
NEXTAUTH_SECRET="xxx" # Generated by `openssl rand -base64 32`

# Email server environment variables
EMAIL_FROM="[email protected]"
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"
```

- **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": [
"*"
]
}
]
```
32 changes: 8 additions & 24 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,30 @@ ARG BASE_URL
ARG DATABASE_URL
ARG NEXTAUTH_SECRET
# SMTP environment variables
ARG EMAIL_SERVER_HOST
ARG EMAIL_SERVER_PORT
ARG EMAIL_SERVER_USERNAME
ARG EMAIL_SERVER_PASSWORD
ARG EMAIL_SERVER_SECURE
ARG EMAIL_FROM
ARG EMAIL_SERVER
# File uplod environment variables
ARG UPLOAD_REGION
ARG UPLOAD_PROVIDER
ARG UPLOAD_ENDPOINT
ARG UPLOAD_ACCESS_KEY_ID
ARG UPLOAD_SECRET_ACCESS_KEY
ARG UPLOAD_BUCKET_PUBLIC
ARG UPLOAD_BUCKET_PRIVATE

# Set environment variables
ENV NODE_ENV="production" \
ENV DOCKER_OUTPUT=1 \
NODE_ENV="production" \
BASE_URL=$BASE_URL \
SKIP_ENV_VALIDATION=1 \
NEXT_TELEMETRY_DISABLED=1 \
DATABASE_URL=$DATABASE_URL \
NEXTAUTH_SECRET=$NEXTAUTH_SECRET \
NEXTAUTH_URL=$BASE_URL \
NEXT_PUBLIC_BASE_URL=$BASE_URL \
NEXT_PUBLIC_NODE_ENV="production" \
EMAIL_SERVER_HOST=$EMAIL_SERVER_HOST \
EMAIL_SERVER_PORT=$EMAIL_SERVER_PORT \
EMAIL_SERVER_USERNAME=$EMAIL_SERVER_USERNAME \
EMAIL_SERVER_PASSWORD=$EMAIL_SERVER_PASSWORD \
EMAIL_SERVER_SECURE=$EMAIL_SERVER_SECURE \
EMAIL_SERVER=${EMAIL_SERVER} \
EMAIL_FROM=$EMAIL_FROM \
UPLOAD_PROVIDER=$UPLOAD_PROVIDER \
UPLOAD_PROVIDER="s3" \
UPLOAD_ENDPOINT=$UPLOAD_ENDPOINT \
NEXT_PUBLIC_UPLOAD_DOMAIN=$UPLOAD_ENDPOINT \
UPLOAD_REGION=$UPLOAD_REGION \
Expand All @@ -67,22 +61,13 @@ COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/prisma ./prisma
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1
ENV DOCKER_OUTPUT 1
ENV SKIP_ENV_VALIDATION 1
# Build the app
RUN corepack enable pnpm && pnpm run build

##### RUNNER
FROM base AS runner
WORKDIR /app

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

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

Expand All @@ -105,7 +90,6 @@ COPY --from=builder --chown=nextjs:nodejs /app/prisma/migrations ./prisma/migrat
USER nextjs

# Run the migration script
ENV DATABASE_URL=$DATABASE_URL
RUN chmod +x ./scripts/migrate.sh
RUN ./scripts/migrate.sh

Expand Down
23 changes: 13 additions & 10 deletions src/server/mailer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ const getTransport = () => {
}

return createTransport({
host: env.EMAIL_SERVER_HOST,
port: env.EMAIL_SERVER_PORT,
secure: env.EMAIL_SERVER_SECURE,
...(env.EMAIL_SERVER_PASSWORD &&
env.EMAIL_SERVER_USERNAME && {
auth: {
user: env.EMAIL_SERVER_USERNAME,
pass: env.EMAIL_SERVER_PASSWORD,
},
}),
url: env.EMAIL_SERVER,
});
// return createTransport({
// host: env.EMAIL_SERVER_HOST,
// port: env.EMAIL_SERVER_PORT,
// secure: env.EMAIL_SERVER_SECURE,
// ...(env.EMAIL_SERVER_PASSWORD &&
// env.EMAIL_SERVER_USERNAME && {
// auth: {
// user: env.EMAIL_SERVER_USERNAME,
// pass: env.EMAIL_SERVER_PASSWORD,
// },
// }),
// });
};

export const sendMail = (options: Omit<SendMailOptions, "from">) => {
Expand Down

0 comments on commit 5969034

Please sign in to comment.