Skip to content

Commit

Permalink
Development: Add documentation for production setup using Docker (#8400)
Browse files Browse the repository at this point in the history
  • Loading branch information
BBesrour authored May 5, 2024
1 parent bfdb659 commit 1d05ef5
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docker/artemis/config/node1.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SPRING_PROFILES_ACTIVE='prod,localvc,localci,buildagent,core,scheduling,docker'
SPRING_PROFILES_ACTIVE='prod,localvc,localci,core,scheduling,docker'
EUREKA_INSTANCE_INSTANCEID='Artemis:1'
EUREKA_INSTANCE_HOSTNAME='artemis-app-node-1'
SPRING_HAZELCAST_INTERFACE='artemis-app-node-1'
3 changes: 3 additions & 0 deletions docker/artemis/config/node2.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ SPRING_PROFILES_ACTIVE='prod,localvc,localci,buildagent,core,docker'
EUREKA_INSTANCE_INSTANCEID='Artemis:2'
EUREKA_INSTANCE_HOSTNAME='artemis-app-node-2'
SPRING_HAZELCAST_INTERFACE='artemis-app-node-2'

ARTEMIS_VERSIONCONTROL_USER='artemis_admin'
ARTEMIS_VERSIONCONTROL_PASSWORD='artemis_admin'
5 changes: 4 additions & 1 deletion docker/artemis/config/node3.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
SPRING_PROFILES_ACTIVE='prod,localvc,localci,buildagent,core,docker'
SPRING_PROFILES_ACTIVE='prod,buildagent'
EUREKA_INSTANCE_INSTANCEID='Artemis:3'
EUREKA_INSTANCE_HOSTNAME='artemis-app-node-3'
SPRING_HAZELCAST_INTERFACE='artemis-app-node-3'

ARTEMIS_VERSIONCONTROL_USER='artemis_admin'
ARTEMIS_VERSIONCONTROL_PASSWORD='artemis_admin'
2 changes: 1 addition & 1 deletion docker/artemis/config/prod-multinode.env
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ EUREKA_INSTANCE_APPNAME='Artemis'
JHIPSTER_REGISTRY_PASSWORD="admin"
JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64SECRET="bXktc2VjcmV0LWtleS13aGljaC1zaG91bGQtYmUtY2hhbmdlZC1pbi1wcm9kdWN0aW9uLWFuZC1iZS1iYXNlNjQtZW5jb2RlZAo="

ARTEMIS_VERSIONCONTROL_URL='https://localhost'
ARTEMIS_VERSIONCONTROL_URL='http://artemis-app-node-2:8080'
ARTEMIS_VERSIONCONTROL_USER='demo'
ARTEMIS_VERSIONCONTROL_PASSWORD='demo'
ARTEMIS_CONTINUOUSINTEGRATION_ARTEMISAUTHENTICATIONTOKENVALUE='demo'
Expand Down
1 change: 0 additions & 1 deletion docker/nginx/artemis-upstream-multi-node.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
server artemis-app-node-1:8080;
server artemis-app-node-2:8080;
server artemis-app-node-3:8080;
117 changes: 117 additions & 0 deletions docs/admin/setup/distributed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ have to be synchronized:

Each of these three aspects is synchronized using a different solution

.. _Database Cache:

Database cache
^^^^^^^^^^^^^^
Artemis uses a cache provider that supports distributed caching: Hazelcast_.
Expand Down Expand Up @@ -281,6 +283,8 @@ This enables the registry in nginx
This will apply the config changes and the registry will be reachable.


.. _WebSockets:

WebSockets
^^^^^^^^^^

Expand Down Expand Up @@ -652,3 +656,116 @@ different ports and a unique instance ID for each instance.
#. Start the remaining instances.

You should now be able to see all instances in the registry interface at ``http://localhost:8761``.

.. _Running multiple instances locally with Docker:

Running multiple instances locally with Docker
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can also run multiple instances of Artemis locally using Docker. This will start 3 Artemis instances, each running
on a its own container. A load balancer (nginx) will be used to distribute the requests to the different instances. The
load balancer will be running in a separate container and will be accessible on ports 80/443 of the host system. The
instances will be registered in the registry service running on a separate container. The instances will use the registry
service to discover each other and form a Hazelcast cluster. Further details can be found in :ref:`Database Cache`. The
instances will also use a ActiveMQ Artemis broker to synchronize WebSocket messages. Further details can be found in
:ref:`WebSockets`. In summary, the setup will look like this:

* 3 Artemis instances:

* artemis-app-node-1: using following spring profile: ``prod,localvc,localci,core,scheduling,docker``
* artemis-app-node-2: using following profile: ``prod,localvc,localci,buildagent,core,docker``
* artemis-app-node-3: using following profile: ``prod,buildagent``
* A MySQL database addressable on port 3306 of the host system
* A Load balancer (nginx) addressable on ports 80/443 of the host system: ``http(s)://localhost``
* A Registry service addressable on port 8761 of the host system: ``http://localhost:8761``
* An ActiveMQ broker


.. figure:: distributed/multi-node-setup.drawio.png
:align: center



.. note::

- You don't have to start the client manually. The client files are served by the Artemis instances and can be
accessed through the load balancer on ``http(s)://localhost``.

- You may run into the following error when starting the containers
``No member group is available to assign partition ownership...``. This issue should resolve itself after a few
minutes. Otherwise, you can first start the following containers:
``docker compose -f docker/test-server-multi-node-mysql-localci.yml up mysql jhipster-registry activemq-broker artemis-app-node-1``.
After these containers are up and running, you can start the remaining containers:
``docker compose -f docker/test-server-multi-node-mysql-localci.yml up artemis-app-node-2 artemis-app-node-3 nginx``.


Linux setup
"""""""""""

#. When running the Artemis container on a Unix system, you will have to give the user running in the container
permission to access the Docker socket by adding them to the docker group. You can find the group ID of the docker
group by running ``getent group docker | cut -d: -f3``. Afterwards, create a new file ``docker/.env`` with the
following content:

.. code:: bash
DOCKER_GROUP_ID=<REPLACE_WITH_DOCKER_GROUP_ID_OF_YOUR_SYSTEM>
#. The docker compose setup which we will use will mount some local directories
(namely the ones under docker/.docker-data) into the containers. To ensure that the user running in the container has
the necessary permissions to these directories, you will have to change the owner of these directories to the
user running in the container (User with ID 1337). You can do this by running the following command:

.. code:: bash
sudo chown -R 1337:1337 docker/.docker-data
.. note::

- If you don't want to change the owner of the directories, you can create other directories with the necessary
permissions and adjust the paths in the docker-compose file accordingly.
- You could also use docker volumes instead of mounting local directories. You will have to adjust the docker-compose
file accordingly (`Docker docs <https://docs.docker.com/storage/volumes/#use-a-volume-with-docker-compose/>`_).
However, this would make it more difficult to access the files on the host system.

#. Start the docker containers by running the following command:

.. code:: bash
docker compose -f docker/test-server-multi-node-mysql-localci.yml up
#. You can now access artemis on ``http(s)://localhost`` and the registry on ``http://localhost:8761``.

Windows setup
"""""""""""""

#. When running the Artemis container on a Windows system, you will have to change the value for the Docker connection
URI. You need to change the value of the environment variable ``ARTEMIS_CONTINUOUSINTEGRATION_DOCKERCONNECTIONURI``
in the file ``docker/artemis/config/prod-multinode.env`` to ``tcp://host.docker.internal:2375``.

.. note::

- Make sure that option "Expose daemon on tcp://localhost:2375 without TLS" is enabled. This can be found under
Settings > General in Docker Desktop.

#. Start the docker containers by running the following command:

.. code:: bash
docker compose -f docker/test-server-multi-node-mysql-localci.yml up
#. You can now access artemis on ``http(s)://localhost`` and the registry on ``http://localhost:8761``.

MacOS setup
"""""""""""

#. Make sure to enable "Allow the default Docker socket to be used (requires password)" in the Docker Desktop settings.
This can be found under Settings > Advanced in Docker Desktop.

#. Start the docker containers by running the following command:

.. code:: bash
docker compose -f docker/test-server-multi-node-mysql-localci.yml up
#. You can now access artemis on ``http(s)://localhost`` and the registry on ``http://localhost:8761``.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1d05ef5

Please sign in to comment.