Skip to content

Commit 165d421

Browse files
authored
fix: remove middle from the app workflows (#52)
* fix: remove middle from the app workflows * feat(docker): add docker compose and docker files
1 parent 2068c4b commit 165d421

File tree

9 files changed

+104
-11
lines changed

9 files changed

+104
-11
lines changed

backend/Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM python:3.11-slim
2+
3+
WORKDIR /app
4+
5+
# Install system dependencies
6+
RUN apt-get update && apt-get install -y \
7+
build-essential \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# Install Poetry
11+
RUN pip install poetry
12+
13+
# Copy application code
14+
COPY . .
15+
16+
# Configure poetry to not create a virtual environment
17+
RUN poetry config virtualenvs.create false
18+
19+
# Install dependencies
20+
RUN poetry install
21+
22+
# run migrations
23+
RUN make migrate
24+
25+
# Expose the port the app runs on
26+
EXPOSE 8000
27+
28+
# Command to run the application
29+
CMD ["poetry", "run", "uvicorn", "app.main:app", "--workers", "2", "--host", "0.0.0.0", "--port", "8000"]

backend/app/api/v1/processes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def get_process(process_id: int, db: Session = Depends(get_db)):
6161
}
6262

6363

64-
@process_router.get("/")
64+
@process_router.get("")
6565
def get_processes(db: Session = Depends(get_db)):
6666
processes = process_repository.get_processes(db=db)
6767

@@ -530,4 +530,4 @@ def get_process_suggestion(
530530

531531
except Exception as e:
532532
logger.error(f"Error retrieving file: {str(e)}\n{traceback.format_exc()}")
533-
raise HTTPException(status_code=500, detail="Failed to retrieve file")
533+
raise HTTPException(status_code=500, detail="Failed to retrieve file")

backend/app/api/v1/projects.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
logger = Logger()
2424

2525

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

4040

41-
@project_router.get("/")
41+
@project_router.get("")
4242
def get_projects(
4343
page: int = Query(1, ge=1),
4444
page_size: int = Query(100, ge=1, le=100),

backend/app/api/v1/user.py

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def save_user_api_key(
4242
raise HTTPException(
4343
status_code=400, detail="Invalid API Key"
4444
)
45-
4645
user_repository.update_user_api_key(db, users[0].id, api_key_request.api_key)
4746

4847
return {

docker-compose.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: "3.8"
2+
3+
services:
4+
backend:
5+
build:
6+
context: ./backend
7+
dockerfile: Dockerfile
8+
container_name: panda-etl-backend
9+
ports:
10+
- "5328:5328"
11+
volumes:
12+
- ./instance:/app/instance
13+
- ./uploads:/app/uploads
14+
- ./processed:/app/processed
15+
environment:
16+
- ENV=production
17+
restart: unless-stopped
18+
command: >
19+
sh -c "poetry run alembic upgrade head && poetry run uvicorn app.main:app --host 0.0.0.0 --port 5328"
20+
21+
frontend:
22+
build:
23+
context: ./frontend
24+
dockerfile: Dockerfile
25+
container_name: panda-etl-frontend
26+
ports:
27+
- "3000:3000"
28+
environment:
29+
- NODE_ENV=production
30+
depends_on:
31+
- backend
32+
restart: unless-stopped
33+
extra_hosts:
34+
- "host.docker.internal:host-gateway"

frontend/Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Use Node.js as the base image
2+
FROM node:18-alpine AS builder
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Copy package.json and install dependencies
8+
COPY package.json package-lock.json ./
9+
RUN npm install --frozen-lockfile
10+
11+
# Copy the entire frontend code
12+
COPY . .
13+
14+
# Build Next.js application
15+
RUN npm run build
16+
17+
# Use a minimal base image for production
18+
FROM node:18-alpine
19+
20+
WORKDIR /app
21+
22+
# Copy built files from builder
23+
COPY --from=builder /app ./
24+
25+
# Expose frontend port
26+
EXPOSE 3000
27+
28+
# Start Next.js
29+
CMD ["npm", "run", "start"]

frontend/next.config.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const nextConfig = {
22
swcMinify: false, // TODO - track and remove this later: https://github.com/wojtekmaj/react-pdf/issues/1822
33
async rewrites() {
44
return [
5-
{
6-
source: "/api/:path*",
7-
destination: "http://127.0.0.1:5328/:path*",
8-
},
5+
// {
6+
// source: "/api/:path*",
7+
// destination: "http://localhost:5328/:path*",
8+
// },
99
{
1010
source: "/assets/:path*",
11-
destination: "http://127.0.0.1:5328/assets/:path*",
11+
destination: "http://localhost:5328/assets/:path*",
1212
},
1313
];
1414
},

frontend/src/app/(editor)/projects/[projectId]/processes/[processId]/csv/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const ProcessPage = () => {
3535
setIsLoading(true);
3636
try {
3737
const response = await fetch(
38-
`${BASE_API_URL}/${processApiUrl}/${processId}/get-csv`
38+
`${BASE_API_URL}${processApiUrl}/${processId}/get-csv`
3939
);
4040
const {
4141
data: { csv },

frontend/src/middleware.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ export async function middleware(request: NextRequest) {
88
try {
99
apiKey = await GetAPIKey();
1010
} catch (error) {
11+
console.error("Error fetching API key:", error);
1112
return NextResponse.redirect(new URL("/api-key-setup", request.url));
1213
}
1314

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

0 commit comments

Comments
 (0)