Skip to content

Commit

Permalink
Containerize.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcisioe committed Mar 28, 2024
1 parent 0f89926 commit 8467788
Show file tree
Hide file tree
Showing 7 changed files with 549 additions and 521 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dockerfile
42 changes: 42 additions & 0 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Create and publish a Docker image

on:
push:
branches: ['release']

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.11-alpine AS builder

RUN apk add poetry

COPY . /build
WORKDIR /build

RUN poetry build --format wheel

FROM python:3.11-alpine

COPY --from=builder /build/dist/*.whl /root
RUN pip install /root/*.whl

CMD python -m picobot
5 changes: 0 additions & 5 deletions config.json.copy

This file was deleted.

18 changes: 13 additions & 5 deletions picobot/config.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import json
from functools import lru_cache
from os import environ
from pathlib import Path

ROOT_DIR = Path(__file__).absolute().parent

try:
CONFIG_DIR = Path(environ['XDG_CONFIG_HOME'], 'picobot')
except KeyError:
CONFIG_DIR = Path.home() / '.config' / 'picobot'
@lru_cache(1)
def get_config_dir() -> Path:
if 'PICOBOT_CONFIG_DIR' in environ:
return Path(environ['PICOBOT_CONFIG_DIR'])

if 'XDG_CONFIG_HOME' in environ:
return Path(environ['XDG_CONFIG_HOME']) / 'picobot'

return Path.home() / '.config' / 'picobot'

CONFIG_DIR = get_config_dir()

with open(CONFIG_DIR / 'config.json') as f:
config = json.load(f)

TOKEN = config['token']
DB_PATH = config.get('db_path', CONFIG_DIR / 'bot.db')
CREATOR_ID = config.get('creator_id', 206454394)
CREATOR_ID = config['creator_id']
974 changes: 472 additions & 502 deletions poetry.lock

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[tool.poetry]
name = "picobot"
version = "0.1.0"
version = "0.2.0"
description = ""
authors = ["Arthur Mesquita Pickcius <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.11"
python-telegram-bot = "^13.11"
dataset = "^1.1"
pillow = "^9.3"
Expand All @@ -14,14 +14,11 @@ emoji = "^0.6.0"
typed-ast = "^1.5.2"
ffmpeg-python = "^0.2.0"

[tool.poetry.dev-dependencies]
pytest = "^3.0"
flake8 = "^3.7"
isort = "^4.3"
black = {version = "^19.10b0", allow-prereleases = true}

[tool.poetry.group.dev.dependencies]
black = {version = "^22.8.0", allow-prereleases = true}
pytest = "^8.1.1"
flake8 = "^7.0.0"
isort = "^5.13.2"
black = "^24.3.0"

[tool.black]
skip_string_normalization = true
Expand Down

0 comments on commit 8467788

Please sign in to comment.