DEV Community

Ivan Starkov
Ivan Starkov

Posted on • Edited on

1

Simple and fast way to run various devops workflows on your servers

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
Enter fullscreen mode Exit fullscreen mode

Here workflow_dispatch.inputs gives nice UI at github

Workflow run UI

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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

If this article connected with you, consider tapping ❤️ or leaving a brief comment to share your thoughts!

Okay