Skip to content

Commit

Permalink
Post screenshots; new deployment method
Browse files Browse the repository at this point in the history
* working on screenshots

* progress

* add tests

* python dependencies do not install in container

* stuff

* asdf

* new deploymeny method

* still need rate limit handling
  • Loading branch information
raphjaph authored Jan 31, 2023
1 parent bcd5ed5 commit dd7fe4c
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ord_bot/__pycache__/
ord_bot/credentials.py
*.png
9 changes: 0 additions & 9 deletions Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[packages]
feedparser = "==6.0.10"
tweepy = "==4.12.1"
selenium = "*"

[dev-packages]
isort = "*"
Expand Down
106 changes: 102 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions bin/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

set -euxo pipefail

apt-get update --yes && apt-get upgrade --yes
apt-get install --yes build-essential \
zlib1g-dev \
libncurses5-dev \
libgdbm-dev \
libnss3-dev \
libssl-dev \
libreadline-dev \
libffi-dev \
libsqlite3-dev \
wget \
libbz2-dev \
acl \
clang \
pkg-config \
software-properties-common \
ufw \
vim

if ! command -v python3.10 &> /dev/null; then
wget https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tgz
tar -xf Python-3.10.*.tgz
cd Python-3.10.*/
./configure --enable-optimizations
make altinstall
python3.10 -m ensurepip --upgrade
fi

if ! command -v google-chrome &> /dev/null; then
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt-get install -y ./google-chrome-stable_current_amd64.deb && apt-get install -fy
fi

if ! command -v chromedriver &> /dev/null; then
wget https://chromedriver.storage.googleapis.com/109.0.5414.74/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver /usr/bin/chromedriver
chown root:root /usr/bin/chromedriver
chmod +x /usr/bin/chromedriver
fi

pip3.10 install --upgrade setuptools pip

# id --user ord_bot || useradd --system ord_bot
# chown -R ord_bot:ord_bot /var/lib/ord_bot

cp ord_bot.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable ord_bot
systemctl restart ord_bot
19 changes: 19 additions & 0 deletions bin/ord_bot.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
After=network.target
Description=ord_bot
StartLimitBurst=120
StartLimitIntervalSec=10m

[Service]
User=root
WorkingDirectory=/var/lib/ord_bot
ExecStart=/usr/local/bin/pipenv run python3.10 /var/lib/ord_bot/ord_bot.py
Restart=on-failure
RestartSec=5s
StandardOutput=syslog+console
StandardError=syslog+console
TimeoutStopSec=10m
Type=simple

[Install]
WantedBy=multi-user.target
29 changes: 14 additions & 15 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
default:
just --list

all: forbid fmt-check
all: forbid fmt

deploy:
ssh 8el "mkdir -p ~/infrastructure/ord_bot"
scp -r Dockerfile ord_bot/*.py 8el:~/infrastructure/ord_bot
ssh 8el "cd ~/infrastructure/ord_bot \
&& docker build -t ord_bot . \
&& docker stop ord_bot \
&& docker rm ord_bot \
&& docker run --name=ord_bot --restart=unless-stopped -d ord_bot"
ssh ordbot "mkdir -p /var/lib/ord_bot"
scp -r Pipfile* ord_bot/*.py bin/* ordbot:/var/lib/ord_bot
ssh ordbot "cd /var/lib/ord_bot && ./deploy"

stop:
ssh ordbot "systemctl stop ord_bot"

env:
pipenv shell

forbid:
./bin/forbid

fmt:
isort . && yapf --in-place --recursive **/*.py

fmt-check:
isort -c . && yapf --diff --recursive .
pipenv run isort . && pipenv run yapf --in-place --recursive **/*.py

install *pkg:
pipenv install {{pkg}} --skip-lock
Expand All @@ -31,7 +30,7 @@ lock:
pipenv lock --pre

run:
python3 ord_bot/ord_bot.py
pipenv run python ord_bot/ord_bot.py

start:
pipenv shell
test:
pipenv run python -m unittest tests/*.py
Loading

0 comments on commit dd7fe4c

Please sign in to comment.