From 35a1dcce4380a70fc67ef4b7e02bbe64a913d30f Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Tue, 22 Oct 2024 14:40:30 +0530 Subject: [PATCH] feat: switch docker dev from webpack to vite (#10322) # Pull Request Template ## Description - Fix docker development - Switch from webpack to vite ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [x] Breaking change (fix or feature that would cause existing functionality not to work as expected) ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration. ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --- docker-compose.yaml | 21 ++++++++++----------- docker/dockerfiles/vite.Dockerfile | 6 ++++++ docker/entrypoints/vite.sh | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 docker/dockerfiles/vite.Dockerfile create mode 100644 docker/entrypoints/vite.sh diff --git a/docker-compose.yaml b/docker-compose.yaml index 37c21c069..cbc25a59e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -30,14 +30,14 @@ services: depends_on: - postgres - redis - - webpack + - vite - mailhog - sidekiq ports: - 3000:3000 env_file: .env environment: - - WEBPACKER_DEV_SERVER_HOST=webpack + - VITE_DEV_SERVER_HOST=vite - NODE_ENV=development - RAILS_ENV=development entrypoint: docker/entrypoints/rails.sh @@ -61,27 +61,26 @@ services: - RAILS_ENV=development command: ["bundle", "exec", "sidekiq", "-C", "config/sidekiq.yml"] - webpack: + vite: <<: *base build: context: . - dockerfile: ./docker/dockerfiles/webpack.Dockerfile - image: chatwoot-webpack:development + dockerfile: ./docker/dockerfiles/vite.Dockerfile + image: chatwoot-vite:development volumes: - ./:/app:delegated - - node_modules:/app/node_modules # Node modules shared across containers + - node_modules:/app/node_modules - packs:/app/public/packs - cache:/app/tmp/cache - bundle:/usr/local/bundle ports: - - "3035" # Webpack dev server + - "5173:5173" # Vite dev server environment: - - WEBPACKER_DEV_SERVER_HOST=0.0.0.0 + - VITE_DEV_SERVER_HOST=0.0.0.0 - NODE_ENV=development - - NODE_OPTIONS=--openssl-legacy-provider - RAILS_ENV=development - entrypoint: docker/entrypoints/webpack.sh - command: bin/webpack-dev-server + entrypoint: docker/entrypoints/vite.sh + command: pnpm run dev postgres: image: postgres:12 diff --git a/docker/dockerfiles/vite.Dockerfile b/docker/dockerfiles/vite.Dockerfile new file mode 100644 index 000000000..2117ff691 --- /dev/null +++ b/docker/dockerfiles/vite.Dockerfile @@ -0,0 +1,6 @@ +FROM chatwoot:development + +RUN chmod +x docker/entrypoints/vite.sh + +EXPOSE 5173 +CMD ["pnpm", "run", "dev"] diff --git a/docker/entrypoints/vite.sh b/docker/entrypoints/vite.sh new file mode 100644 index 000000000..16e57e82c --- /dev/null +++ b/docker/entrypoints/vite.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -e + +rm -rf /app/tmp/pids/server.pid +rm -rf /app/tmp/cache/* + +pnpm install --frozen-lockfile + +echo "Waiting for pnpm and bundle integrity to match lockfiles...." +PNPM="pnpm list --json | grep -q 'Missing dependencies'" +BUNDLE="bundle check" + +until ! $PNPM && $BUNDLE +do + sleep 2; +done + +echo "Ready to run Vite development server." + +exec "$@"