Skip to content

Commit

Permalink
[IMPROVEMENT] - add scheduler Docker image (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-lixakov authored Nov 29, 2024
1 parent f18e073 commit f8103ae
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 97 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/scheduler_docker_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Scheduler docker image

on:
push:
branches:
- develop
tags:
- '[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

jobs:
release:
name: Build & push scheduler image to Dockerhub
runs-on: ubuntu-latest
if: github.repository == 'MobileTeleSystems/syncmaster' # prevent running on forks

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Checkout code
uses: actions/checkout@v4

- name: Set tag
id: set_tag
run: |
if [[ "${{ github.ref_type }}" == "branch" && "${{ github.ref_name }}" == "develop" ]]; then
echo "TAG=mtsrus/syncmaster-scheduler:develop" >> $GITHUB_ENV
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
echo "TAG=mtsrus/syncmaster-scheduler:latest,mtsrus/syncmaster-scheduler:${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Build scheduler image
uses: docker/build-push-action@v6
with:
tags: ${{ env.TAG }}
context: .
target: prod
file: docker/Dockerfile.scheduler
pull: true
push: true
cache-to: type=inline
cache-from: mtsrus/syncmaster-scheduler:develop
platforms: |
linux/amd64
linux/arm64/v8
provenance: mode=max

- name: Convert README to Markdown
uses: docker://pandoc/core:2.9
with:
args: >-
--output=README.md
--from=rst
--to=gfm
--wrap=none
README.rst
- name: Update DockerHub Description
uses: peter-evans/dockerhub-description@v4
if: github.ref_type == 'tag'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
# this requires token with read+write+delete permissions. read+write is not enough!
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: mtsrus/syncmaster-scheduler
short-description: ${{ github.event.repository.description }}
enable-url-completion: true
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Install dependencies
run: |
poetry install --no-root --extras "backend" --with test
poetry install --no-root --all-extras --with test
- name: Start docker compose
run: |
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,23 @@ services:
profiles: [backend, all]

scheduler:
image: mtsrus/syncmaster-backend:${BACKEND_IMAGE_TAG:-test}
image: mtsrus/syncmaster-scheduler:${SCHEDULER_IMAGE_TAG:-test}
restart: unless-stopped
build:
dockerfile: docker/Dockerfile.backend
dockerfile: docker/Dockerfile.scheduler
context: .
target: test
env_file: .env.docker
volumes:
- ./syncmaster:/app/syncmaster
- ./tests:/app/tests
- ./reports:/app/reports
- ./pyproject.toml:/app/pyproject.toml
depends_on:
db:
condition: service_healthy
rabbitmq:
condition: service_healthy
entrypoint: [python, -m, syncmaster.scheduler]
profiles: [scheduler, all]

worker:
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ services:
rabbitmq:
condition: service_healthy

scheduler:
image: mtsrus/syncmaster-scheduler:${TAG:-develop}
restart: unless-stopped
build:
dockerfile: docker/Dockerfile.scheduler
context: .
env_file: .env.docker
depends_on:
db:
condition: service_healthy
rabbitmq:
condition: service_healthy

volumes:
postgres_data:
rabbitmq_data:
6 changes: 5 additions & 1 deletion docker/Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
ARG BASE_IMAGE=python:3.12-slim
FROM $BASE_IMAGE AS base

RUN pip install --no-cache-dir --timeout 3 --retries 3 poetry \
RUN apt-get update && apt-get install -y curl \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sSL https://install.python-poetry.org | python3 - \
&& ln -s /root/.local/bin/poetry /usr/local/bin/poetry \
&& poetry config virtualenvs.create false

WORKDIR /app
Expand Down
28 changes: 28 additions & 0 deletions docker/Dockerfile.scheduler
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM python:3.12-slim AS base

RUN apt-get update && apt-get install -y curl \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sSL https://install.python-poetry.org | python3 - \
&& ln -s /root/.local/bin/poetry /usr/local/bin/poetry \
&& poetry config virtualenvs.create false

WORKDIR /app
ENV PYTHONPATH=/app

COPY ./pyproject.toml ./poetry.lock* /app/

RUN pip install --upgrade pip setuptools wheel packaging
RUN poetry install --no-root --extras "scheduler" --without test,docs,dev

COPY ./docker/entrypoint_scheduler.sh /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]

FROM base AS prod

COPY ./syncmaster/ /app/syncmaster/

FROM base as test

Check warning on line 25 in docker/Dockerfile.scheduler

View workflow job for this annotation

GitHub Actions / Build & push scheduler image to Dockerhub

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

RUN poetry install --no-root --all-extras --with test --without docs,dev
RUN sed -i 's/python -m/coverage run -m/g' /app/entrypoint.sh
7 changes: 6 additions & 1 deletion docker/Dockerfile.worker
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ RUN apt-get update && apt-get install -y \
libffi-dev \
&& rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir --timeout 3 --retries 3 poetry && poetry config virtualenvs.create false
RUN apt-get update && apt-get install -y curl \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sSL https://install.python-poetry.org | python3 - \
&& ln -s /root/.local/bin/poetry /usr/local/bin/poetry \
&& poetry config virtualenvs.create false

WORKDIR /app
ENV PYTHONPATH=/app
Expand Down
4 changes: 4 additions & 0 deletions docker/entrypoint_scheduler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -e

exec python -m syncmaster.scheduler "$@"
Loading

0 comments on commit f8103ae

Please sign in to comment.