Skip to content

Commit

Permalink
Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Feb 14, 2024
1 parent a37de1a commit 851de89
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 33 deletions.
34 changes: 22 additions & 12 deletions .github/workflows/preview-dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,28 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Generate slug
uses: rlespinasse/github-slug-action@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: "1.0.26"
- name: Install dependencies
run: bun install --frozen-lockfile
- name: 📤 Pull Vercel Environment Information
run: bunx vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: 🏗 Build Project Artifacts
run: bunx vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: |
bunx vercel deploy --prebuilt --archive=tgz --token=${{ secrets.VERCEL_TOKEN }} > domain.txt
bunx vercel alias --scope=${{ secrets.VERCEL_ORG_ID }} --token=${{ secrets.VERCEL_TOKEN }} set `cat domain.txt` ${{ env.GITHUB_REF_SLUG }}.app.midday.ai
- name: ⚡ Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: 🐳 Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: 🐳 Docker build
uses: docker/build-push-action@v4
with:
context: .
file: apps/dashboard/Dockerfile
push: true
tags: registry.fly.io/midday-dashboard:preview-${{ github.sha }}
build-args: |
TURBO_TEAM=${{ secrets.TURBO_TOKEN }}
TURBO_TOKEN=${{ secrets.TURBO_TEAM }}
provenance: false
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
35 changes: 35 additions & 0 deletions apps/dashboard/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Dependency directories
node_modules
**/node_modules

# Log files
*.log

# Version control
.git

# System files
.DS_Store
Thumbs.db

# Editor directories
.idea/
.vscode/

# Build outputs
dist/
build/
out/
.coverage/
.turbo/
.next/

# Documentation & Tests
*.md
LICENSE
test/
tests/
__tests__/

# Environment configs
.env*
111 changes: 111 additions & 0 deletions apps/dashboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
FROM oven/bun:1 as base

ARG API_ROUTE_SECRET
ENV API_ROUTE_SECRET=$API_ROUTE_SECRET

ARG DUB_API_KEY
ENV DUB_API_KEY=$DUB_API_KEY

ARG EDGE_CONFIG
ENV EDGE_CONFIG=$EDGE_CONFIG

ARG GOCARDLESS_SECRET_ID
ENV GOCARDLESS_SECRET_ID=$GOCARDLESS_SECRET_ID

ARG GOCARDLESS_SECRET_KEY
ENV GOCARDLESS_SECRET_KEY=$GOCARDLESS_SECRET_KEY

ARG LOGSNAG_PRIVATE_TOKEN
ENV LOGSNAG_PRIVATE_TOKEN=$LOGSNAG_PRIVATE_TOKEN

ARG LOOPS_API_KEY
ENV LOOPS_API_KEY=$LOOPS_API_KEY

ARG LOOPS_ENDPOINT
ENV LOOPS_ENDPOINT=$LOOPS_ENDPOINT

ARG NOVU_API_KEY
ENV NOVU_API_KEY=$NOVU_API_KEY

ARG OPENAI_API_KEY
ENV OPENAI_API_KEY=$OPENAI_API_KEY

ARG PLAID_CLIENT_ID
ENV PLAID_CLIENT_ID=$PLAID_CLIENT_ID

ARG PLAID_CLIENT_SECRET
ENV PLAID_CLIENT_SECRET=$PLAID_CLIENT_SECRET

ARG RESEND_API_KEY
ENV RESEND_API_KEY=$RESEND_API_KEY

ARG SUPABASE_SERVICE_KEY
ENV SUPABASE_SERVICE_KEY=$SUPABASE_SERVICE_KEY

ARG TRIGGER_API_KEY
ENV TRIGGER_API_KEY=$TRIGGER_API_KEY

ARG TRIGGER_API_URL
ENV TRIGGER_API_URL=$TRIGGER_API_URL

ARG UPSTASH_REDIS_REST_TOKEN
ENV UPSTASH_REDIS_REST_TOKEN=$UPSTASH_REDIS_REST_TOKEN

ARG UPSTASH_REDIS_REST_URL
ENV UPSTASH_REDIS_REST_URL=$UPSTASH_REDIS_REST_URL

ARG NEXT_PUBLIC_LOGSNAG_PROJECT
ENV NEXT_PUBLIC_LOGSNAG_PROJECT=$NEXT_PUBLIC_LOGSNAG_PROJECT

ARG NEXT_PUBLIC_LOGSNAG_TOKEN
ENV NEXT_PUBLIC_LOGSNAG_TOKEN=$NEXT_PUBLIC_LOGSNAG_TOKEN

ARG NEXT_PUBLIC_NOVU_APPLICATION_IDENTIFIER
ENV NEXT_PUBLIC_NOVU_APPLICATION_IDENTIFIER=$NEXT_PUBLIC_NOVU_APPLICATION_IDENTIFIER

ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
ENV NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY

ARG NEXT_PUBLIC_SUPABASE_ID
ENV NEXT_PUBLIC_SUPABASE_ID=$NEXT_PUBLIC_SUPABASE_ID

ARG NEXT_PUBLIC_SUPABASE_URL
ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL

ARG NEXT_PUBLIC_SUPABASE_URL
ENV NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL

ARG NEXT_PUBLIC_TRIGGER_API_KEY
ENV NEXT_PUBLIC_TRIGGER_API_KEY=$NEXT_PUBLIC_TRIGGER_API_KEY


# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
WORKDIR /app

# First install the dependencies (as they change less often)
COPY . .
RUN bun install --frozen-lockfile

# Build the project
RUN bun run build --filter=@midday/dashboard

FROM base AS runner
WORKDIR /app

# Don't run production as root
RUN adduser --system --uid 1001 dashboard
USER dashboard

ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production

COPY --from=installer /app/apps/dashboard/next.config.mjs .

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=installer --chown=dashboard:bun /app/apps/dashboard/.next/standalone ./
COPY --from=installer --chown=dashboard:bun /app/apps/dashboard/.next/static ./apps/dashboard/.next/static
COPY --from=installer --chown=dashboard:bun /app/apps/dashboard/public ./apps/dashboard/public

CMD node apps/dashboard/server.js
11 changes: 6 additions & 5 deletions apps/dashboard/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import path from "path";
import "./src/env.mjs";

import withBundleAnalyzer from "@next/bundle-analyzer";

/** @type {import("next").NextConfig} */
const config = {
reactStrictMode: true,
Expand Down Expand Up @@ -33,8 +31,11 @@ const config = {
typescript: {
ignoreBuildErrors: true,
},
output: "standalone",
experimental: {
taint: true,
outputFileTracingRoot: path.resolve("../../"),
},
};

export default withBundleAnalyzer({
enabled: process.env.ANALYZE === "true",
})(config);
export default config;
3 changes: 1 addition & 2 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": true,
"scripts": {
"build": "NODE_ENV=production next build",
"build": "next build",
"clean": "git clean -xdf .next .turbo node_modules",
"jobs": "bunx @trigger.dev/cli@latest dev -p 3001 --client-id=midday-G6Yq",
"dev": "next dev -p 3001",
Expand All @@ -22,7 +22,6 @@
"@midday/notification": "workspace:*",
"@midday/supabase": "workspace:*",
"@midday/ui": "workspace:*",
"@next/bundle-analyzer": "^14.1.0",
"@novu/headless": "^0.23.1",
"@tanstack/react-table": "^8.11.8",
"@todesktop/client-active-win": "^0.15.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/api/auth/callback/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { cookies } from "next/headers";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export const runtime = "edge";
export const preferredRegion = "fra1";
// export const runtime = "edge";
// export const preferredRegion = "fra1";

export async function GET(req: NextRequest) {
const cookieStore = cookies();
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/api/download/file/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { getUser } from "@midday/supabase/cached-queries";
import { createClient } from "@midday/supabase/server";
import { download } from "@midday/supabase/storage";

export const preferredRegion = "fra1";
export const runtime = "edge";
// export const preferredRegion = "fra1";
// export const runtime = "edge";

export async function GET(req, res) {
const supabase = createClient();
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/api/download/zip/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { createClient } from "@midday/supabase/server";
import { download } from "@midday/supabase/storage";
import { BlobReader, BlobWriter, ZipWriter } from "@zip.js/zip.js";

export const preferredRegion = "fra1";
export const runtime = "edge";
// export const preferredRegion = "fra1";
// export const runtime = "edge";
export const dynamic = "force-dynamic";

export async function GET(req, res) {
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/api/gocardless/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { createClient } from "@midday/supabase/server";
import { NextResponse } from "next/server";

export const dynamic = "force-dynamic";
export const preferredRegion = "fra1";
export const runtime = "edge";
// export const preferredRegion = "fra1";
// export const runtime = "edge";

export async function GET(req) {
const supabase = createClient();
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/app/api/trigger/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { client } from "@midday/jobs";
import { createAppRoute } from "@trigger.dev/nextjs";

export const runtime = "nodejs";
// export const runtime = "nodejs";
export const maxDuration = 300; // 5min

import "@midday/jobs";
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/app/api/webhook/inbox/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { decode } from "base64-arraybuffer";
import { revalidateTag } from "next/cache";
import { headers } from "next/headers";

export const runtime = "nodejs";
// export const runtime = "nodejs";
export const maxDuration = 300; // 5min
export const dynamic = "force-dynamic";

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/components/tracker-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { TrackerDayCard } from "./tracker-day-card";
export function TrackerGraph() {
const [data, setData] = useState();
const [meta, setMeta] = useState();
const weekStartsOn = 1; // Monday
const weekStartsOn = 1; // NOTE: Monday, should be a user setting
const supabase = createClient();

const currentDate = new Date();
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/components/tracker-month-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function TrackerMonthGraph({
projectId,
disableHover,
}) {
const weekStartsOn = 1;
const weekStartsOn = 1; // NOTE: Monday, should be a user setting
const { isTracking } = useTrackerStore();
const currentDate = new Date(date);

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ export const env = createEnv({
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
API_ROUTE_SECRET: process.env.API_ROUTE_SECRET,
},
skipValidation: !!process.env.CI || !!process.env.SKIP_ENV_VALIDATION,
skipValidation: true,
});
2 changes: 1 addition & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": true,
"scripts": {
"build": "NODE_ENV=production next build",
"build": "next build",
"clean": "git clean -xdf .next .turbo node_modules",
"dev": "next dev -p 3000",
"lint": "next lint",
Expand Down
Binary file modified bun.lockb
Binary file not shown.

0 comments on commit 851de89

Please sign in to comment.