Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove middle from the app workflows #52

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM python:3.11-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Install Poetry
RUN pip install poetry

# Copy application code
COPY . .

# Configure poetry to not create a virtual environment
RUN poetry config virtualenvs.create false

# Install dependencies
RUN poetry install

# run migrations
RUN make migrate

# Expose the port the app runs on
EXPOSE 8000

# Command to run the application
CMD ["poetry", "run", "uvicorn", "app.main:app", "--workers", "2", "--host", "0.0.0.0", "--port", "8000"]
4 changes: 2 additions & 2 deletions backend/app/api/v1/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_process(process_id: int, db: Session = Depends(get_db)):
}


@process_router.get("/")
@process_router.get("")
def get_processes(db: Session = Depends(get_db)):
processes = process_repository.get_processes(db=db)

Expand Down Expand Up @@ -530,4 +530,4 @@ def get_process_suggestion(

except Exception as e:
logger.error(f"Error retrieving file: {str(e)}\n{traceback.format_exc()}")
raise HTTPException(status_code=500, detail="Failed to retrieve file")
raise HTTPException(status_code=500, detail="Failed to retrieve file")
4 changes: 2 additions & 2 deletions backend/app/api/v1/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
logger = Logger()


@project_router.post("/", status_code=201)
@project_router.post("", status_code=201)
def create_project(project: ProjectCreate, db: Session = Depends(get_db)):
if not project.name.strip():
raise HTTPException(
Expand All @@ -38,7 +38,7 @@ def create_project(project: ProjectCreate, db: Session = Depends(get_db)):
}


@project_router.get("/")
@project_router.get("")
def get_projects(
page: int = Query(1, ge=1),
page_size: int = Query(100, ge=1, le=100),
Expand Down
1 change: 0 additions & 1 deletion backend/app/api/v1/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def save_user_api_key(
raise HTTPException(
status_code=400, detail="Invalid API Key"
)

user_repository.update_user_api_key(db, users[0].id, api_key_request.api_key)

return {
Expand Down
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: "3.8"

services:
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: panda-etl-backend
ports:
- "5328:5328"
volumes:
- ./instance:/app/instance
- ./uploads:/app/uploads
- ./processed:/app/processed
environment:
- ENV=production
restart: unless-stopped
command: >
sh -c "poetry run alembic upgrade head && poetry run uvicorn app.main:app --host 0.0.0.0 --port 5328"

frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: panda-etl-frontend
ports:
- "3000:3000"
environment:
- NODE_ENV=production
depends_on:
- backend
restart: unless-stopped
extra_hosts:
- "host.docker.internal:host-gateway"
29 changes: 29 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use Node.js as the base image
FROM node:18-alpine AS builder

# Set working directory
WORKDIR /app

# Copy package.json and install dependencies
COPY package.json package-lock.json ./
RUN npm install --frozen-lockfile

# Copy the entire frontend code
COPY . .

# Build Next.js application
RUN npm run build

# Use a minimal base image for production
FROM node:18-alpine

WORKDIR /app

# Copy built files from builder
COPY --from=builder /app ./

# Expose frontend port
EXPOSE 3000

# Start Next.js
CMD ["npm", "run", "start"]
10 changes: 5 additions & 5 deletions frontend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ const nextConfig = {
swcMinify: false, // TODO - track and remove this later: https://github.com/wojtekmaj/react-pdf/issues/1822
async rewrites() {
return [
{
source: "/api/:path*",
destination: "http://127.0.0.1:5328/:path*",
},
// {
// source: "/api/:path*",
// destination: "http://localhost:5328/:path*",
// },
{
source: "/assets/:path*",
destination: "http://127.0.0.1:5328/assets/:path*",
destination: "http://localhost:5328/assets/:path*",
},
];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ProcessPage = () => {
setIsLoading(true);
try {
const response = await fetch(
`${BASE_API_URL}/${processApiUrl}/${processId}/get-csv`
`${BASE_API_URL}${processApiUrl}/${processId}/get-csv`
);
const {
data: { csv },
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ export async function middleware(request: NextRequest) {
try {
apiKey = await GetAPIKey();
} catch (error) {
console.error("Error fetching API key:", error);
return NextResponse.redirect(new URL("/api-key-setup", request.url));
}

if (!apiKey && !request.nextUrl.pathname.startsWith("/api-key-setup")) {
console.log("No API key found. Redirecting to /api-key-setup");
return NextResponse.redirect(new URL("/api-key-setup", request.url));
}

Expand Down