Skip to content

Commit 355098e

Browse files
committed
Update CI; change .secrets.toml to settings.toml; more info about funcs; small fixes
1 parent 2905ecb commit 355098e

8 files changed

Lines changed: 64 additions & 52 deletions

File tree

.github/workflows/release.yaml

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -103,52 +103,35 @@ jobs:
103103
strategy:
104104
matrix:
105105
include:
106-
- os: windows-latest
107-
TARGET: windows
108-
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
109-
OUT_FILE_NAME: truth_seeker.exe
110-
ASSET_MIME: application/vnd.microsoft.portable-executable
111106
- os: ubuntu-latest
112-
TARGET: ubuntu
113-
CMD_BUILD: python -m PyInstaller --clean --workpath /tmp/build --specpath /tmp -F ./app/truth_seeker.py
114-
OUT_FILE_NAME: truth_seeker
115-
ASSET_MIME: application/x-binary
107+
SERVICENAME: news_db
108+
CONTAINERFILE: Containerfile-db
109+
- os: ubuntu-latest
110+
SERVICENAME: truth_seeker
111+
CONTAINERFILE: Containerfile-ts
112+
- os: ubuntu-latest
113+
SERVICENAME: datapath
114+
CONTAINERFILE: Containerfile-dp
116115

117116
steps:
118117

119-
- name: Checkout code
120-
uses: actions/checkout@v2
121-
122-
- name: Set up Python 3.9
123-
uses: actions/setup-python@v2
118+
- name: Login to DockerHub
119+
uses: docker/login-action@v1
124120
with:
125-
python-version: 3.9
126-
127-
- name: Install dependencies
128-
run: |
129-
python -m pip install --upgrade pip
130-
pip install -r requirements.txt
131-
132-
- name: Build with pyinstaller for ${{ matrix.TARGET }}
133-
run: ${{ matrix.CMD_BUILD }}
121+
username: ${{ secrets.DOCKER_USERNAME }}
122+
password: ${{ secrets.DOCKER_TOKEN }}
134123

135-
- name: Upload Artifacts
136-
uses: actions/upload-artifact@v3
137-
with:
138-
name: ${{ matrix.OUT_FILE_NAME }}
139-
path: ./dist/${{ matrix.OUT_FILE_NAME }}
140-
retention-days: 1
124+
- name: Checkout code
125+
uses: actions/checkout@v2
141126

142-
- name: Upload Release Asset
143-
id: upload-release-asset
144-
uses: actions/upload-release-asset@v1
145-
env:
146-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127+
- name: Build and push
128+
id: push_image
129+
uses: docker/build-push-action@v2
147130
with:
148-
upload_url: ${{ needs.release.outputs.get_release_url }}
149-
asset_path: ./dist/${{ matrix.OUT_FILE_NAME }}
150-
asset_name: ${{ matrix.OUT_FILE_NAME }}
151-
asset_content_type: ${{ matrix.ASSET_MIME }}
131+
context: .
132+
push: true
133+
file: ${{ matrix.CONTAINERFILE }}
134+
tags: h0d0user/${{ matrix.SERVICENAME }}:latest
152135

153136
- name: Notify if failure
154137
if: ${{ failure() }}
@@ -186,6 +169,11 @@ jobs:
186169
187170
Branch: ${{ github.ref }}
188171
172+
<b>Pushed image:</b> <code>docker pull h0d0user/news_db:latest</code>,
173+
<code>docker pull h0d0user/truth_seeker:latest</code>,
174+
<code>docker pull h0d0user/datapath:latest</code>
175+
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}
176+
189177
<b>Release URL:</b> https://github.com/${{ github.repository }}/releases/tag/${{ needs.prepare.outputs.get_current_tag }}
190178
191179
See changes: https://github.com/${{ github.repository }}/commit/${{ github.sha }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ dmypy.json
129129
.pyre/
130130

131131
# Secret file
132-
.secrets.toml
132+
settings.toml
133133

134134
# Database files
135135
*.db

datapath.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626

2727

2828
def send_news_to_telegram(message):
29+
"""
30+
Send messages from db to telegram
31+
:param message:
32+
:return:
33+
"""
2934
try:
3035
response = requests.post(API_URL, json={"chat_id": CHAT_ID, "text": message})
3136
if response.status_code == 200:

docker-compose.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@ version: '3'
33
services:
44
news_db:
55
container_name: news_db
6-
image: h0d0user/news_db:v0.0.49
6+
image: h0d0user/news_db:latest
77
restart: always
88
network_mode: host
99
volumes:
1010
- "shared-volume:/mnt/"
11-
- ".secrets.toml:/opt/.secrets.toml"
11+
- "settings.toml:/opt/settings.toml"
1212

1313
truth_seeker:
1414
container_name: truth_seeker
15-
image: h0d0user/truth_seeker:v0.0.49
15+
image: h0d0user/truth_seeker:latest
1616
restart: always
1717
network_mode: host
1818
depends_on:
1919
- "news_db"
2020
volumes:
2121
- "shared-volume:/mnt/"
22-
- ".secrets.toml:/opt/.secrets.toml"
22+
- "settings.toml:/opt/settings.toml"
2323

2424
datapath:
2525
container_name: datapath
26-
image: h0d0user/datapath:v0.0.49
26+
image: h0d0user/datapath:latest
2727
restart: always
2828
network_mode: host
2929
depends_on:
3030
- "news_db"
3131
volumes:
3232
- "shared-volume:/mnt/"
33-
- ".secrets.toml:/opt/.secrets.toml"
33+
- "settings.toml:/opt/settings.toml"
3434

3535
volumes:
3636
shared-volume:

dynaconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99

1010
settings = Dynaconf(
11-
settings_files=[".secrets.toml"],
11+
settings_files=["settings.toml"],
1212
)
1313

1414
if __name__ == "__main__":

news_db.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
from pathlib import Path
66
from sqlite3 import Error
77

8-
TIME_TO_PURGE = "00:00"
8+
import dynaconfig
99

10+
TIME_TO_PURGE = "00:00"
1011

11-
DB_FILE = Path("/mnt/test.db")
12+
DB_FILE = Path(f"/mnt/{dynaconfig.settings['DB_NAME']}")
1213

14+
# SQL queries
1315
CREATE_TABLE_SQL = """
1416
CREATE TABLE IF NOT EXISTS news (
1517
author TEXT,
@@ -46,6 +48,11 @@
4648

4749

4850
def create_connection(db_file: Path):
51+
"""
52+
Create db file
53+
:param db_file: path to db file to create
54+
:return:
55+
"""
4956
try:
5057
conn = sqlite3.connect(db_file)
5158
logging.info("Connection created successfully !")
@@ -72,6 +79,7 @@ def create_table(conn, create_table_query):
7279
def insert_into(conn, data: tuple):
7380
"""
7481
Insert data to base
82+
This is the load step in ETL pipeline
7583
:param conn: Connection to the SQLite database
7684
:param data:
7785
:return:

truth_seeker.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
import dynaconfig
88
import news_db
99

10+
# Load variables from settings.toml
1011
API_KEY = dynaconfig.settings["API_KEY"]
1112
QUERY = dynaconfig.settings["QUERY"]
1213

13-
# Use to get news from yesterday to current time
14-
YESTERDAY = date.today() - timedelta(days=1)
15-
1614
newsapi = NewsApiClient(api_key=API_KEY)
1715

1816
TIME_TO_SEARCH = "11:10"
@@ -31,9 +29,16 @@
3129

3230

3331
def fetch_info() -> dict:
32+
"""
33+
Fetch info from API according to query in settings.toml
34+
This is the extraction step in ETL pipeline
35+
:return:
36+
"""
37+
# Use to get news from yesterday to current time
38+
yesterday = date.today() - timedelta(days=1)
3439
try:
3540
result = newsapi.get_everything(
36-
q=QUERY, sort_by="popularity", from_param=YESTERDAY
41+
q=QUERY, sort_by="popularity", from_param=yesterday
3742
)
3843
logging.info(f"Searching for {QUERY}")
3944
return result
@@ -46,6 +51,12 @@ def fetch_info() -> dict:
4651

4752

4853
def load_to_db(fetch_info: dict):
54+
"""
55+
Load specific info to db
56+
These are the transform and load steps in ETL pipeline
57+
:param fetch_info:
58+
:return:
59+
"""
4960
if fetch_info:
5061
for article in fetch_info.get("articles"):
5162
article_list = []

0 commit comments

Comments
 (0)