Skip to content

Commit

Permalink
Merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 committed Aug 15, 2024
2 parents 8316770 + 100ccfa commit e8f2f09
Show file tree
Hide file tree
Showing 20 changed files with 540 additions and 209 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
commit-message:
prefix: "[pip]"
include: "scope"
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Docker

on:
push:
branches: [main]
tags: ["v*"]

jobs:
Build-and-Push:
runs-on: ubuntu-latest

# We want to filter out dependabot and pre-commit
# automated pushes to main
if: ${{ github.actor != 'dependabot[bot]'}} && ${{ github.actor != 'pre-commit-ci[bot]'}}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare Docker Meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/transprogrammer/rodhaj
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=edge,branch=main
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
version: latest

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile
push: true
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/rodhaj-build-cache:bot
cache-to: type=registry,mode=max,ref=ghcr.io/${{ github.repository_owner }}/rodhaj-build-cache:bot
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
44 changes: 42 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,66 @@ on:
branches:
- main
jobs:
Bundle:
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, '#major') || contains(github.event.head_commit.message, '#minor') || contains(github.event.head_commit.message, '#patch')
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Prepare for bundling
run: |
mkdir -p rodhaj-docker
mkdir -p releases
cp docker/docker-compose.yml rodhaj-docker/
cp docker/example.env rodhaj-docker/
cp -r docker/pg/ rodhaj-docker/
- name: Bundle docker-related files
run: |
zip releases/rodhaj-docker.zip rodhaj-docker/**
tar -czf releases/rodhaj-docker.tar.gz rodhaj-docker/**
- name: Upload bundle
uses: actions/upload-artifact@v4
with:
path: releases


Release:
runs-on: ubuntu-latest
needs: Bundle
if: contains(github.event.head_commit.message, '#major') || contains(github.event.head_commit.message, '#minor') || contains(github.event.head_commit.message, '#patch')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'

- name: Get Previous Tag
uses: WyriHaximus/github-action-get-previous-tag@v1
id: prev_tag
with:
fallback: v0.1.0

- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: artifact
path: releases

- name: Bump version and push tag
uses: anothrNick/[email protected]
id: tag_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
WITH_V: true
RELEASE_BRANCHES: main

- name: Release New Version
uses: ncipollo/release-action@v1
with:
body: "https://github.com/transprogrammer/rodhaj/compare/${{ steps.tag_version.outputs.tag }}...${{ steps.tag_version.outputs.new_tag }}"
body: "https://github.com/transprogrammer/rodhaj/compare/${{ steps.prev_tag.outputs.tag }}...${{ steps.tag_version.outputs.new_tag }}"
token: ${{ secrets.PAT_TOKEN }}
tag: ${{ steps.tag_version.outputs.new_tag }}
name: ${{ steps.tag_version.outputs.new_tag }}
artifacts: "releases/rodhaj-docker.zip,releases/rodhaj-docker.tar.gz"
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
additional_dependencies: ["bandit[toml]"]

- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.8.0
hooks:
- id: black
name: Black
Expand All @@ -30,7 +30,7 @@ repos:
stages: [commit]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.4
rev: v0.5.7
hooks:
- id: ruff
name: Ruff
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def __str__(self) -> str:


EXTENSIONS = [module.name for module in iter_modules(__path__, f"{__package__}.")]
VERSION: VersionInfo = VersionInfo(major=0, minor=2, micro=0, releaselevel="alpha")
VERSION: VersionInfo = VersionInfo(major=0, minor=3, micro=1, releaselevel="final")
18 changes: 0 additions & 18 deletions docker-compose-dev.yml

This file was deleted.

4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
tini \
bash \
netcat-traditional \
git \
netcat-traditional \
tini \
&& apt-get clean

WORKDIR /rodhaj
Expand Down
20 changes: 20 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: rodhaj_dev

# For development purposes, it is recommended in order to start the bot normally and using the Dev Reloader system
services:
database:
container_name: rodhaj_postgres
build:
context: ./pg
dockerfile: Dockerfile
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_DATABASE_NAME}
POSTGRES_USER: ${DB_USERNAME}
volumes:
- database:/var/lib/postgresql/data
ports:
- 5432:5432

volumes:
database:
64 changes: 64 additions & 0 deletions docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: rodhaj_prod

services:
rodhaj:
container_name: rodhaj
image: ghcr.io/transprogrammer/rodhaj:edge
volumes:
# Do not edit the next line. If you want to change the path of the configuration file, please edit the CONFIG_LOCATION variable
- ${CONFIG_LOCATION}:/rodhaj/bot/config.yml
env_file:
- .env
ports:
- 8555:8555
depends_on:
- database
command: sh -c '/rodhaj/wait-for database:5432 -- echo "[Wait-for] PostgreSQL is fully up. Starting Rodhaj." && /rodhaj/start.sh'
restart: always

database:
container_name: rodhaj_postgres
build:
context: ./pg
dockerfile: Dockerfile
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_DATABASE_NAME}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_INITDB_ARGS: '--data-checksums'
ports:
- 5432:5432
volumes:
# Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
- database:/var/lib/postgresql/data
healthcheck:
test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1
interval: 5m
start_interval: 30s
start_period: 5m
restart: always

rodhaj-prometheus:
container_name: rodhaj_prometheus
ports:
- 9090:9090
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus-data:/prometheus

# first login uses admin/admin
# add data source for http://rodhaj-prometheus:9090 to get started
rodhaj-grafana:
container_name: rodhaj_grafana
command: ['./run.sh', '-disable-reporting']
ports:
- 3000:3000
image: grafana/grafana-enterprise:11.1.3-ubuntu
volumes:
- grafana-data:/var/lib/grafana

volumes:
database:
prometheus-data:
grafana-data:
43 changes: 43 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: rodhaj

services:
rodhaj:
container_name: rodhaj
image: ghcr.io/transprogrammer/rodhaj:edge
volumes:
# Do not edit the next line. If you want to change the path of the configuration file, please edit the CONFIG_LOCATION variable
- ${CONFIG_LOCATION}:/rodhaj/bot/config.yml
env_file:
- .env
ports:
- 8555:8555
depends_on:
- database
# Oftentimes if Rodhaj started too early (aka starting without this script), then it would entirely not run the migrations and error out
command: sh -c '/rodhaj/wait-for database:5432 -- echo "[Wait-for] PostgreSQL is fully up. Starting Rodhaj." && /rodhaj/start.sh'
restart: always

database:
container_name: rodhaj_postgres
build:
context: ./pg
dockerfile: Dockerfile
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_DATABASE_NAME}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_INITDB_ARGS: '--data-checksums'
ports:
- 5432:5432
volumes:
# Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
- database:/var/lib/postgresql/data
healthcheck:
test: pg_isready --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' || exit 1; Chksum="$$(psql --dbname='${DB_DATABASE_NAME}' --username='${DB_USERNAME}' --tuples-only --no-align --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')"; echo "checksum failure count is $$Chksum"; [ "$$Chksum" = '0' ] || exit 1
interval: 5m
start_interval: 30s
start_period: 5m
restart: always

volumes:
database:
11 changes: 11 additions & 0 deletions docker/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# The location of where Rodhaj's configuration is stored.
# The configuration can be found under the config-example.yml
CONFIG_LOCATION=./config.yml

# Connection secret for the postgres. You should change it to a random password
POSTGRES_PASSWORD=postgres

# The values below this line do not need to be changed
###################################################################################
POSTGRES_USER=postgres
POSTGRES_DB=rodhaj
2 changes: 0 additions & 2 deletions docker/pg/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE ROLE rodhaj WITH LOGIN PASSWORD '$RODHAJ_PASSWORD';
CREATE DATABASE rodhaj OWNER rodhaj;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
EOSQL
8 changes: 8 additions & 0 deletions docker/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: rodhaj
static_configs:
- targets: ['rodhaj:8555']
Loading

0 comments on commit e8f2f09

Please sign in to comment.