Prerequisites
Make sure to have the following installed on your machine before proceeding:
- Docker
- Docker Compose
Setting Up Docker for Development
Clone the Repository
Begin by cloning the
helixml/chat-widgetrepository:git clone https://github.com/helixml/chat-widget.git cd chat-widgetConfiguration Files
The project contains a
Dockerfilewhich specifies how the development environment is built. Review theDockerfileto understand dependencies and configurations.# Dockerfile FROM node:14 # Create app directory WORKDIR /usr/src/app # Install app dependencies COPY package*.json ./ RUN npm install # Copy app source COPY . . # The application's default port EXPOSE 3000 # Command to run the app CMD [ "npm", "start" ]Docker Compose Setup
A
docker-compose.ymlfile is utilized to define and run multi-container Docker applications. This is particularly useful if your app requires additional services such as a database.version: '3.8' services: chat-widget: build: . ports: - "3000:3000" volumes: - .:/usr/src/app environment: NODE_ENV: developmentThis configuration does the following:
- Builds the image according to the Dockerfile in the same directory.
- Maps port
3000of the container to port3000on your host. - Mounts the local directory to
/usr/src/appin the container for live code updates. - Sets the
NODE_ENVenvironment variable todevelopment.
Building and Running the Container
To build the Docker image and run the container, execute the following command from the root of the cloned repository:
docker-compose up --buildThis command will build the application and start the service. You can access the chat widget in your browser at
http://localhost:3000.Development Workflow
With Docker, the development workflow becomes seamless. Any changes made in the local files will reflect in the running container due to the volume mapping.
For example, if you modify a TypeScript file in your project:
// src/index.ts import express from 'express'; const app = express(); app.get('/', (req, res) => { res.send('Hello World!'); }); app.listen(3000, () => { console.log('Chat Widget listening on port 3000!'); });After saving your changes, they will automatically be available in the running application without restarting the Docker container.
Stopping the Container
When you wish to stop the Docker container, you can do so by entering:
docker-compose downThis command will stop and remove all containers defined in the
docker-compose.ymlfile.Troubleshooting
If you encounter issues during the setup, check the logs for any errors. You can view the logs with:
docker-compose logsThis will provide insight into what might have gone wrong during the build or runtime processes.
Conclusion
Following the above steps will set up a Docker-based development environment for the helixml/chat-widget. This enables continuous development with real-time updates and efficient management of dependencies.
Sources:
- Direct reference from the project’s Docker and Docker Compose configurations.