Skip to content

Commit

Permalink
Cicd (#30)
Browse files Browse the repository at this point in the history
* Added CICD (#28)

* Revert some changes.

* Add Dockerfile.

* Add github actions.

* Add some operation stuff.

* Comment build and deploy stages in CI/CD.

---------

Co-authored-by: GolovkinAlexander <112856471+GolovkinAlexander@users.noreply.github.com>
  • Loading branch information
TyVik and GolovkinAlexander authored Sep 8, 2024
1 parent 30dd56c commit ca63376
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
.idea
.env
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
ignore = E501, E203, E305, F401, F541
exclude =
.venv,
.git,
__pycache__
max-line-length = 120
84 changes: 84 additions & 0 deletions .github/workflows/ci-cd-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: KrdDevBot CI/CD Pipeline

on:
push:
branches:
- cicd

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install PDM
run: |
python -m pip install --upgrade pip
pip install pdm
- name: Install dependencies using PDM
run: |
pdm install --dev
- name: Run tests
run: |
pdm run pytest
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install PDM
run: |
python -m pip install --upgrade pip
pip install pdm
- name: Install dependencies using PDM
run: |
pdm install --dev
- name: Run linters
run: |
pdm run flake8
# build:
# needs: [test, lint]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - 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: Build and push
# uses: docker/build-push-action@v5
# with:
# push: true
# tags: krddev/bot:$GITHUB_REF_TYPE
#
# deploy:
# needs: [build]
# runs-on: ubuntu-latest
# steps:
# - name: Add SSH key
# uses: webfactory/ssh-agent@v0.5.3
# with:
# ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
#
# - name: Deploy
# run: |
# ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} << 'EOF'
# cd ~/krddevbot
# git pull
# docker build -t krddev/bot:main .
# sudo systemctl restart krddevbot.service
# EOF
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
ARG PYTHON_BASE=3.10-slim

FROM python:$PYTHON_BASE AS builder

ENV PDM_CHECK_UPDATE=false

WORKDIR /app

RUN pip install --no-cache-dir -U pdm \
&& find /usr/local/lib -name "*.pyc" -exec rm -f {} \;

COPY pyproject.toml pdm.lock /app/

RUN pdm install --check --prod --no-editable \
&& find /usr/local/lib -name "*.pyc" -exec rm -f {} \;

RUN pdm export --dev --without-hashes > /app/.venv/requirements.txt

FROM python:$PYTHON_BASE

WORKDIR /app

COPY --from=builder /app/.venv/ /app/.venv

ENV PATH="/app/.venv/bin:$PATH"
COPY . .

CMD ["python3", "-m", "krddevbot"]
11 changes: 11 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'

services:
krddevbot:
image: krddev/bot:main
container_name: krddevbot
restart: always
volumes:
- ~/krddevbot/tander:/app/tander
env_file:
- ~/krddevbot/.env
15 changes: 15 additions & 0 deletions krddevbot.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=KrdDevBot systemd service
PartOf=docker.service
After=docker.service

[Service]
Type=oneshot
User=krddev
RemainAfterExit=true
WorkingDirectory=/home/krddev/
ExecStart=docker compose up -d --remove-orphans
ExecStop=docker compose down

[Install]
WantedBy=multi-user.target
3 changes: 2 additions & 1 deletion krddevbot/tander/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import pathlib
import re
from datetime import datetime, UTC
from pytz import UTC
from datetime import datetime

from telegram import Update
from telegram.ext import ContextTypes
Expand Down
47 changes: 46 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ bot = "python -m krddevbot"
[tool.pdm.dev-dependencies]
dev = [
"pytest>=8.0.0",
]
"flake8>=5.0.0",
]

0 comments on commit ca63376

Please sign in to comment.