Skip to content

Commit c56ebee

Browse files
committed
[DOP-22054] Move migrations to separated script
1 parent 27ea965 commit c56ebee

File tree

6 files changed

+54
-14
lines changed

6 files changed

+54
-14
lines changed

docker-compose.test.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ services:
2828
timeout: 5s
2929
retries: 3
3030

31+
migrations:
32+
image: mtsrus/syncmaster-backend:${BACKEND_IMAGE_TAG:-test}
33+
restart: unless-stopped
34+
build:
35+
dockerfile: docker/Dockerfile.backend
36+
context: .
37+
target: test
38+
volumes:
39+
- ./syncmaster:/app/syncmaster
40+
entrypoint: [python, -m, syncmaster.db.migrations, upgrade, head]
41+
env_file: .env.docker
42+
depends_on:
43+
db:
44+
condition: service_healthy
45+
profiles: [backend, worker, scheduler, all]
46+
3147
backend:
3248
image: mtsrus/syncmaster-backend:${BACKEND_IMAGE_TAG:-test}
3349
restart: unless-stopped
@@ -41,15 +57,22 @@ services:
4157
volumes:
4258
- ./syncmaster:/app/syncmaster
4359
- ./docs/_static:/app/docs/_static
44-
- ./cached_jars:/root/.ivy2
4560
- ./reports:/app/reports
4661
- ./tests:/app/tests
4762
- ./pyproject.toml:/app/pyproject.toml
4863
depends_on:
4964
db:
5065
condition: service_healthy
66+
migrations:
67+
condition: service_completed_successfully
5168
rabbitmq:
5269
condition: service_healthy
70+
healthcheck:
71+
test: [CMD-SHELL, curl -f http://localhost:8000/monitoring/ping]
72+
interval: 30s
73+
timeout: 5s
74+
retries: 3
75+
start_period: 5s
5376
profiles: [backend, all]
5477

5578
scheduler:
@@ -68,6 +91,8 @@ services:
6891
depends_on:
6992
db:
7093
condition: service_healthy
94+
migrations:
95+
condition: service_completed_successfully
7196
rabbitmq:
7297
condition: service_healthy
7398
profiles: [scheduler, all]
@@ -94,6 +119,8 @@ services:
94119
depends_on:
95120
db:
96121
condition: service_healthy
122+
migrations:
123+
condition: service_completed_successfully
97124
rabbitmq:
98125
condition: service_healthy
99126
profiles: [worker, scheduler, s3, oracle, hdfs, hive, clickhouse, mysql, mssql, all]

docker-compose.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ services:
2828
timeout: 5s
2929
retries: 3
3030

31+
migrations:
32+
image: mtsrus/syncmaster-backend:${TAG:-develop}
33+
restart: unless-stopped
34+
build:
35+
dockerfile: docker/Dockerfile.backend
36+
context: .
37+
entrypoint: [python, -m, syncmaster.db.migrations, upgrade, head]
38+
env_file: .env.docker
39+
depends_on:
40+
db:
41+
condition: service_healthy
42+
3143
backend:
3244
image: mtsrus/syncmaster-backend:${TAG:-develop}
3345
restart: unless-stopped
@@ -49,6 +61,8 @@ services:
4961
depends_on:
5062
db:
5163
condition: service_healthy
64+
migrations:
65+
condition: service_completed_successfully
5266
rabbitmq:
5367
condition: service_healthy
5468
healthcheck:
@@ -68,6 +82,8 @@ services:
6882
depends_on:
6983
db:
7084
condition: service_healthy
85+
migrations:
86+
condition: service_completed_successfully
7187
rabbitmq:
7288
condition: service_healthy
7389

@@ -81,6 +97,8 @@ services:
8197
depends_on:
8298
db:
8399
condition: service_healthy
100+
migrations:
101+
condition: service_completed_successfully
84102
rabbitmq:
85103
condition: service_healthy
86104

docker/entrypoint_backend.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
python -m syncmaster.db.migrations upgrade head
5-
64
if [[ "x${SYNCMASTER__ENTRYPOINT__SUPERUSERS}" != "x" ]]; then
75
superusers=$(echo "${SYNCMASTER__ENTRYPOINT__SUPERUSERS}" | tr "," " ")
86
python -m syncmaster.backend.scripts.manage_superusers add ${superusers}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Now migrations are executed in a dedicated one-off container, instead of being run as a part of ``backend`` container.

docs/scheduler/start_scheduler.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Starting the Scheduler
22
======================
33

4-
54
With docker
65
-----------
76

@@ -14,12 +13,12 @@ Options can be set via ``.env`` file or ``environment`` section in ``docker-comp
1413
.. dropdown:: ``docker-compose.yml``
1514

1615
.. literalinclude:: ../../docker-compose.yml
17-
:emphasize-lines: 68-83
16+
:emphasize-lines: 90-103
1817

1918
.. dropdown:: ``.env.docker``
2019

2120
.. literalinclude:: ../../.env.docker
22-
:emphasize-lines: 11-25
21+
:emphasize-lines: 11-25
2322

2423
To start the worker container you need to run the command:
2524

@@ -28,7 +27,6 @@ To start the worker container you need to run the command:
2827
docker compose up scheduler -d --wait --wait-timeout 200
2928
3029
31-
3230
Without docker
3331
--------------
3432

docs/worker/start_worker.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ Starting the Celery Worker
66
Before starting the worker you need to create a queue.
77
The queue is created by sending a post request to ``/queues`` endpoint (See Swagger doc for details).
88

9-
109
With docker
1110
-----------
1211

1312
Installation process
1413
~~~~~~~~~~~~~~~~~~~~
1514

16-
Docker will download worker image of syncmaster worker & broker, and run them.
15+
Docker will download worker image, and then start worker container with dependencies.
1716
Options can be set via ``.env`` file or ``environment`` section in ``docker-compose.yml``
1817

1918
.. dropdown:: ``docker-compose.yml``
2019

2120
.. literalinclude:: ../../docker-compose.yml
22-
:emphasize-lines: 55-66
21+
:emphasize-lines: 75-88
2322

2423
.. dropdown:: ``.env.docker``
2524

2625
.. literalinclude:: ../../.env.docker
27-
:emphasize-lines: 11-22
26+
:emphasize-lines: 11-22
2827

2928
To start the worker container you need to run the command:
3029

@@ -33,21 +32,20 @@ To start the worker container you need to run the command:
3332
docker compose up worker -d --wait --wait-timeout 200
3433
3534
36-
3735
Without docker
3836
--------------
3937

4038
To start the worker you need to run the command
4139

4240
.. code-block:: bash
4341
44-
python -m celery -A syncmaster.worker.celery worker
42+
python -m celery -A syncmaster.worker.celery worker --max-tasks-per-child=1
4543
4644
You can specify options like concurrency and queues by adding additional flags:
4745

4846
.. code-block:: bash
4947
50-
celery -A -A syncmaster.worker.celery worker --concurrency=4 --max-tasks-per-child=1 --loglevel=info
48+
python -m celery -A syncmaster.worker.celery worker --concurrency=4 --max-tasks-per-child=1 --loglevel=info
5149
5250
5351
Refer to the `Celery <https://docs.celeryq.dev/en/stable/>`_ documentation for more advanced start options.

0 commit comments

Comments
 (0)