Skip to content

Commit 53029ee

Browse files
authored
Add full Docker support (#170)
1 parent c996be9 commit 53029ee

13 files changed

+343
-23
lines changed

.github/workflows/docker.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
Build-and-Push:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- name: Prepare Docker Meta
15+
id: meta
16+
uses: docker/metadata-action@v5
17+
with:
18+
images: |
19+
ghcr.io/transprogrammer/rodhaj
20+
tags: |
21+
type=semver,pattern={{version}}
22+
type=semver,pattern={{major}}.{{minor}}
23+
type=semver,pattern={{major}}
24+
type=edge,branch=main
25+
26+
- name: Setup Docker Buildx
27+
id: buildx
28+
uses: docker/setup-buildx-action@v3
29+
with:
30+
version: latest
31+
32+
- name: Login to GitHub Container Registry
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ghcr.io
36+
username: ${{ github.repository_owner }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Build and push image
40+
uses: docker/build-push-action@v6
41+
with:
42+
context: .
43+
file: ./docker/Dockerfile
44+
push: true
45+
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/rodhaj-build-cache:bot
46+
cache-to: cache-to=type=registry,mode=max,ref=ghcr.io/${{ github.repository_owner }}/rodhaj-build-cache:bot
47+
tags: ${{ steps.meta.outputs.tags }}
48+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/release.yml

+37
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,50 @@ on:
44
branches:
55
- main
66
jobs:
7+
Bundle:
8+
runs-on: ubuntu-latest
9+
if: contains(github.event.head_commit.message, '#major') || contains(github.event.head_commit.message, '#minor') || contains(github.event.head_commit.message, '#patch')
10+
steps:
11+
- name: Checkout Repository
12+
uses: actions/checkout@v4
13+
14+
- name: Prepare for bundling
15+
run: |
16+
mkdir -p rodhaj-docker
17+
mkdir -p releases
18+
cp docker/docker-compose.yml rodhaj-docker/
19+
cp docker/example.env rodhaj-docker/
20+
cp -r docker/pg/ rodhaj-docker/
21+
22+
- name: Bundle docker-related files
23+
run: |
24+
zip releases/rodhaj-docker.zip rodhaj-docker/**
25+
tar -czf releases/rodhaj-docker.tar.gz rodhaj-docker/**
26+
27+
- name: Upload bundle
28+
uses: actions/upload-artifact@v4
29+
with:
30+
path: releases
31+
32+
733
Release:
34+
permissions:
35+
contents: write
36+
needs: Bundle
37+
838
runs-on: ubuntu-latest
939
if: contains(github.event.head_commit.message, '#major') || contains(github.event.head_commit.message, '#minor') || contains(github.event.head_commit.message, '#patch')
1040
steps:
1141
- uses: actions/checkout@v4
1242
with:
1343
fetch-depth: '0'
1444

45+
- name: Download Artifacts
46+
uses: actions/download-artifact@v4
47+
with:
48+
name: artifact
49+
path: releases
50+
1551
- name: Bump version and push tag
1652
uses: anothrNick/[email protected]
1753
id: tag_version
@@ -27,3 +63,4 @@ jobs:
2763
token: ${{ secrets.PAT_TOKEN }}
2864
tag: ${{ steps.tag_version.outputs.new_tag }}
2965
name: ${{ steps.tag_version.outputs.new_tag }}
66+
artifacts: "releases/rodhaj-docker.zip,releases/rodhaj-docker.tar.gz"

docker-compose-dev.yml

-18
This file was deleted.

docker/docker-compose.dev.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: rodhaj_dev
2+
3+
# For development purposes, it is recommended in order to start the bot normally and using the Dev Reloader system
4+
services:
5+
database:
6+
container_name: rodhaj_postgres
7+
build:
8+
context: ./pg
9+
dockerfile: Dockerfile
10+
environment:
11+
POSTGRES_PASSWORD: ${DB_PASSWORD}
12+
POSTGRES_DB: ${DB_DATABASE_NAME}
13+
POSTGRES_USER: ${DB_USERNAME}
14+
volumes:
15+
- database:/var/lib/postgresql/data
16+
ports:
17+
- 5432:5432
18+
19+
volumes:
20+
database:

docker/docker-compose.prod.yml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: rodhaj_prod
2+
3+
services:
4+
rodhaj:
5+
container_name: rodhaj
6+
image: ghcr.io/transprogrammer/rodhaj:latest
7+
volumes:
8+
# Do not edit the next line. If you want to change the path of the configuration file, please edit the CONFIG_LOCATION variable
9+
- ${CONFIG_LOCATION}:/rodhaj/bot/config.yml
10+
env_file:
11+
- .env
12+
ports:
13+
- 8555:8555
14+
depends_on:
15+
- database
16+
command: sh -c '/rodhaj/wait-for database:5432 -- echo "[Wait-for] PostgreSQL is fully up. Starting Rodhaj." && /rodhaj/start.sh'
17+
restart: always
18+
19+
database:
20+
container_name: rodhaj_postgres
21+
build:
22+
context: ./pg
23+
dockerfile: Dockerfile
24+
environment:
25+
POSTGRES_PASSWORD: ${DB_PASSWORD}
26+
POSTGRES_DB: ${DB_DATABASE_NAME}
27+
POSTGRES_USER: ${DB_USERNAME}
28+
POSTGRES_INITDB_ARGS: '--data-checksums'
29+
ports:
30+
- 5432:5432
31+
volumes:
32+
# 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
33+
- database:/var/lib/postgresql/data
34+
healthcheck:
35+
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
36+
interval: 5m
37+
start_interval: 30s
38+
start_period: 5m
39+
restart: always
40+
41+
rodhaj-prometheus:
42+
container_name: rodhaj_prometheus
43+
ports:
44+
- 9090:9090
45+
image: prom/prometheus:latest
46+
volumes:
47+
- ./prometheus.yml:/etc/prometheus/prometheus.yml
48+
- prometheus-data:/prometheus
49+
50+
# first login uses admin/admin
51+
# add data source for http://rodhaj-prometheus:9090 to get started
52+
rodhaj-grafana:
53+
container_name: rodhaj_grafana
54+
command: ['./run.sh', '-disable-reporting']
55+
ports:
56+
- 3000:3000
57+
image: grafana/grafana-enterprise:11.1.3-ubuntu
58+
volumes:
59+
- grafana-data:/var/lib/grafana
60+
61+
volumes:
62+
database:
63+
prometheus-data:
64+
grafana-data:

docker/docker-compose.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: rodhaj
2+
3+
services:
4+
rodhaj:
5+
container_name: rodhaj
6+
image: ghcr.io/transprogrammer/rodhaj:latest
7+
volumes:
8+
# Do not edit the next line. If you want to change the path of the configuration file, please edit the CONFIG_LOCATION variable
9+
- ${CONFIG_LOCATION}:/rodhaj/bot/config.yml
10+
env_file:
11+
- .env
12+
ports:
13+
- 8555:8555
14+
depends_on:
15+
- database
16+
# Oftentimes if Rodhaj started too early (aka starting without this script), then it would entirely not run the migrations and error out
17+
command: sh -c '/rodhaj/wait-for database:5432 -- echo "[Wait-for] PostgreSQL is fully up. Starting Rodhaj." && /rodhaj/start.sh'
18+
restart: always
19+
20+
database:
21+
container_name: rodhaj_postgres
22+
build:
23+
context: ./pg
24+
dockerfile: Dockerfile
25+
environment:
26+
POSTGRES_PASSWORD: ${DB_PASSWORD}
27+
POSTGRES_DB: ${DB_DATABASE_NAME}
28+
POSTGRES_USER: ${DB_USERNAME}
29+
POSTGRES_INITDB_ARGS: '--data-checksums'
30+
ports:
31+
- 5432:5432
32+
volumes:
33+
# 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
34+
- database:/var/lib/postgresql/data
35+
healthcheck:
36+
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
37+
interval: 5m
38+
start_interval: 30s
39+
start_period: 5m
40+
restart: always
41+
42+
volumes:
43+
database:

docker/example.env

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# The location of where Rodhaj's configuration is stored.
2+
# The configuration can be found under the config-example.yml
3+
CONFIG_LOCATION=./config.yml
4+
5+
# Connection secret for the postgres. You should change it to a random password
6+
POSTGRES_PASSWORD=postgres
7+
8+
# The values below this line do not need to be changed
9+
###################################################################################
10+
POSTGRES_USER=postgres
11+
POSTGRES_DB=rodhaj

docker/pg/init.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
set -e
33

44
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
5-
CREATE ROLE rodhaj WITH LOGIN PASSWORD '$RODHAJ_PASSWORD';
6-
CREATE DATABASE rodhaj OWNER rodhaj;
5+
CREATE EXTENSION IF NOT EXISTS pg_trgm;
76
EOSQL

docker/prometheus.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
global:
2+
scrape_interval: 15s
3+
evaluation_interval: 15s
4+
5+
scrape_configs:
6+
- job_name: rodhaj
7+
static_configs:
8+
- targets: ['rodhaj:8555']

docs/deployment/docker.rst

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
======
2+
Docker
3+
======
4+
5+
.. warning::
6+
7+
This method of deployment is only for internal use within the transprogrammer community.
8+
In addition, this deployment method is fairly advanced. This guide is only intended for internal
9+
documentation for possible deployment options.
10+
11+
Docker Compose can be used to run an Rodhaj instance in production. This will only work if you have access to the
12+
Rodhaj Docker images.
13+
14+
Step 1 - Download required files
15+
================================
16+
17+
Download the necessary archive for getting started. This archive contains all
18+
of the files needed to get started. These are provided either in ``.zip`` or ``.tar.gz``
19+
formats.
20+
21+
.. code-block:: bash
22+
23+
wget https://github.com/transprogrammer/rodhaj/releases/latest/download/rodhaj-docker.tar.gz
24+
25+
# .zip version download
26+
wget https://github.com/transprogrammer/rodhaj/releases/latest/download/rodhaj-docker.zip
27+
28+
We need to unpack the archive in order to access the files. The following commands should do that.
29+
30+
.. code-block:: bash
31+
32+
tar -xvzf rodhaj-docker.tar.gz
33+
34+
# .zip version unpacking
35+
unzip rodhaj-docker.zip
36+
37+
Once we have the files, we can now ``cd`` into the new extracted archive.
38+
39+
.. code-block:: bash
40+
41+
cd rodhaj-docker
42+
43+
.. important::
44+
45+
Throughout the rest of the guide, the next steps assume that
46+
you are in the ``rodhaj-docker`` directory.
47+
48+
Step 2 - Populate ``.env`` and ``config.yml`` file with values
49+
==============================================================
50+
51+
- Change ``DB_PASSWORD`` to a randomly generated password.
52+
- Provide Rodhaj's bot token in ``config.yml``
53+
- Change ``rodhaj.guild_id`` in ``config.yml`` to the server ID that Rodhaj is running on
54+
- Modify the PostgreSQL URI used in ``config.yml`` to redirect to the database container and appropriate password
55+
56+
.. note::
57+
58+
In order for Rodhaj to work container-wise, the IP aliases that is provided by the compose file
59+
must be used instead. For example, the URI would look like this (of course replace the password):
60+
61+
.. code-block::
62+
63+
postgresql://postgres:somepwd@database:5432/rodhaj
64+
65+
.. important::
66+
67+
If you are running the full production version, please enable the Prometheus metrics
68+
found in Rodhaj's configuration
69+
70+
Step 3 - Start all containers
71+
=============================
72+
73+
Assume that you are in the directory created in Step 1, run the following command to bring up Rodhaj entirely.
74+
75+
.. code-block::
76+
77+
docker compose up -d
78+
79+
.. tip::
80+
81+
If you are having issues downloading container images, you will need to authenticate to the Github Container
82+
Registry. Steps can be found `here <https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry>`_.
83+
84+
Step 4 - Upgrading
85+
==================
86+
87+
.. danger::
88+
89+
Although Rodhaj doesn't often update version-wise, there
90+
may be breaking changes between versions. Be careful and be
91+
up-to-date with changes.
92+
93+
Upgrading Rodhaj is very simple. All you need to do is run the following commands below:
94+
95+
.. code-block:: bash
96+
97+
docker compose pull && docker compose up -d

docs/deployment/index.rst

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
================
2+
Deployment Guide
3+
================
4+
5+
This document represents the deployment guide for Rodhaj. Currently, these are the officially supported methods as shown below.
6+
7+
.. toctree::
8+
:maxdepth: 1
9+
10+
docker

0 commit comments

Comments
 (0)