feat(prod): production stage for frontend
This commit is contained in:
@@ -3,12 +3,29 @@ FROM oven/bun:1.2.18-alpine@sha256:a7df687a2f684ee2f7404e2592039e192d75d26a04f84
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
COPY package.json bun.lock ./
|
COPY frontend/package.json frontend/bun.lock ./
|
||||||
RUN bun install --frozen-lockfile
|
RUN bun install --frozen-lockfile
|
||||||
|
|
||||||
|
# ------ Build stage ------
|
||||||
|
FROM deps AS build
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy code, and compile
|
||||||
|
COPY frontend/ .
|
||||||
|
RUN bun run build
|
||||||
|
|
||||||
# ------ Development stage ------
|
# ------ Development stage ------
|
||||||
FROM deps AS dev
|
FROM deps AS dev
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
CMD ["bun", "run", "dev"]
|
CMD ["bun", "run", "dev"]
|
||||||
|
|
||||||
|
# ------ Production stage ------
|
||||||
|
FROM caddy:2.10.0-alpine@sha256:e2e3a089760c453bc51c4e718342bd7032d6714f15b437db7121bfc2de2654a6 AS prod
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy built code
|
||||||
|
COPY --from=build /app/dist .
|
||||||
|
|
||||||
|
# Copy configuration for caddy
|
||||||
|
COPY caddy/prod /etc/caddy/Caddyfile
|
||||||
|
|||||||
@@ -5,9 +5,16 @@
|
|||||||
|
|
||||||
:8080 {
|
:8080 {
|
||||||
encode
|
encode
|
||||||
reverse_proxy frontend:3000
|
|
||||||
|
|
||||||
|
# Proxy to backend
|
||||||
handle_path /api* {
|
handle_path /api* {
|
||||||
reverse_proxy backend:8080
|
reverse_proxy backend:8080
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Server static files
|
||||||
|
handle_path /* {
|
||||||
|
root * /app
|
||||||
|
try_files {path} /index.html
|
||||||
|
file_server
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
frontend:
|
frontend:
|
||||||
build:
|
build:
|
||||||
context: ./frontend
|
context: .
|
||||||
dockerfile: ../Dockerfile.frontend
|
dockerfile: Dockerfile.frontend
|
||||||
target: dev # Development stage
|
target: dev # Development stage
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
container_name: cover-letter-frontend
|
container_name: cover-letter-frontend
|
||||||
|
|||||||
@@ -6,10 +6,9 @@ import type { TokenUserInfo } from "@/types/api";
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
className?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Authorised({ children, className = "" }: Props) {
|
export default function Authorised({ children }: Props) {
|
||||||
// Check authentication
|
// Check authentication
|
||||||
useQuery({
|
useQuery({
|
||||||
queryKey: ["user_info"],
|
queryKey: ["user_info"],
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { StrictMode } from "react";
|
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
import { RouterProvider, createRouter } from "@tanstack/react-router";
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle }
|
|||||||
import { useAppForm } from "@/hooks/formHook";
|
import { useAppForm } from "@/hooks/formHook";
|
||||||
import Guest from "@/layouts/Guest";
|
import Guest from "@/layouts/Guest";
|
||||||
import requests from "@/lib/requests";
|
import requests from "@/lib/requests";
|
||||||
import { createFileRoute, Link, redirect, useNavigate } from "@tanstack/react-router";
|
import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import * as z from "zod/v4";
|
import * as z from "zod/v4";
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// @ts-nocheck
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import viteReact from "@vitejs/plugin-react";
|
import viteReact from "@vitejs/plugin-react";
|
||||||
import tailwindcss from "@tailwindcss/vite";
|
import tailwindcss from "@tailwindcss/vite";
|
||||||
|
|||||||
@@ -21,33 +21,18 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
db: # Wait for database to be ready (Pass healthcheck)
|
db: # Wait for database to be ready (Pass healthcheck)
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
# frontend:
|
frontend:
|
||||||
# build:
|
build:
|
||||||
# context: ./frontend
|
context: .
|
||||||
# dockerfile: ../Dockerfile.frontend
|
dockerfile: Dockerfile.frontend
|
||||||
# target: dev # Development stage
|
target: prod # Development stage
|
||||||
# restart: unless-stopped
|
restart: unless-stopped
|
||||||
# container_name: cover-letter-frontend
|
container_name: cover-letter-frontend
|
||||||
#
|
|
||||||
# volumes:
|
ports:
|
||||||
# - "./frontend:/app" # Mount frontend
|
- 80:8080
|
||||||
# - "/app/node_modules" # Ignore node_modules
|
networks:
|
||||||
# networks:
|
- cover-letter-network
|
||||||
# - cover-letter-network
|
|
||||||
# proxy:
|
|
||||||
# image: caddy:alpine
|
|
||||||
# restart: unless-stopped
|
|
||||||
# container_name: cover-letter-proxy
|
|
||||||
#
|
|
||||||
# networks:
|
|
||||||
# - cover-letter-network
|
|
||||||
# volumes:
|
|
||||||
# - ./caddy/Caddyfile:/etc/caddy/Caddyfile
|
|
||||||
# ports:
|
|
||||||
# - 8000:8080
|
|
||||||
# depends_on:
|
|
||||||
# - frontend
|
|
||||||
# - backend
|
|
||||||
db:
|
db:
|
||||||
image: postgres:13.21-alpine3.22
|
image: postgres:13.21-alpine3.22
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# export file="development.yml"
|
export file="development.yml"
|
||||||
export file="production.yml"
|
# export file="production.yml"
|
||||||
|
|||||||
Reference in New Issue
Block a user