Ivan Starkov
Posted on October 23, 2022
We periodically need to run different workflows on different servers. For example stop replication, do a vacuum or global database update, start replication.
I don't want to give everyone ssh access to the servers. In addition some workflows need to be run by non-developers.
So to solve this problem I need some simple UI to run workflows, the ability to see logs and the ability to easily and quickly create complex workflows.
Recently I found what I think is the perfect and simple solution. This is github actions + self-hosted runners
I roll out github action runner on each of my servers in addition to the usual set of software. (The code to install via terraform, namely the key generation is taken from here https://github.com/myoung34/docker-github-actions-runner)
Next I write the workflow:
name: Tasks
on:
workflow_dispatch:
inputs:
DEPLOYMENT:
type: choice
description: 'Database is production or test'
options:
- production
- test
default: test
required: true
task:
type: choice
description: 'Select task'
options:
- stop-replication
- start-replication
- ps
- restart
default: ps
required: true
country:
type: choice
description: 'Select country'
options:
- ch
- fr
required: true
jobs:
main:
runs-on: [self-hosted, clickhouse-runner, linux, "${{ github.event.inputs.DEPLOYMENT }}"]
steps:
- if: ${{ github.event.inputs.task == 'restart' }}
run: docker compose restart
- if: ${{ github.event.inputs.task == 'ps' }}
run: docker compose ps
- if: ${{ github.event.inputs.task == 'stop-replication' }}
run: |
docker compose stop clickhouse-replication-updater clickhouse-init
docker compose exec -iT clickhouse clickhouse-client --query="DROP DATABASE IF EXISTS some_db"
echo Stopped
- if: ${{ github.event.inputs.task == 'start-replication' }}
run: |
docker compose start clickhouse-replication-updater clickhouse-init
Here workflow_dispatch.inputs
gives nice UI at github
And you can use steps/jobs etc to generate any workflow depending on inputs.
With runs-on: [self-hosted, clickhouse-runner, linux, "${{ github.event.inputs.DEPLOYMENT }}"]
section you are able to select any server where you need to execute workflow.
Since now everyone with access to repositary can execute server workflows with beautiful UI, logs etc.
Posted on October 23, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.