Skip to content

Commit a1a0313

Browse files
committed
[DOP-25282] Use docker-compose profiles
1 parent 7e78ea0 commit a1a0313

File tree

9 files changed

+65
-50
lines changed

9 files changed

+65
-50
lines changed

.github/labels.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
color: '5319e7'
2020
from_name: component:backend
2121

22-
- name: component:client
23-
description: Client-related changes
22+
- name: component:consumer
23+
description: Consumer-related changes
2424
color: 75f526
2525

2626
- name: kind:bug

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
include .env.local
44

5-
BAKEND_IMAGE = develop
6-
FRONTEND_IMAGE = develop
5+
VERSION = develop
76
VENV = .venv
87
PIP = ${VENV}/bin/pip
98
POETRY = ${VENV}/bin/poetry
@@ -108,10 +107,10 @@ prod-build: ##@Application Build docker image
108107
docker build --progress=plain --network=host -t mtsrus/data-rentgen:develop -f ./docker/Dockerfile $(ARGS) .
109108

110109
prod: ##@Application Run production containers
111-
docker compose -f docker-compose.yml up -d
110+
docker compose -f docker-compose.yml --profile all up -d $(ARGS)
112111

113-
prod-cleanup: ##@Application Stop production containers
114-
docker compose -f docker-compose.yml down --remove-orphans $(ARGS)
112+
prod-stop: ##@Application Stop production containers
113+
docker compose -f docker-compose.yml --profile all down --remove-orphans $(ARGS)
115114

116115

117116
.PHONY: docs

docker-compose.yml

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,26 @@ services:
1414
timeout: 5s
1515
retries: 3
1616

17+
db-migration:
18+
image: mtsrus/data-rentgen:${VERSION:-latest}
19+
command: |
20+
python -m data_rentgen.db.migrations upgrade head && python -m data_rentgen.db.scripts.create_partitions
21+
env_file: .env.docker
22+
depends_on:
23+
db:
24+
condition: service_healthy
25+
26+
db-views:
27+
image: mtsrus/data-rentgen:${VERSION:-latest}
28+
command: |
29+
python -m data_rentgen.db.scripts.refresh_analytic_views
30+
env_file: .env.docker
31+
depends_on:
32+
db-migration:
33+
condition: service_completed_successfully
34+
1735
server:
18-
image: mtsrus/data-rentgen:${BACKEND_IMAGE:-latest}
36+
image: mtsrus/data-rentgen:${VERSION:-latest}
1937
command: python -m data_rentgen.server --host 0.0.0.0 --port 8000
2038
restart: unless-stopped
2139
env_file: .env.docker
@@ -39,6 +57,10 @@ services:
3957
condition: service_healthy
4058
db-migration:
4159
condition: service_completed_successfully
60+
profiles:
61+
- server
62+
- frontend
63+
- all
4264

4365
broker:
4466
image: bitnami/kafka:3.9
@@ -53,9 +75,13 @@ services:
5375
interval: 10s
5476
timeout: 5s
5577
retries: 5
78+
profiles:
79+
- consumer
80+
- broker
81+
- all
5682

5783
consumer:
58-
image: mtsrus/data-rentgen:${BACKEND_IMAGE:-latest}
84+
image: mtsrus/data-rentgen:${VERSION:-latest}
5985
command: python -m data_rentgen.consumer --host 0.0.0.0 --port 8000
6086
restart: unless-stopped
6187
env_file: .env.docker
@@ -70,27 +96,12 @@ services:
7096
condition: service_healthy
7197
db-migration:
7298
condition: service_completed_successfully
73-
74-
db-migration:
75-
image: mtsrus/data-rentgen:${BACKEND_IMAGE:-latest}
76-
command: |
77-
python -m data_rentgen.db.migrations upgrade head && python -m data_rentgen.db.scripts.create_partitions
78-
env_file: .env.docker
79-
depends_on:
80-
db:
81-
condition: service_healthy
82-
83-
db-views:
84-
image: mtsrus/data-rentgen:${BACKEND_IMAGE:-latest}
85-
command: |
86-
python -m data_rentgen.db.scripts.refresh_analytic_views
87-
env_file: .env.docker
88-
depends_on:
89-
db-migration:
90-
condition: service_completed_successfully
99+
profiles:
100+
- consumer
101+
- all
91102

92103
frontend:
93-
image: mtsrus/data-rentgen-ui:${FRONTEND_IMAGE:-latest}
104+
image: mtsrus/data-rentgen-ui:${VERSION:-latest}
94105
restart: unless-stopped
95106
env_file: .env.docker
96107
ports:
@@ -104,6 +115,9 @@ services:
104115
depends_on:
105116
server:
106117
condition: service_healthy
118+
profiles:
119+
- frontend
120+
- all
107121

108122
volumes:
109123
postgres_data:

docs/quickstart/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Then start containers using ``docker-compose``:
2727

2828
.. code:: console
2929
30-
$ docker compose up -d --wait
30+
$ docker compose --profile all up -d --wait
3131
3232
``docker-compose`` will download required images, create containers and start them in a proper order.
3333
Options can be set via ``.env.docker`` file or ``environment`` section in ``docker-compose.yml``.

docs/reference/broker/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ With Docker
2222

2323
.. code:: console
2424
25-
$ docker compose up -d broker
25+
$ docker compose --profile broker up -d
2626
2727
``docker-compose`` will download Apache Kafka image, create container and volume, and then start container.
2828

@@ -32,7 +32,7 @@ With Docker
3232
.. dropdown:: ``docker-compose.yml``
3333

3434
.. literalinclude:: ../../../docker-compose.yml
35-
:emphasize-lines: 43-55,95
35+
:emphasize-lines: 65-81,124
3636

3737
.. dropdown:: ``.env.docker``
3838

docs/reference/consumer/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ With docker
1818

1919
.. code:: console
2020
21-
$ docker compose up -d db consumer
21+
$ docker compose --profile consumer up -d
2222
2323
``docker-compose`` will download all necessary images, create containers, and then start consumer process.
2424

@@ -27,7 +27,7 @@ With docker
2727
.. dropdown:: ``docker-compose.yml``
2828

2929
.. literalinclude:: ../../../docker-compose.yml
30-
:emphasize-lines: 57-72
30+
:emphasize-lines: 83-101
3131

3232
.. dropdown:: ``.env.docker``
3333

docs/reference/database/index.rst

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ After a database is started, it is required to run migration script.
99
For empty database, it creates all the required tables and indexes.
1010
For non-empty database, it will perform database structure upgrade, using `Alembic <https://alembic.sqlalchemy.org/>`_.
1111

12+
.. warning::
13+
14+
Other containers (consumer, server) should be stopped while running migrations, to prevent interference.
15+
1216
After migrations are performed, it is required to run script which creates partitions for some tables in the database.
1317
By default, it creates monthly partitions, for current and next month. This can be changed by overriding command args.
1418
This script should run on schedule, for example by adding a dedicated entry to `crontab <https://help.ubuntu.com/community/CronHowto>`_.
@@ -17,18 +21,16 @@ Along with migrations analytics views are created. By default these materialized
1721
In order to fill these tables with data you need to run refresh script. The command for this shown below.
1822
Views based on data in ``output`` and ``input`` tables and has such structure:
1923

20-
.. code:: text
21-
22-
dataset_name - Name of dataset.
23-
dataset_location - Name of dataset location (e.g. clusster name).
24-
dataset_location_type - Type of dataset location (e.g. hive, hdfs, postgres).
25-
user_id - Internal user id.
26-
user_name - Internal user name (e.g. name of user which run spark job).
27-
last_interaction_dt - Time when user lat time interact with dataset. Read or write depens on base table.
28-
num_of_interactions - Number of interactions in given interval.
29-
sum_bytes - Sum of bytes in given interval. ``num_bytes`` - column.
30-
sum_rows - Sum of rows in given interval. ``num_rows`` - column.
31-
sum_files - Sum of files in given interval. ``num_files`` - column.
24+
* ``dataset_name`` - Name of dataset.
25+
* ``dataset_location`` - Name of dataset location (e.g. clusster name).
26+
* ``dataset_location_type`` - Type of dataset location (e.g. hive, hdfs, postgres).
27+
* ``user_id`` - Internal user id.
28+
* ``user_name`` - Internal user name (e.g. name of user which run spark job).
29+
* ``last_interaction_dt`` - Time when user lat time interact with dataset. Read or write depens on base table.
30+
* ``num_of_interactions`` - Number of interactions in given interval.
31+
* ``sum_bytes`` - Sum of bytes in given interval.
32+
* ``sum_rows`` - Sum of rows in given interval.
33+
* ``sum_files`` - Sum of files in given interval.
3234

3335
We provide three types of views: ``day``, ``week`` and ``month``, based on the time period in which the aggregation occur.
3436
Views are created for all intervals and by default, script refresh all views.
@@ -64,7 +66,7 @@ With Docker
6466
.. dropdown:: ``docker-compose.yml``
6567

6668
.. literalinclude:: ../../../docker-compose.yml
67-
:emphasize-lines: 1-15,108-110
69+
:emphasize-lines: 1-33,123
6870

6971
.. dropdown:: ``.env.docker``
7072

docs/reference/frontend/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ With Docker
1919

2020
.. code:: console
2121
22-
$ docker compose up -d db frontend
22+
$ docker compose --profile frontend up -d
2323
2424
``docker-compose`` will download Data.Rentgen UI image, create containers, and then start them.
2525

@@ -28,7 +28,7 @@ With Docker
2828
.. dropdown:: ``docker-compose.yml``
2929

3030
.. literalinclude:: ../../../docker-compose.yml
31-
:emphasize-lines: 92-106
31+
:emphasize-lines: 103-120
3232

3333
.. dropdown:: ``.env.docker``
3434

docs/reference/server/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ With docker
1919

2020
.. code:: console
2121
22-
$ docker compose up -d db server
22+
$ docker compose --profile server up -d
2323
2424
``docker-compose`` will download all necessary images, create containers, and then start the server.
2525

@@ -28,7 +28,7 @@ With docker
2828
.. dropdown:: ``docker-compose.yml``
2929

3030
.. literalinclude:: ../../../docker-compose.yml
31-
:emphasize-lines: 17-41
31+
:emphasize-lines: 35-63
3232

3333
.. dropdown:: ``.env.docker``
3434

0 commit comments

Comments
 (0)