Skip to content

Commit

Permalink
Merge pull request #1 from ImMohammad20000/Dockerize
Browse files Browse the repository at this point in the history
Dockerize project
  • Loading branch information
erfjab authored Sep 14, 2024
2 parents 21c51ae + 7a2cfa5 commit ad7d269
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 11 deletions.
20 changes: 20 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**/node_modules
__pycache__
*.pyc
*.pyo
*.pyd
.env*
db.sqlite3
db.sqlite3-journal
*.log
*.git
*.github
docker-compose.yml
docker-compose.debug.yml
docker-compose-marzban.yml
Makefile
openapi-generator-config.yaml
openapi.json
README.md
.gitignore
*.env*
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build

on:
push:
tags:
- "v*.*.*"

jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
erfjab/ServerManagerBot:latest
erfjab/ServerManagerBot:${{github.ref_name}}
ghcr.io/erfjab/ServerManagerBot:latest
ghcr.io/erfjab/ServerManagerBot:${{github.ref_name}}
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.11.8-alpine

ENV PYTHONUNBUFFERED 1

WORKDIR /code

COPY ./requirements.txt .

RUN pip install --no-cache-dir --upgrade -r requirements.txt

COPY . .

RUN chmod +x main.py

CMD [ "./main.py" ]
24 changes: 13 additions & 11 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json
from log import logger
from typing import Dict, Optional

from log import logger

# Configuration file path
CONFIG_FILE = '.json'
CONFIG_FILE = 'data/.info.json'


class ConfigManager:
_config: Optional[Dict] = None
Expand All @@ -12,7 +14,7 @@ class ConfigManager:
def _load_config() -> Optional[Dict]:
"""
Load configuration from the JSON file.
Returns:
Optional[Dict]: The loaded configuration as a dictionary if successful,
None if there was an error.
Expand All @@ -32,7 +34,7 @@ def get_config() -> Optional[Dict]:
"""
Retrieve the configuration from the cache.
If not cached, load it from the file.
Returns:
Optional[Dict]: The configuration dictionary if successful, None otherwise.
"""
Expand All @@ -44,10 +46,10 @@ def get_config() -> Optional[Dict]:
def get_admin_key(admin_chatid: int) -> Optional[str]:
"""
Get the Hetzner API key for a specific admin chat ID.
Args:
admin_chatid (int): The chat ID of the admin.
Returns:
Optional[str]: The Hetzner API key if the admin chat ID exists, None otherwise.
"""
Expand All @@ -61,7 +63,7 @@ def get_admin_key(admin_chatid: int) -> Optional[str]:
def get_bot_token() -> Optional[str]:
"""
Get the Telegram bot token.
Returns:
Optional[str]: The Telegram bot token if available, None otherwise.
"""
Expand All @@ -74,7 +76,7 @@ def get_bot_token() -> Optional[str]:
def get_all_admin_keys() -> Optional[Dict[int, str]]:
"""
Get a dictionary of all admin chat IDs and their corresponding Hetzner API keys.
Returns:
Optional[Dict[int, str]]: A dictionary mapping admin chat IDs to Hetzner API keys,
or None if configuration could not be loaded.
Expand All @@ -88,11 +90,11 @@ def get_all_admin_keys() -> Optional[Dict[int, str]]:
def is_admin(chat_id: int) -> bool:
"""
Check if a given chat ID is an admin.
Args:
chat_id (int): The chat ID to check.
Returns:
bool: True if the chat ID is an admin, False otherwise.
"""
return str(chat_id) in ConfigManager.get_all_admin_keys()
return str(chat_id) in ConfigManager.get_all_admin_keys()
File renamed without changes.
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
ServerManagerBot:
image: erfjab/ServerManagerBot:latest
restart: always
volumes:
- ./data/:/code/data/

0 comments on commit ad7d269

Please sign in to comment.