Skip to content

Commit

Permalink
* Trying to launch a bot on a prod server using the socket mode
Browse files Browse the repository at this point in the history
  • Loading branch information
korsakovs committed Dec 28, 2023
1 parent 6d560ee commit 0754c32
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
pg_data/
.github
.devcontainer
7 changes: 7 additions & 0 deletions .github/workflows/deploy.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ jobs:
- run: echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
- run: ssh ${{ secrets.WWF_SSH_USERNAME }}@${{ secrets.WWF_SERVER }} "mkdir -p ./merci"
- run: docker context create remote --docker "host=ssh://${{ secrets.WWF_SSH_USERNAME }}@${{ secrets.WWF_SERVER }}"
- run: docker --context remote compose -f docker-compose.yml build
# as we can't set --project-directory for a remote context, we have to use "ssh" to run docker compose
- run: scp ./docker-compose.prod.yml ${{ secrets.WWF_SSH_USERNAME }}@${{ secrets.WWF_SERVER }}:~/
- run: ssh ${{ secrets.WWF_SSH_USERNAME }}@${{ secrets.WWF_SERVER }} "docker compose -f docker-compose.yml up -d --force-recreate"
- run: docker --context remote image prune -a -f
- run: docker --context remote image container -a -f
- run: docker --context remote volume prune -a -f
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ cython_debug/
.idea/

db/
pg_data/
74 changes: 74 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
version: '3.8'

services:
merci-postgres:
container_name: merci-postgres
build:
context: .
dockerfile: docker/postgres/.Dockerfile
environment:
- POSTGRES_DB=thank_you
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- ./pg_data/pg-thank-you-data:/var/lib/postgresql/data/pgdata
ports:
- "5432:5432"
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres -d postgres" ]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
restart: always
deploy:
resources:
limits:
cpus: '1'
memory: 1G
networks:
- wwf_network

merci-bot:
container_name: merci-bot
depends_on:
merci-postgres:
condition: service_healthy
restart: true
environment:
- POSTGRES_HOST=merci-postgres
- SLACK_BOT_TOKEN=${SLACK_BOT_TOKEN}
- SLACK_APP_TOKEN=${SLACK_APP_TOKEN}
- THANK_YOU_DAO=${THANK_YOU_DAO}
build:
context: .
dockerfile: docker/bot/.Dockerfile
restart: always
networks:
- wwf_network

pgadmin:
container_name: merci-pgadmin
depends_on:
- merci-postgres
image: dpage/pgadmin4:7.2
environment:
- PGADMIN_DEFAULT_EMAIL=test@gmail.com
- PGADMIN_DEFAULT_PASSWORD=postgres
- PGADMIN_CONFIG_SERVER_MODE=False
ports:
- "5433:80"
networks:
- wwf_network


volumes:
thank-you-data:
name: thank-you-data


networks:
wwf_network:
name: wwf_network
driver: bridge
6 changes: 6 additions & 0 deletions docker/bot/.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.8-alpine AS merci-bot
RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
WORKDIR /merci-bot
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "-m", "thankyou.slackbot"]
2 changes: 2 additions & 0 deletions docker/postgres/.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM postgres:alpine
COPY ./docker/postgres/docker-entrypoint-initdb.d/* /docker-entrypoint-initdb.d/
10 changes: 10 additions & 0 deletions docker/postgres/docker-entrypoint-initdb.d/init-user-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER "thank-you-slack-bot" WITH PASSWORD 'thank-you-slack-bot';
GRANT ALL ON SCHEMA public TO "thank-you-slack-bot";
EOSQL

# CREATE DATABASE thank_you;
# GRANT ALL ON thank_you TO "thank-you-slack-bot";
7 changes: 5 additions & 2 deletions thankyou/dao/postres.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@


class PostgresDao(SQLAlchemyDao):
CONN_PYTEST_STRING = "postgresql://localhost:5432/thank_you_test"
CONN_STRING = "postgresql://localhost:5432/thank_you"
HOST = "merci-postgres"
USER = "thank-you-slack-bot"
PASSWORD = "thank-you-slack-bot"
CONN_PYTEST_STRING = f"postgresql://{USER}:{PASSWORD}@{HOST}:5432/thank_you_test"
CONN_STRING = f"postgresql://{USER}:{PASSWORD}@{HOST}:5432/thank_you"

def _create_engine(self) -> Engine:
conn_string = self.CONN_STRING if "pytest" not in sys.modules else self.CONN_PYTEST_STRING
Expand Down

0 comments on commit 0754c32

Please sign in to comment.