Skip to content

zacharyabolton/chat_server

Repository files navigation

Chat Server

CI Status Erlang Version Rebar3 Version Project Status License Version

Erlang Logo Docker Logo

A simple chat server built with Erlang and Docker.

📝 License

This project is licensed under the Apache License 2.0.

🎖️ Honorable Mentions

🚀 Getting Started

📚 Requirements

  • Erlang/OTP 26 Erts 14.2.5
  • rebar 3.23.0
  • Docker
  • Docker Compose

🛠️ Development Setup

  1. Build the Docker image:

    docker-compose down; docker-compose build
  2. Start the server (with live code reloading):

    docker-compose up chat_server_development --watch

🧪 Running Tests

This project uses a combination of EUnit and Common Test for its testing strategy. Tests are set up to run automatically on code changes, fitting the Test Driven Development (TDD) lifecycle.

Setting up Automatic Test Running

  1. Install the file watcher tool entr:

    On macOS with Homebrew:

    brew install entr

    For other systems, refer to the entr installation guide.

  2. Run the automatic test watcher:

    From the project root, run:

    ./watch_and_test.sh

    This will run both EUnit and Common Test whenever a .erl or .hrl file changes in the src or test directories.

  3. Stop the watcher:

    Press Ctrl + C in the terminal where watch_and_test.sh is running.

The run_tests.sh and watch_and_test.sh scripts are already included in the repository, so you don't need to create them manually.

When running the application directly with rebar3 (e.g., using rebar3 shell, rebar3 eunit, or rebar3 ct), the application uses a default port of 8081. This differs from execution in release-based environments (development containers, production, and CI), which use port 8080.

Important Note for Contributors:

  • When executed directly with rebar3, the application will use port 8081 by default.
  • This default port is hard-coded and not configurable through the usual configuration files when running directly with rebar3.
  • If you need to change this port for non-release execution, you'll need to modify the get_port/0 function in src/chat_server.erl.
  • Remember that this port (8081) is specifically for non-release execution and does not affect release-based environments.

Example of the relevant code in src/chat_server.erl:

get_port() ->
  application:get_env(chat_server, port, 8081).

Please be aware of this distinction when running the application directly with rebar3 versus in a release-based environment.

🏭 Production Setup

  1. Build the production Docker image:

    docker-compose down; docker-compose -f docker-compose.prod.yml build
  2. Start the server in production mode:

    docker-compose -f docker-compose.prod.yml up

🤝 Contributing

Contributions are welcome! If you find this project useful or have ideas for improvements, please fork the repository and create a pull request.

📧 Contact

For any questions or inquiries, please contact Zac Bolton.


📝 Notes

This project serves as a practical example of Erlang development and Docker containerization. It aims to provide a solid foundation for further development and potential commercial use. Feedback and suggestions are greatly appreciated.