Skip to content

Commit

Permalink
Feature/ci cd (#22)
Browse files Browse the repository at this point in the history
* beginning of ci/cd implementation

* added ci-cd branch for testing

* fix branches to build
  • Loading branch information
ilyarolf authored Feb 28, 2024
1 parent 2441c7b commit 4bd63a1
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
.idea
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ WEBAPP_PORT =
TOKEN = ""
ADMIN_ID_LIST =
SUPPORT_LINK = ""
DB_NAME = ""
DB_NAME = ""
NGROK_TOKEN = ""
29 changes: 29 additions & 0 deletions .github/worflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build and Push Docker Image

on:
push:
branches: [master, feature/sqlalchemy-sqlcipher]

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

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

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/AiogramShopBot:latest
- name: clean all
run: rm -rf ./*
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.9-slim

WORKDIR /bot
COPY . /bot/
RUN pip install --no-cache-dir -r requirements.txt
ENV PYTHONUNBUFFERED=1
CMD ["python3", "-u", "/bot/main.py"]
8 changes: 3 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from dotenv import load_dotenv
import os

from ngrok_executor import start_ngrok

load_dotenv()

WEBHOOK_HOST = os.environ.get("WEBHOOK_HOST")
WEBHOOK_HOST = start_ngrok()
WEBHOOK_PATH = os.environ.get("WEBHOOK_PATH")
WEBAPP_HOST = os.environ.get("WEBAPP_HOST")
WEBAPP_PORT = os.environ.get("WEBAPP_PORT")
DB_PASS = os.environ.get("DB_PASS")
MNEMONIC = os.environ.get("MNEMONIC")
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
TOKEN = os.environ.get("TOKEN")
ADMIN_ID_LIST = os.environ.get("ADMIN_ID_LIST").split(',')
ADMIN_ID_LIST = [int(admin_id) for admin_id in ADMIN_ID_LIST]
SUPPORT_LINK = os.environ.get("SUPPORT_LINK")
DB_NAME = os.environ.get("DB_NAME")
DB_ENCRYPTION = os.environ.get("DB_ENCRYPTION") == "True"
ADDITIVE = os.environ.get("ADDITIVE")
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "3.8"
services:
bot:
build:
context: .
container_name: 'AiogramShopBot'
environment:
WEBHOOK_PATH: ""
WEBAPP_HOST: "0.0.0.0" # Don't touch this
WEBAPP_PORT: 5000 # Here your port
TOKEN: "1234567890:QWER.....TYI" # Here your bot token from botfather
NGROK_TOKEN: 'NGROK_TOKEN_HERE' # Here your ngrok token from ngrok.com
ADMIN_ID_LIST: 12345678,87654321 # Telegram ID's for admins;
SUPPORT_LINK: "https://t.me/YourUsername"
DB_NAME: "database.db" # Here your database name
ports:
- "4040:4040"
- 5000:${WEBAPP_PORT}
expose:
- 4040
- ${WEBAPP_PORT}
volumes:
- /AiogramShopBot:/bot/${DB_NAME}

volumes:
AiogramShopBot:
11 changes: 11 additions & 0 deletions ngrok_executor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os

from pyngrok import ngrok


def start_ngrok():
ngrok_token = os.environ.get("NGROK_TOKEN")
port = os.environ.get("WEBAPP_PORT")
ngrok.set_auth_token(ngrok_token)
http_tunnel = ngrok.connect(f":{port}", "http")
return http_tunnel.public_url
Binary file modified requirements.txt
Binary file not shown.

0 comments on commit 4bd63a1

Please sign in to comment.