Skip to content

Commit bf3813c

Browse files
author
maxim-lixakov
committed
[IMPROVEMENT] - add scheduler Docker image
1 parent f18e073 commit bf3813c

File tree

10 files changed

+238
-105
lines changed

10 files changed

+238
-105
lines changed

.github/workflows/scheduler-tests.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ jobs:
2929
${{ runner.os }}-python-${{ env.DEFAULT_PYTHON }}-test-scheduler
3030
${{ runner.os }}-python-
3131
32-
- name: Build Worker Image
32+
- name: Build Scheduler Image
3333
uses: docker/build-push-action@v6
3434
with:
3535
context: .
36-
tags: mtsrus/syncmaster-worker:${{ github.sha }}
36+
tags: mtsrus/syncmaster-scheduler:${{ github.sha }}
3737
target: test
38-
file: docker/Dockerfile.worker
38+
file: docker/Dockerfile.scheduler
3939
load: true
40-
cache-from: mtsrus/syncmaster-worker:develop
40+
cache-from: mtsrus/syncmaster-scheduler:develop
4141

4242
- name: Docker compose up
4343
run: |
@@ -48,13 +48,13 @@ jobs:
4848

4949
- name: Run Scheduler Tests
5050
run: |
51-
docker compose -f ./docker-compose.test.yml --profile worker exec -T worker coverage run -m pytest -vvv -s -m "worker and scheduler_integration"
51+
docker compose -f ./docker-compose.test.yml --profile worker exec -T scheduler coverage run -m pytest -vvv -s -m "worker and scheduler_integration"
5252
53-
- name: Dump worker logs on failure
53+
- name: Dump scheduler logs on failure
5454
if: failure()
5555
uses: jwalton/gh-docker-logs@v2
5656
with:
57-
images: mtsrus/syncmaster-worker
57+
images: mtsrus/syncmaster-scheduler
5858
dest: ./logs
5959

6060
# This is important, as coverage is exported after receiving SIGTERM
@@ -63,7 +63,7 @@ jobs:
6363
run: |
6464
docker compose -f docker-compose.test.yml --profile all down -v --remove-orphans
6565
66-
- name: Upload worker logs
66+
- name: Upload sheduler logs
6767
uses: actions/upload-artifact@v4
6868
if: failure()
6969
with:
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Scheduler docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
tags:
8+
- '[0-9]+.[0-9]+.[0-9]+'
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
release:
17+
name: Build & push scheduler image to Dockerhub
18+
runs-on: ubuntu-latest
19+
if: github.repository == 'MobileTeleSystems/syncmaster' # prevent running on forks
20+
21+
steps:
22+
- name: Set up QEMU
23+
uses: docker/setup-qemu-action@v3
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Login to Docker Hub
29+
uses: docker/login-action@v3
30+
with:
31+
username: ${{ secrets.DOCKERHUB_USERNAME }}
32+
password: ${{ secrets.DOCKERHUB_TOKEN }}
33+
34+
- name: Checkout code
35+
uses: actions/checkout@v4
36+
37+
- name: Set tag
38+
id: set_tag
39+
run: |
40+
if [[ "${{ github.ref_type }}" == "branch" && "${{ github.ref_name }}" == "develop" ]]; then
41+
echo "TAG=mtsrus/syncmaster-scheduler:develop" >> $GITHUB_ENV
42+
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
43+
echo "TAG=mtsrus/syncmaster-scheduler:latest,mtsrus/syncmaster-scheduler:${{ github.ref_name }}" >> $GITHUB_ENV
44+
fi
45+
46+
- name: Build scheduler image
47+
uses: docker/build-push-action@v6
48+
with:
49+
tags: ${{ env.TAG }}
50+
context: .
51+
target: prod
52+
file: docker/Dockerfile.scheduler
53+
pull: true
54+
push: true
55+
cache-to: type=inline
56+
cache-from: mtsrus/syncmaster-scheduler:develop
57+
platforms: |
58+
linux/amd64
59+
linux/arm64/v8
60+
provenance: mode=max
61+
62+
- name: Convert README to Markdown
63+
uses: docker://pandoc/core:2.9
64+
with:
65+
args: >-
66+
--output=README.md
67+
--from=rst
68+
--to=gfm
69+
--wrap=none
70+
README.rst
71+
72+
- name: Update DockerHub Description
73+
uses: peter-evans/dockerhub-description@v4
74+
if: github.ref_type == 'tag'
75+
with:
76+
username: ${{ secrets.DOCKERHUB_USERNAME }}
77+
# this requires token with read+write+delete permissions. read+write is not enough!
78+
password: ${{ secrets.DOCKERHUB_TOKEN }}
79+
repository: mtsrus/syncmaster-scheduler
80+
short-description: ${{ github.event.repository.description }}
81+
enable-url-completion: true

.github/workflows/unit-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
4646
- name: Install dependencies
4747
run: |
48-
poetry install --no-root --extras "backend" --with test
48+
poetry install --no-root --all-extras --with test
4949
5050
- name: Start docker compose
5151
run: |

docker-compose.test.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,24 @@ services:
5353
profiles: [backend, all]
5454

5555
scheduler:
56-
image: mtsrus/syncmaster-backend:${BACKEND_IMAGE_TAG:-test}
56+
image: mtsrus/syncmaster-scheduler:${SCHEDULER_IMAGE_TAG:-test}
5757
restart: unless-stopped
5858
build:
59-
dockerfile: docker/Dockerfile.backend
59+
dockerfile: docker/Dockerfile.scheduler
6060
context: .
6161
target: test
6262
env_file: .env.docker
6363
volumes:
6464
- ./syncmaster:/app/syncmaster
65+
- ./tests:/app/tests
66+
- ./reports:/app/reports
6567
- ./pyproject.toml:/app/pyproject.toml
6668
depends_on:
6769
db:
6870
condition: service_healthy
6971
rabbitmq:
7072
condition: service_healthy
71-
entrypoint: [python, -m, syncmaster.scheduler]
73+
entrypoint: [coverage, run, -m, syncmaster.scheduler]
7274
profiles: [scheduler, all]
7375

7476
worker:

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ services:
6565
rabbitmq:
6666
condition: service_healthy
6767

68+
scheduler:
69+
image: mtsrus/syncmaster-scheduler:${TAG:-develop}
70+
restart: unless-stopped
71+
build:
72+
dockerfile: docker/Dockerfile.scheduler
73+
context: .
74+
env_file: .env.docker
75+
volumes:
76+
- ./syncmaster:/app/syncmaster
77+
- ./pyproject.toml:/app/pyproject.toml
78+
depends_on:
79+
db:
80+
condition: service_healthy
81+
rabbitmq:
82+
condition: service_healthy
83+
entrypoint: [python, -m, syncmaster.scheduler]
84+
6885
volumes:
6986
postgres_data:
7087
rabbitmq_data:

docker/Dockerfile.backend

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
ARG BASE_IMAGE=python:3.12-slim
22
FROM $BASE_IMAGE AS base
33

4-
RUN pip install --no-cache-dir --timeout 3 --retries 3 poetry \
4+
RUN apt-get update && apt-get install -y curl \
5+
&& rm -rf /var/lib/apt/lists/*
6+
7+
RUN curl -sSL https://install.python-poetry.org | python3 - \
8+
&& ln -s /root/.local/bin/poetry /usr/local/bin/poetry \
59
&& poetry config virtualenvs.create false
610

711
WORKDIR /app

docker/Dockerfile.scheduler

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM python:3.12-slim AS base
2+
3+
RUN apt-get update && apt-get install -y curl \
4+
&& rm -rf /var/lib/apt/lists/*
5+
6+
RUN curl -sSL https://install.python-poetry.org | python3 - \
7+
&& ln -s /root/.local/bin/poetry /usr/local/bin/poetry \
8+
&& poetry config virtualenvs.create false
9+
10+
WORKDIR /app
11+
ENV PYTHONPATH=/app
12+
13+
COPY ./pyproject.toml ./poetry.lock* /app/
14+
15+
RUN pip install --upgrade pip setuptools wheel packaging
16+
RUN poetry install --no-root --extras "scheduler" --without test,docs,dev
17+
18+
FROM base AS prod
19+
20+
COPY ./syncmaster/ /app/syncmaster/
21+
22+
FROM base as test
23+
24+
RUN poetry install --no-root --all-extras --with test --without docs,dev

docker/Dockerfile.worker

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ RUN apt-get update && apt-get install -y \
1717
libffi-dev \
1818
&& rm -rf /var/lib/apt/lists/*
1919

20-
RUN pip install --no-cache-dir --timeout 3 --retries 3 poetry && poetry config virtualenvs.create false
20+
RUN apt-get update && apt-get install -y curl \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
RUN curl -sSL https://install.python-poetry.org | python3 - \
24+
&& ln -s /root/.local/bin/poetry /usr/local/bin/poetry \
25+
&& poetry config virtualenvs.create false
2126

2227
WORKDIR /app
2328
ENV PYTHONPATH=/app

0 commit comments

Comments
 (0)