Skip to content

Commit

Permalink
Added Docker to build image
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-holzner committed Sep 29, 2024
1 parent 0f8fbed commit 986ee80
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Start with a Node.js base image for building the frontend
FROM node:20 AS frontend-build

# Set working directory for frontend
WORKDIR /app/frontend

# Copy frontend files
COPY frontend/package*.json ./

# Install frontend dependencies
RUN npm install

# Copy the rest of the frontend code
COPY frontend/ ./

# Build the frontend
RUN npm run build

# Start a new stage with a Python base image for the backend
FROM python:3.10

# Set working directory for backend
WORKDIR /app

# Copy backend requirements and install dependencies
COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the backend code
COPY backend/ .

# Copy the built frontend files to the backend's static directory
COPY --from=frontend-build /app/frontend/build /app/frontend

# Expose the port the app runs on
EXPOSE 8000

# Command to run the application
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Hackathon CodeFusion

This project combines a FastAPI backend with a React frontend, containerized using Docker.

## Building and Running with Docker

### Production Build

To build and run the production version of the application:

1. Ensure you have Docker installed on your system.

2. Clone this repository and navigate to the project root directory.

3. Build the Docker image:
```
docker build -t fastapi-react-app .
```

4. Run the container:
```
docker run -p 8000:8000 fastapi-react-app
```

5. Access the application at `http://localhost:8000`


## Project Structure

- `backend/`: Contains the FastAPI application
- `frontend/`: Contains the React application
- `Dockerfile`: Defines the production Docker image

## API Documentation

When running the application, you can access the API documentation at:

- Swagger UI: `http://localhost:8000/api/docs`
- OpenAPI JSON: `http://localhost:8000/api/openapi.json`

5 changes: 3 additions & 2 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# Include the router with the /api prefix
app.include_router(items.router, prefix="/api")

# Serve static files
app.mount("/static", StaticFiles(directory="frontend"), name="static")

@app.get("/", include_in_schema=False)
async def serve_index():
Expand All @@ -36,5 +34,8 @@ async def custom_swagger_ui_html():
async def get_open_api_endpoint():
return get_openapi(title="API Docs", version="1.0.0", routes=app.routes)

# Serve static files
app.mount("/", StaticFiles(directory="frontend"), name="static")

# Make sure to export the 'app' variable
__all__ = ['app']

0 comments on commit 986ee80

Please sign in to comment.