Skip to content

Commit 7006fa2

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

File tree

10 files changed

+235
-97
lines changed

10 files changed

+235
-97
lines changed
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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ 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+
depends_on:
76+
db:
77+
condition: service_healthy
78+
rabbitmq:
79+
condition: service_healthy
80+
6881
volumes:
6982
postgres_data:
7083
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
COPY ./docker/entrypoint_scheduler.sh /app/entrypoint.sh
19+
ENTRYPOINT ["/app/entrypoint.sh"]
20+
21+
FROM base AS prod
22+
23+
COPY ./syncmaster/ /app/syncmaster/
24+
25+
FROM base as test
26+
27+
RUN poetry install --no-root --all-extras --with test --without docs,dev
28+
RUN sed -i 's/python -m/coverage run -m/g' /app/entrypoint.sh

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

docker/entrypoint_scheduler.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
exec python -m syncmaster.scheduler
5+

0 commit comments

Comments
 (0)