Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Buquet committed Jul 11, 2024
0 parents commit fe4d725
Show file tree
Hide file tree
Showing 25 changed files with 2,760 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Docker

# This workflow uses actions that are certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
push:
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

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

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

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

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
DIGEST: ${{ steps.build-and-push.outputs.digest }}
TAGS: ${{ steps.meta.outputs.tags }}
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
cosign sign --yes ${images}
63 changes: 63 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Tests

on:
push:
pull_request:
merge_group:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
runs-on: ubuntu-latest
name: Testing

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

- name: Setup Poetry
uses: MatMaul/setup-python-poetry@v1
with:
groups: dev

- name: Run tests
run: poetry run pytest

lint:
runs-on: ubuntu-latest
name: Formatting and linting

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

- name: Setup Poetry
uses: MatMaul/setup-python-poetry@v1
with:
groups: dev

- name: Code style (ruff)
run: poetry run ruff format --diff

- name: Semantic checks (ruff)
run: poetry run ruff check

types:
runs-on: ubuntu-latest
name: Typechecking

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

- name: Setup Poetry
uses: MatMaul/setup-python-poetry@v1
with:
groups: dev

- name: Type checks
run: poetry run basedpyright
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.pyc
__pycache__
.venv/
.tox/
.vscode
.coverage
coverage.xml
report.xml
node_modules/
.idea/
.cache/
store/
session.txt
config.toml
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ARG PYTHON_VERSION=3.11

FROM python:${PYTHON_VERSION}-bookworm as builder

ENV POETRY_VERSION=1.8.3

RUN pip install poetry==$POETRY_VERSION

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

WORKDIR /app

COPY pyproject.toml poetry.lock ./
COPY scripts ./scripts

RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --compile

FROM python:${PYTHON_VERSION}-slim-bookworm as runtime

COPY --from=builder /app /app

WORKDIR /data
ENTRYPOINT ["/app/.venv/bin/bot-entry-point"]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Setup your environment
```
python -m venv .env
source .env/bin/activate
python install poetry
poetry install
```

# Build Release
```
docker build --target=runtime . -t matrix-bot-admin
```

# Execute Release
```
docker run --name bot-admin -v <path_to_config.toml>:/config.toml matrix-bot-admin
```
Loading

0 comments on commit fe4d725

Please sign in to comment.