A simple chat server built with Erlang and Docker.
This project is licensed under the Apache License 2.0.
- The Erlang Docs
- Adopting Erlang by Tristan Sloughter, Fred Hebert, and Evan Vigil-McClanahan
- The Cowboy Documentation by Loïc Hoguin
- Learn You Some Erlang for Great Good! by Fred Hebert
- ... and of course a myriad of other resources and contributors
- Erlang/OTP 26 Erts 14.2.5
- rebar 3.23.0
- Docker
- Docker Compose
-
Build the Docker image:
docker-compose down; docker-compose build
-
Start the server (with live code reloading):
docker-compose up chat_server_development --watch
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.
-
Install the file watcher tool
entr
:On macOS with Homebrew:
brew install entr
For other systems, refer to the entr installation guide.
-
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 thesrc
ortest
directories. -
Stop the watcher:
Press
Ctrl + C
in the terminal wherewatch_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 insrc/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.
-
Build the production Docker image:
docker-compose down; docker-compose -f docker-compose.prod.yml build
-
Start the server in production mode:
docker-compose -f docker-compose.prod.yml up
Contributions are welcome! If you find this project useful or have ideas for improvements, please fork the repository and create a pull request.
For any questions or inquiries, please contact Zac Bolton.
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.