Skip to content

Feat: optimize Dockerfile of frontend#2453

Open
mustafa-sayyed wants to merge 7 commits into
arc53:mainfrom
mustafa-sayyed:feat/optimize-dockerfile-of-frontend
Open

Feat: optimize Dockerfile of frontend#2453
mustafa-sayyed wants to merge 7 commits into
arc53:mainfrom
mustafa-sayyed:feat/optimize-dockerfile-of-frontend

Conversation

@mustafa-sayyed
Copy link
Copy Markdown
Contributor

@mustafa-sayyed mustafa-sayyed commented May 4, 2026

Fixes #2452

  • Reduces the Docker image Size by 850 MB
  • It uses multi-stage build and a lightweight base, i.e. node:22-alpine
  • Build the frontend and serve it on port 5173 to make it backward compatible with the existing application

Edited:

  • I have now replaced the node:22-alpine image with nginx as base image
  • Now it reduces size by 1 GB, it takes now only 104 MB
image

Copilot AI review requested due to automatic review settings May 4, 2026 17:13
@vercel
Copy link
Copy Markdown

vercel Bot commented May 4, 2026

@mustafa-sayyed is attempting to deploy a commit to the Arc53 Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the frontend container’s Vite dev-server workflow with a multi-stage Docker build that compiles the React app and serves the generated dist assets from a smaller node:22-alpine image. In the codebase, this changes how the frontend container is built and run for all Docker-based frontend deployments.

Changes:

  • Switches the frontend image to a multi-stage node:22-alpine build.
  • Replaces npm install with npm ci and adds a production build step.
  • Replaces npm run dev -- --host with serve -s dist -l 5173.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/Dockerfile Outdated
Comment thread frontend/Dockerfile Outdated
@mustafa-sayyed
Copy link
Copy Markdown
Contributor Author

Hey @dartpain , @ManishMadan2882

I have optimized the Dockerfile of frontend, it now only takes 104 MB

But it breaks with the existing Docker compose setup
such as it now doesn't take the Env variable of Vite at runtime

The Dockerfile is good for Production, not for Development, as it doesn't sync with the source, doesn't take runtime env vars

We can solve this issue using the multi-stage build itself

Plan

  • I will use two build stages inside the Docker, one for Development, which uses Vite Server
  • And the second Stage for production, which uses nginx to serve the dist
  • and in Docker Compose files, we can use the target cmd to select the stage
  • such as using target: dev in docker-compose-local.yaml and target: prod in docker-compose-azure.yaml

@mustafa-sayyed
Copy link
Copy Markdown
Contributor Author

@dartpain
@ManishMadan2882

I have implemented the PLAN, Please review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deployment/docker-compose.yaml Outdated
Comment thread deployment/docker-compose-local.yaml Outdated
Comment thread deployment/docker-compose-azure.yaml Outdated
Comment thread frontend/Dockerfile
Comment on lines +23 to +27
FROM nginx:alpine AS production

COPY --from=build /app/dist /usr/share/nginx/html

COPY nginx.conf /etc/nginx/conf.d/default.conf
Comment thread frontend/Dockerfile Outdated
@mustafa-sayyed
Copy link
Copy Markdown
Contributor Author

@dartpain
@ManishMadan2882

Review from GitHub Copilot:

The final image is now a static Vite build served by nginx, so all VITE_* settings are frozen at image-build time. This repo still deploys that image with runtime VITE_API_HOST/VITE_API_STREAMING overrides (for example in deployment/docker-compose-hub.yaml and deployment/k8s/deployments/docsgpt-deploy.yaml), so those deployments will ignore the configured backend and use whatever was baked into .env.production during npm run build.

I have fixed all things,
But one thing is still to address: the runtime Env injection
After doing a lot of research, I came to know that we can solve this problem using an entrypoint script

what your thoughts ?
Guide me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 Feature: Dockerfile is too heavy in frontend, Reduce the image size

2 participants