Skip to content

Commit

Permalink
Merge pull request #1 from mairror/feat/telegram_bot
Browse files Browse the repository at this point in the history
feat: New telegram bot
  • Loading branch information
blopezpi authored Mar 3, 2022
2 parents 219afe0 + bd821b6 commit 7673735
Show file tree
Hide file tree
Showing 22 changed files with 826 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.dockerignore
Dockerfile
.hadolint.yml
.git/
.gitignore
.isort.cfg
.pre-commit-config.yaml
LICENSE
Makefile
README.md
setup.cfg
**/**/__pycache__/**
75 changes: 75 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Bug report
description: You've found a bug with the Mairror API.
labels: ['type:bug', 'status:requirements', 'priority-5-triage']
body:
- type: markdown
attributes:
value: |
Before you begin to fill out the form, make sure you have actually found a bug.
If you're not sure then create a [discussion](https://github.com/mairror/infrastructure/discussions) first.
If you have questions or want help with Mairror infrastructure, then also create a [discussion](https://github.com/mairror/infrastructure/discussions).
- type: dropdown
id: how-are-you-running
attributes:
label: How are you running Mairror API?
options:
- 'Running without Docker'
- 'Running using Docker'
- 'Other'
validations:
required: true

- type: dropdown
id: what-component-is-causing-the-bug
attributes:
label: What component is causing the bug?
options:
- 'Python'
- 'Dependencies'
- 'Bot'
validations:
required: true

- type: input
id: commit-hash
attributes:
label: Tell us what is the commit hash you run.
validations:
required: false

- type: dropdown
id: regression-error
attributes:
label: Was this something which used to work for you, and then stopped?
options:
- 'It used to work, and then stopped'
- 'I never saw this working'
validations:
required: true

- type: textarea
id: describe-bug
attributes:
label: Describe the bug
description: 'Do not report any security concerns here. Email organization members instead.'
validations:
required: true

- type: textarea
id: debug-logs
attributes:
label: Relevant debug logs
description: |
Try not to raise a bug report unless you've looked at the logs first.
Paste the *relevant* logs here, not the entire thing and not just a link. to the dashboard (others do not have permissions to view them).
value: |
<details><summary>Logs</summary>
```
Copy/paste any log here, between the starting and ending backticks
```
</details>
validations:
required: false
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Start a discussion (config, doubts, docs)
url: https://github.com/mairror/telegram-bot/discussions/new
about: If you have any questions about Mairror Telegram Bot configuration or doubts about whether you should create a feature request or bug report, or have problems with the documentation please click here to create a Discussion instead of an Issue.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Feature request
description: Suggest an idea for this project.
labels: ['type:feature', 'status:requirements', 'priority-5-triage']
body:
- type: textarea
id: what-would-you-like-renovate-to-be-able-to-do
attributes:
label: What would you like Mairror Telegram Bot to be able to do?
description: Tell us what requirements you need solving, and be sure to mention too if this is part of any bigger problem you're trying to solve.
validations:
required: true

- type: textarea
id: implementation-idea-textbox
attributes:
label: If you have any ideas on how this should be implemented, please tell us here.
description: |
In case you've already dug into existing options or source code and have ideas, mention them here.
Try to keep implementation ideas separate from requirements.
validations:
required: true

- type: dropdown
id: interested-in-implementing-the-feature
attributes:
label: Is this a feature you are interested in implementing yourself?
options:
- 'Yes'
- 'Maybe'
- 'No'
validations:
required: true
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE/refactor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Refactor (internal)
description: For internal use only.
labels: ['type:refactor', 'status:requirements', 'priority-5-triage']
body:
- type: markdown
attributes:
value: '# This form is for Mairror maintainers only.'

- type: textarea
id: describe-proposed-changes
attributes:
label: Describe the proposed change(s).
description: 'Do not report any security concerns here. Email the organization members instead.'
validations:
required: true
30 changes: 30 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/about-dependabot-version-updates
# https://sysdogs.com/articles/automating-terraform-updates-with-dependabot

# Set update schedule for GitHub Actions

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
target-branch: "main"
schedule:
interval: "weekly"
assignees:
- "aacecandev"
- "blopezpi"
commit-message:
prefix: "[Github]"

# Maintain dependencies for pip on telegram bot
- package-ecosystem: "pip"
directory: "/src"
target-branch: "main"
schedule:
interval: "weekly"
assignees:
- "aacecandev"
- "blopezpi"
commit-message:
prefix: "[PIP]"
45 changes: 45 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Build Bot"
on:
push:
tags:
- v*.*.*

jobs:
build-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-

- name: Login to DockerHub Registry
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Push to Docker Hub
uses: docker/build-push-action@v2
with:
platforms: linux/amd64
push: true
tags: |
mairror/mairror-bot:${{ github.ref_name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max

- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Release Bot"
on:
push:
branches:
- main

jobs:
new-release:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
id: semantic
with:
semantic_version: "18.0.1"
extra_plugins: |
@semantic-release/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
16 changes: 16 additions & 0 deletions .hadolint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Docker linter https://github.com/hadolint/hadolint
# # https://github.com/hadolint/hadolint#rules

failure-threshold: warning

label-schema:
maintainer: text

override:
warning:
- DL3049 # Label <label> is missing.
info:
- DL3008 # Specify version with apt-get install -y <package>=<version>
- DL3013 # Pin versions in pip. Instead of `pip install <package>` use `pip install <package>==<version>` or `pip install --requirement <requirements file>
- DL3018 # Pin versions in apk add. Instead of apk add <package> use apk add <package>=<version>
- SC2174 # When used with -p, -m only applies to the deepest directory
59 changes: 59 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-ast
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-yaml
- id: debug-statements
- id: detect-aws-credentials
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/asottile/blacken-docs
rev: v1.8.0
hooks:
- id: blacken-docs
additional_dependencies: [black==20.8b1]
- repo: https://github.com/zricethezav/gitleaks
rev: v8.2.0
hooks:
- id: gitleaks
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.4.2
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.2
hooks:
- id: pyupgrade
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-ast # Is it valid Python?
# Check for debugger imports and py37+ breakpoint() calls
# in python source.
- id: debug-statements
# - repo: https://github.com/pre-commit/mirrors-mypy
# # https://github.com/python/mypy
# rev: v0.782
# hooks:
# - id: mypy
# args: [--ignore-missing-imports, --no-strict-optional, --show-error-codes]
- repo: https://gitlab.com/pycqa/flake8
rev: '3.8.3'
hooks:
- id: flake8
8 changes: 8 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"branches": ["main"],
"plugins": [
"@semantic-release/github",
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator"
]
}
54 changes: 54 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM python:3.9-slim

# Maintainer of the Dockerfile
LABEL maintainer="Mairror Team"

# Input data
ARG NON_ROOT_USER=nroot
ARG ID=1000

# Hadolint DL4006
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Switch to root user to make administrative tasks
# hadolint ignore=DL3002
USER root

# Change directory to /tmp to do administrative tasks
WORKDIR /tmp

# Create a non-root user group
RUN addgroup ${NON_ROOT_USER} --gid ${ID} && \
adduser \
--disabled-password \
--uid ${ID} --gid ${ID} \
--shell /bin/bash \
--gecos "" \
${NON_ROOT_USER}

# Upgrade OS && install all OS dependencies
RUN apt-get update && \
# APT and /tmp cleanup
apt-get clean && apt-get autoremove -y && \
rm -rf /var/lib/{apt,dpkg,cache,log}/ && \
rm -rf -- *

WORKDIR /app

# Change the ownership of /app to the non-root user
RUN chown -R ${NON_ROOT_USER}:${NON_ROOT_USER} /app

# Use non-root user
USER ${NON_ROOT_USER}

# Install python libraries
COPY requirements.txt /app

RUN pip install --upgrade pip==21.3.1 --no-cache-dir && \
pip install -r /app/requirements.txt --no-cache-dir


# Add local files as late as possible to avoid cache busting
COPY --chown=${NON_ROOT_USER}:${ID} src/ /app

CMD ["python", "main.py"]
Loading

0 comments on commit 7673735

Please sign in to comment.