Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #38

Merged
merged 31 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
86d273b
Fix error logging format
orenlab May 18, 2024
0087206
Change app version to dev
orenlab May 18, 2024
3499499
Fix #28
orenlab May 18, 2024
4c48531
Update README.md
orenlab May 18, 2024
8961866
Add inline_query in update_types
orenlab May 20, 2024
771c46b
Update dep
orenlab May 20, 2024
65bb52b
Update dep (in requests fix bug "Unknown URL-schema http+docker")
orenlab May 21, 2024
8e06d1e
Downgrade requests to version 2.31.0. Tests failed.
orenlab May 21, 2024
4eb98c2
Update Dockerfiles
orenlab May 21, 2024
ad1d0e9
Refactoring code
orenlab May 21, 2024
a3abb64
Remove unused handler
orenlab May 21, 2024
016f2f5
Update README.md
orenlab May 21, 2024
8c4a450
Redesigned logic in Dockerfiles
orenlab May 21, 2024
9660b3c
Update docker-compose.yml
orenlab May 21, 2024
1cf949d
Update hub.alpine.Dockerfile
orenlab May 21, 2024
adb12a7
Update installation.md
orenlab May 22, 2024
1661f2a
Add correct logger stage in telebot polling arg
orenlab May 23, 2024
e2c75b4
Update docker_image_release.yml
orenlab May 23, 2024
d7274db
Refactoring dockerfiles
orenlab May 23, 2024
c980536
Merge remote-tracking branch 'origin/development' into development
orenlab May 23, 2024
e2a5b52
Fix CI/CD error "buildx failed with: ERROR: failed to solve: process"
orenlab May 23, 2024
0300a4e
Fix CI/CD error "buildx failed with: ERROR: failed to solve: process"
orenlab May 23, 2024
0ad5573
Fix CI/CD error "buildx failed with: ERROR: failed to solve: process"
orenlab May 23, 2024
43e286f
update dep and fix #37
orenlab May 23, 2024
df23d87
Freeze deps in requirements.txt
orenlab May 23, 2024
9272624
Refactoring code in docker section
orenlab May 23, 2024
919c04b
Refactoring code in docker section
orenlab May 23, 2024
a79e2de
Refactoring code in docker section
orenlab May 23, 2024
9b229a2
Update docs
orenlab May 23, 2024
d150d21
Update bot tree in README.md
orenlab May 23, 2024
2a8847b
Bump version to 0.0.6 release
orenlab May 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ setup_req.txt
### Docker
# .dockerignore
.dockerignore
dev.Dockerfile
docker-compose.yml
Dockerfile
hub.alpine.Dockerfile
hub.ubuntu.Dockerfile
ubuntu.Dockerfile
hub.Dockerfile
#######################################
### pyTMbot
# app dir
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker_build_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Build the Docker image
run: docker build . --file hub.alpine.Dockerfile --tag orenlab/pytmbot:$(date +%s)
run: docker build . --target prod --tag orenlab/pytmbot:$(date +%s)
3 changes: 2 additions & 1 deletion .github/workflows/docker_dev_alpine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- name: Build and push
uses: docker/build-push-action@v5
with:
file: hub.alpine.Dockerfile
build-args: --target prod
file: hub.Dockerfile
push: true
tags: orenlab/pytmbot:alpine-dev
26 changes: 0 additions & 26 deletions .github/workflows/docker_dev_ubuntu.yml

This file was deleted.

5 changes: 3 additions & 2 deletions .github/workflows/docker_image_release_cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ jobs:
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: orenlab/pytmbot
images: ${{ github.repository }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: hub.alpine.Dockerfile
file: Dockerfile
build-args: --target prod
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
58 changes: 39 additions & 19 deletions .run/Dockerfile.run.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="latest"/>
<option name="containerName" value="pytmbot"/>
<option name="sourceFilePath" value="Dockerfile"/>
<option name="volumeBindings">
<list>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/var/run/docker.sock"/>
<option name="hostPath" value="/var/run/docker.sock"/>
<option name="readOnly" value="true"/>
</DockerVolumeBindingImpl>
</list>
</option>
</settings>
</deployment>
<method v="2"/>
</configuration>
<configuration default="false" name="Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="latest" />
<option name="containerName" value="pytmbot" />
<option name="sourceFilePath" value="Dockerfile" />
<option name="volumeBindings">
<list>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/var/run/docker.sock" />
<option name="hostPath" value="/var/run/docker.sock" />
<option name="readOnly" value="true" />
</DockerVolumeBindingImpl>
</list>
</option>
</settings>
</deployment>
<method v="2" />
</configuration>
<configuration default="false" name="Dockerfile" type="docker-deploy" factoryName="dockerfile" server-name="Docker">
<deployment type="dockerfile">
<settings>
<option name="imageTag" value="dev-latest-loc" />
<option name="buildCliOptions" value="--target selfbuild_dev" />
<option name="containerName" value="pytmbot" />
<option name="sourceFilePath" value="Dockerfile" />
<option name="volumeBindings">
<list>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/var/run/docker.sock" />
<option name="hostPath" value="/var/run/docker.sock" />
<option name="readOnly" value="true" />
</DockerVolumeBindingImpl>
</list>
</option>
</settings>
</deployment>
<method v="2" />
</configuration>
</component>
21 changes: 0 additions & 21 deletions .run/Dockerfile_dev.run.xml

This file was deleted.

125 changes: 72 additions & 53 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
#######################################
# pyTMbot Dockerfile (based on Alpine)
# image size: ~ 90Mb
#############################################################
## pyTMbot Dockerfile
# https://github.com/orenlab/pytmbot
#######################################
#
# To launch with a production token. Default way:
# docker --target prod build -t orenlab/pytmbot:latest .
#
# To launch with a development token. Only for development:
# docker --target dev build -t orenlab/pytmbot:latest .
#############################################################

# Set Alpine tag version for first and second stage
ARG IMAGE_VERSION_FIRST=3.12.3-alpine3.19
ARG IMAGE_VERSION_SECOND=3.19.1
# Set base images tag
ARG PYTHON_IMAGE=3.12.3-alpine3.19
ARG ALPINE_IMAGE=3.19.1

# First stage
FROM python:$IMAGE_VERSION_FIRST AS builder
# Python version (minimal - 3.12)
ARG PYTHON_VERSION=3.12
########################################################################################################################
######################### BUILD ALPINE BASED IMAGE #####################################################################
########################################################################################################################

COPY requirements.txt .
# Zero Alpine stage - setup base image
FROM alpine:${ALPINE_IMAGE} AS alpine_base

# Update base os components and install all deps (need to build psutil)
# Update base os components
RUN apk --no-cache update && \
apk --no-cache upgrade && \
apk --no-cache add gcc python3-dev musl-dev linux-headers

# Install dependencies to the venv path
RUN python$PYTHON_VERSION -m venv --without-pip venv
RUN pip install --no-cache --target="/venv/lib/python$PYTHON_VERSION/site-packages" -r requirements.txt

RUN python -m pip uninstall pip setuptools python3-wheel python3-dev -y

# Second unnamed stage
FROM alpine:$IMAGE_VERSION_SECOND
# Python version (minimal - 3.12)
ARG PYTHON_VERSION=3.12

# Add Timezone support in Alpine image
RUN apk --no-cache add tzdata
apk --no-cache add tzdata

# App workdir
WORKDIR /opt/pytmbot/
Expand All @@ -43,42 +35,69 @@ ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONPATH=/opt/pytmbot
ENV PATH=/venv/bin:$PATH

# Copy lisence
COPY LICENSE /opt/pytmbot/

# Copy bot files
COPY ./app ./app/
COPY ./logs /opt/logs/

# First Alpine stage - build Python deps
FROM python:${PYTHON_IMAGE} AS builder

# Python version (minimal - 3.12)
ARG PYTHON_VERSION=3.12

COPY requirements.txt .

# Install all deps (need to build psutil)
RUN apk --no-cache add gcc python3-dev musl-dev linux-headers

# Install dependencies to the venv path
RUN python${PYTHON_VERSION} -m venv --without-pip venv
RUN pip install --no-cache-dir --no-deps --target="/venv/lib/python${PYTHON_VERSION}/site-packages" -r requirements.txt

RUN python${PYTHON_VERSION} -m pip uninstall pip setuptools python3-wheel python3-dev musl-dev -y

# Second Alpine stage - based on the base stage. Setup bot
FROM alpine_base AS reliase_base

# Python version (minimal - 3.12)
ARG PYTHON_VERSION=3.12

# Сopy only the necessary python files and directories from first stage
COPY --from=builder /usr/local/bin/python3 /usr/local/bin/python3
COPY --from=builder /usr/local/bin/python$PYTHON_VERSION /usr/local/bin/python$PYTHON_VERSION
COPY --from=builder /usr/local/lib/python$PYTHON_VERSION /usr/local/lib/python$PYTHON_VERSION
COPY --from=builder /usr/local/lib/libpython$PYTHON_VERSION.so.1.0 /usr/local/lib/libpython$PYTHON_VERSION.so.1.0
COPY --from=builder /usr/local/bin/python${PYTHON_VERSION} /usr/local/bin/python${PYTHON_VERSION}
COPY --from=builder /usr/local/lib/python${PYTHON_VERSION} /usr/local/lib/python${PYTHON_VERSION}
COPY --from=builder /usr/local/lib/libpython${PYTHON_VERSION}.so.1.0 /usr/local/lib/libpython${PYTHON_VERSION}.so.1.0
COPY --from=builder /usr/local/lib/libpython3.so /usr/local/lib/libpython3.so

# Copy only the dependencies installation from the first stage image
COPY --from=builder /venv /venv

# Copy .pytmbotenv file with token (prod, dev)
COPY .pytmbotenv /opt/pytmbot
# activate venv
RUN source /venv/bin/activate && \
# forward logs to Docker's log collector
ln -sf /dev/stdout /opt/logs/pytmbot.log

# Copy lisence
COPY LICENSE /opt/pytmbot

# Copy bot files
COPY ./app ./app/
COPY ./logs /opt/logs/
# Target for CI/CD image, --mode = prod
FROM reliase_base AS prod

CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ]

# Update base os components
RUN apk --no-cache update && \
apk --no-cache upgrade && \
# activate venv
source /venv/bin/activate && \
# forward logs to Docker's log collector
ln -sf /dev/stdout /opt/logs/pytmbot.log
# Target for self biuld image, --mode = prod
FROM reliase_base AS selfbuild_prod

# Copy .pytmbotenv file with token (prod, dev)
COPY .pytmbotenv /opt/pytmbot/

# Run app
# !!! needed set log level:
# - DEBUG
# - INFO (default)
# - ERROR
# - CRITICAL
# !!! needed set pyTMBot mode:
# - dev
# - prod (default)
CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=prod" ]

# Target for self biuld image, --mode = dev
FROM reliase_base AS selfbuild_dev

# Copy .pytmbotenv file with token (prod, dev)
COPY .pytmbotenv /opt/pytmbot/

CMD [ "/venv/bin/python3", "app/main.py", "--log-level=INFO", "--mode=dev" ]
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The bot operates synchronously. It does not use webhooks.
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=orenlab_pytmbot&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=orenlab_pytmbot)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/abe0314bb5c24cfda8db9c0a293d17c0)](https://app.codacy.com/gh/orenlab/pytmbot/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![Docker Image Build CI/CD](https://github.com/orenlab/pytmbot/actions/workflows/docker_build_on_push.yml/badge.svg)](https://github.com/orenlab/pytmbot/actions/workflows/docker_build_on_push.yml)
![Docker Pulls](https://img.shields.io/docker/pulls/orenlab/pytmbot?link=https%3A%2F%2Fhub.docker.com%2Fr%2Forenlab%2Fpytmbot)

The bot was written using the [pyTelegramBotAPI](https://github.com/eternnoir/pyTelegramBotAPI).
Use [psutil](https://github.com/giampaolo/psutil) and [docker-py](https://github.com/docker/docker-py) libraries for
Expand Down Expand Up @@ -88,8 +89,7 @@ All failed attempts to authorize are logged with an `ERROR` flag.
│ │ │ ├── handler.py - Base handler class (abc)
│ │ │ ├── handlers_aggregator.py - Main handlers aggregator
│ │ │ └── inline_handlers
│ │ │ ├── __init__.py - Import all inline handlers
│ │ │ ├── inline_query_handler.py - Deprecated in next release
│ │ │ ├── __init__.py
│ │ │ └── swap_handler.py - Swap inline handler
│ │ ├── jinja2
│ │ │ ├── __init__.py
Expand Down Expand Up @@ -124,15 +124,13 @@ All failed attempts to authorize are logged with an `ERROR` flag.
│ ├── cfg_templates
│ │ └── env.py - Template for initial setup
│ └── fs.py - Filesystem utility
├── dev.Dockerfile - Dockerfile with mode=dev
├── docker-compose.yml - Docker Compose file (used main Dockerfile)
├── docs
│ ├── docker.md - README for hub.docker.com
│ ├── installation.md - Installation guide
│ ├── roadmap.md - Roadmap guide
│ └── screenshots.md - Bots screenshot
├── hub.alpine.Dockerfile - Dockerfile for Docker CI/CD based on Alpine
├── hub.ubuntu.Dockerfile - Dockerfile for Docker CI/CD based on Ubuntu
├── hub.Dockerfile - Dockerfile for Docker CI/CD based on Alpine
├── logs
│ └── pytmbot.log - Main logs file
├── poetry.lock - Poetry file
Expand All @@ -142,7 +140,6 @@ All failed attempts to authorize are logged with an `ERROR` flag.
├── setup_req.txt - Setup requirements
├── tests
│ └── bot_tests.py - Bots tests
└── ubuntu.Dockerfile - Dockerfile, based on Ubuntu image
```

## 📈 Roadmap
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

| Version | Supported |
|---------|--------------------|
| 0.0.5 | :white_check_mark: |
| < 0.0.5 | :x: |
| 0.0.6 | :white_check_mark: |
| < 0.0.6 | :x: |

## Reporting a Vulnerability

Expand Down
Loading
Loading