Contoh Pengunaan

  1. User request buat sebuah repo yang berisi Locustfile, semua konfigurasi Locust (jumlah worker, script, environment) di setup via Github Actions

Catatan Penting

  1. Manual workflows hanya bisa jalan di branch default

  2. Type environment ini di dapat dari menu “Environment”

name: Run Locust
on:
  workflow_dispatch:
    inputs:
      #setup this at settings->environment
      environment:
        description: "Choose deployment environment:"
        type: environment
        required: true
Environment Menu

Environment Menu

Cara Memanggil Variables & Secrets

Cara Memanggil Variables & Secrets


How To

  1. Buat Locust docker-compose.yml
name: locust
services:
  master:
    image: locustio/locust:latest
    ports:
      - "8809:8089"
    volumes:
      - ./:/mnt/locust
    environment:
      LOCUST_FILE: ${LOCUST_FILE:-default_locustfile.py}
    command: -f /mnt/locust/${LOCUST_FILE} -t 5m --master -H https://ipang.my.id

  worker:
    image: locustio/locust:latest
    volumes:
      - ./:/mnt/locust
    environment:
      LOCUST_FILE: ${LOCUST_FILE:-default_locustfile.py}
    command: -f /mnt/locust/${LOCUST_FILE} --worker --master-host master
  1. Buat locust.yml untuk workflows Github Actions
name: Run Locust
on:
  workflow_dispatch:
    inputs:
      #setup this at settings->environment
      environment:
        description: "Choose deployment environment:"
        type: environment
        required: true

      worker_size:
        description: "How much worker do you need?"
        required: true
        default: "5"
        type: choice
        options:
          - 5
          - 10
      locustfile:
        description: "Specify the Locust file to use (e.g., locustfile1.py):"
        required: false

jobs:
  run-locust:
    runs-on: self-hosted
    environment: ${{ github.event.inputs.environment }} 
    steps:
      - name: Run Locust
        env:  
          WORKER_SIZE: ${{ github.event.inputs.worker_size }} 
          LOCUST_FILE: ${{ github.event.inputs.locustfile }}
        run: |
          #stop all container with locust name
          docker ps -a --filter "name=locust" --format "{{.ID}}" | xargs docker stop
          #create new variable so the docker-compose can read that
          export LOCUST_FILE=$LOCUST_FILE
          docker-compose up --scale worker=$WORKER_SIZE -d --remove-orphans           
Contoh Workflows yang Sudah Jalan

Contoh Workflows yang Sudah Jalan

Referensi:

  1. Github Blog - GitHub Actions: Input types for manual workflows

  2. Github Docs - Accessing contextual information about workflow runs