Skip to content

Commit 726e7af

Browse files
andrevisАндрей Игоревич Никитин
andauthored
Deploy
* deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy * deploy --------- Co-authored-by: Андрей Игоревич Никитин <[email protected]>
1 parent a1ad645 commit 726e7af

File tree

6 files changed

+36
-85
lines changed

6 files changed

+36
-85
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
deploy:
1010
runs-on: ubuntu-latest
1111
env: # Or as an environment variable
12-
JBOND_BOT_TOKEN: ${{ secrets.JBOND_BOT_TOKEN }}
12+
BRANCH: master
13+
DIRECTORY: /opt/jbond
1314
steps:
1415
- name: Checkout code
1516
uses: actions/checkout@v3
@@ -25,31 +26,28 @@ jobs:
2526
run: |
2627
python3 -m ensurepip
2728
pip3 install aiogram
28-
- name: Pull code
29-
uses: appleboy/[email protected]
30-
with:
31-
host: ${{ secrets.JBOND_SSH_HOST }}
32-
username: ${{ secrets.JBOND_SSH_USER }}
33-
password: ${{ secrets.JBOND_SSH_PASS }}
34-
#private_key: ${{ secrets.JBOND_SSH_PRIVATE_KEY }}
35-
script: |
36-
cd /opt
37-
git clone https://github.com/andrevis/jbond.git
38-
cd jbond
39-
git checkout master
40-
git pull origin master
41-
- name: Install
42-
uses: appleboy/[email protected]
43-
with:
44-
host: ${{ secrets.JBOND_SSH_HOST }}
45-
username: ${{ secrets.JBOND_SSH_USER }}
46-
password: ${{ secrets.JBOND_SSH_PASS }}
47-
#private_key: ${{ secrets.JBOND_SSH_PRIVATE_KEY }}
48-
script: |
49-
systemctl stop jbond.service
50-
systemctl disable jbond.service
51-
cp -f /opt/jbond/misc/jbond.service /usr/lib/systemd/system/
52-
systemctl daemon-reload
53-
systemctl enable jbond.service
54-
cp -f /opt/jbond/misc/jbond_logrotate /etc/logrotate.d/
55-
systemctl restart crond
29+
- name: install ssh keys
30+
# check this thread to understand why its needed:
31+
# <https://stackoverflow.com/a/70447517>
32+
run: |
33+
install -m 600 -D /dev/null ~/.ssh/id_rsa
34+
echo "${{ secrets.JBOND_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
35+
cat ~/.ssh/id_rsa
36+
ssh-keyscan -H ${{ secrets.JBOND_SSH_HOST }} > ~/.ssh/known_hosts
37+
- name: clone
38+
run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "rm -rf $DIRECTORY && git clone https://github.com/andrevis/jbond.git $DIRECTORY"
39+
- name: checkout-pull
40+
run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "cd $DIRECTORY && git checkout $BRANCH && git pull origin $BRANCH"
41+
- name: stop service
42+
run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "systemctl stop jbond.service && systemctl disable jbond.service"
43+
- name: set token
44+
run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "echo ${{ secrets.JBOND_BOT_TOKEN }} > $DIRECTORY/token"
45+
- name: setup service
46+
run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "cp -f $DIRECTORY/misc/jbond.service /usr/lib/systemd/system/"
47+
- name: enable service
48+
run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "systemctl daemon-reload && systemctl enable jbond.service && systemctl restart jbond.service"
49+
- name: setup logrotate
50+
run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "cp -f $DIRECTORY/misc/jbond_logrotate /etc/logrotate.d/ && systemctl restart crond"
51+
- name: cleanup keys
52+
if: always()
53+
run: rm -rf ~/.ssh/id_rsa

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
token
12
# Byte-compiled / optimized / DLL files
23
__pycache__/
34
*.py[cod]
@@ -174,9 +175,9 @@ cython_debug/
174175
.abstra/
175176

176177
# Visual Studio Code
177-
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
178+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
178179
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
179-
# and can be added to the global gitignore or merged into this file. However, if you prefer,
180+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
180181
# you could uncomment the following to ignore the enitre vscode folder
181182
# .vscode/
182183

src/jbond.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,6 @@
88
from aiogram import Bot, Dispatcher
99
from aiogram.fsm.storage.memory import MemoryStorage
1010

11-
# def signal_handler(sig, frame):
12-
# raise RuntimeError('Interrupted Ctrl+C')
13-
14-
# signal.signal(signal.SIGINT, signal_handler)
15-
16-
17-
bot = Bot(token=os.environ['JBOND_BOT_TOKEN'])
11+
with open("/opt/jbond/token", 'r') as token:
12+
bot = Bot(token=token.readline().strip())
1813
dispatcher = Dispatcher(storage=MemoryStorage())
19-
20-
21-
# async def main():
22-
# await dispatcher.start_polling(bot)
23-
24-
# def main():
25-
# timer = TimeThread()
26-
# timer.start()
27-
28-
# jbond = JBond()
29-
# jbond.start()
30-
31-
# while (True):
32-
# sleep(1)
33-
34-
# if __name__ == '__main__':
35-
# main()

src/logger.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,3 @@
44
LOG_FORMAT = '%(asctime)s(%(threadName)s) %(levelname)s - %(message)s'
55

66
logging.basicConfig(filename='/opt/jbond/jbond.log', level=logging.INFO)
7-
8-
# logger = logging.getLogger(__name__)
9-
10-
# handler = logging.StreamHandler(sys.stdout)
11-
# handler.setFormatter(logging.Formatter(fmt=LOG_FORMAT))
12-
# logging.getLogger().addHandler(handler)

src/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import os
12
import asyncio
23
from jbond import bot, dispatcher #,scheduler
34
from handlers.start import start_router
5+
from logger import *
6+
7+
logger = logging.getLogger("Main")
48

59

610
async def main():

src/time_source.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)