MinIO: CI pipeline integration with GitHub Actions and GitLab CI

Launch a real MinIO service from your GitHub Actions or GitLab CI pipeline, run your tests against it, and automatically remove it afterwards

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use MinIO Object Storage platform designed for reliability and speed. The main advantages include:

  • Unlimited data transfers with no hidden fees.
  • Simple, predictable, and transparent pricing.
  • A custom domain name secured with HTTPS (for example, https://object-storage.your-company.com).
  • Smooth, one-click updates with no manual intervention required.
  • High performance and security on private, dedicated infrastructure.
  • Available in both 🇪🇺 Europe and 🇺🇸 USA regions.

Simplify your workflows and save setup time: you can deploy Stackhero's MinIO Object Storage hosting in just 5 minutes.

This guide explains how to run a real, dedicated MinIO service within your CI pipeline using either GitHub Actions or GitLab CI. By following these steps, you can test your code against a live MinIO instance in production-like conditions, so you no longer need to rely on mocks or simulations. MinIO is high-performance, S3-compatible object storage, so you get S3 semantics for your files without the S3 bill.

Each time your pipeline runs, a new MinIO instance is created. This means your tests interact with the same type of service your users will encounter in production. The workflow adds MinIO to a stack dedicated to CI, waits for it to be ready, retrieves the generated credentials, runs a smoke test using the AWS CLI, and always deletes the service once the run is complete.

You will use the Stackhero CLI, a standalone command-line tool that enables you to launch and manage Stackhero services quickly and easily.

To allow the CLI to operate non-interactively, you will need an access token (format: usr-xxxxxx:tokenId). You only need to create this token once, then add it to your CI pipeline as a secure, encrypted secret.

  1. Create the token: In your Stackhero dashboard, click your profile picture at the top right, go to Your account, then Access tokens, and click Create token.
  2. For GitHub Actions: In your repository, go to Settings > Secrets and variables > Actions > New repository secret, and enter the token as STACKHERO_TOKEN.
  3. For GitLab CI: In your project, go to Settings > CI/CD > Variables > Add variable, set the key to STACKHERO_TOKEN, and tick Masked (and Protected if your CI only runs on protected branches).

Never include your access token directly in your pipeline YAML file. If it is present in the YAML, it could be exposed to anyone with repository access and may appear in build logs. Storing it as a CI secret ensures it remains encrypted and masked, keeping your token secure.

Each run adds its own MinIO service to a stack that you keep for your CI. You only need to create it once, from your computer:

stackhero login
stackhero stack-create --name="CI"

You can also create it from your Stackhero dashboard. Runs can safely overlap: each one adds and deletes its own service, and the stack remains ready for the next run.

Below is a complete example script that manages the entire service lifecycle. It demonstrates how straightforward the setup is, requiring just a few commands. You can copy the ready-made YAML for your platform from the sections below.

#!/bin/bash
set -euo pipefail

# STACKHERO_TOKEN is provided by the CI secret, the CLI picks it up automatically.

stack="CI"                              # The stack created in step 2
serviceStore="minio"             # The MinIO service store
instance="100G"        # Change this as needed (see step 4)
region="europe"                         # Region name (see stackhero regions-list)

# 1. Install the client used for the smoke test (as root, or prefix with sudo)
apt-get update && apt-get install -y --no-install-recommends ca-certificates jq curl awscli

# 2. Install the CLI on the runner
curl -fsSL https://www.stackhero.io/install.sh | STACKHERO_INSTALL_DIR="$HOME/.local/bin" sh
export PATH="$HOME/.local/bin:$PATH"

# 3. Add MinIO to the CI stack and capture its service ID
serviceId=$(stackhero --format=script service-add \
  --stack="$stack" \
  --service-store="$serviceStore" \
  --instance="$instance" \
  --region="$region")
echo "Service added: $serviceId"

# 4. Delete the service when the script ends, whether it succeeds or fails
trap 'stackhero service-delete --service="$serviceId" --confirm' EXIT

# 5. Wait until the service is running (this usually takes a few minutes)
timeout 15m stackhero service-wait-for --service="$serviceId"

# 6. Retrieve the configuration (contains the generated credentials)
config=$(stackhero service-configuration-get --service="$serviceId" --format=json)

# 7. Extract the credentials you need
host=$(echo "$config" | jq -r '.configuration.domain')
accessKey=$(echo "$config" | jq -r '.configuration.credentials.rootUser')
secretKey=$(echo "$config" | jq -r '.configuration.credentials.rootPassword')

# 8. Smoke test: List the buckets with the AWS CLI (S3-compatible).
AWS_ACCESS_KEY_ID="$accessKey" AWS_SECRET_ACCESS_KEY="$secretKey" \
  aws --endpoint-url "https://$host" s3 ls

echo "✅ MinIO is reachable from CI."

The only clean-up required is deleting the service: the stack remains for the next run. In the YAML below, this deletion is a separate step that the CI always executes, even if a test fails, so you are never billed for a service you are no longer using.

timeout 15m sets a limit on the wait. If the service does not start, the run fails quickly and the service is deleted, rather than waiting for your CI's time limit.

The examples below use the entry-level instance 100G for MinIO by default. This is suitable for most workloads, but you can adjust it as needed. To view all available instance types for MinIO, run:

# The NAME column shows the value to pass to --instance
stackhero instances-store-list --service-store=minio

To get started, save the following as .github/workflows/ci.yml. From now on, every push and pull request will run tests against a real MinIO instance.

name: CI with MinIO

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    env:
      STACKHERO_TOKEN: ${{ secrets.STACKHERO_TOKEN }}
      STACK: CI                            # The stack created in step 2
      INSTANCE: "100G"   # Change this as needed (see step 4)
      REGION: europe
    steps:
      - uses: actions/checkout@v4

      - name: Install the client and the Stackhero CLI
        run: |
          sudo sh -c "apt-get update && apt-get install -y --no-install-recommends ca-certificates jq curl awscli"
          curl -fsSL https://www.stackhero.io/install.sh | STACKHERO_INSTALL_DIR="$HOME/.local/bin" sh
          echo "$HOME/.local/bin" >> "$GITHUB_PATH"

      - name: Add the MinIO service
        run: |
          set -euo pipefail
          SERVICE_ID=$(stackhero --format=script service-add \
            --stack="$STACK" \
            --service-store="minio" \
            --instance="$INSTANCE" \
            --region="$REGION")
          echo "SERVICE_ID=$SERVICE_ID" >> "$GITHUB_ENV"

      - name: Wait for MinIO to be running
        run: timeout 15m stackhero service-wait-for --service="$SERVICE_ID"

      - name: Run tests against MinIO
        run: |
          set -euo pipefail
          config=$(stackhero service-configuration-get --service="$SERVICE_ID" --format=json)
          host=$(echo "$config" | jq -r '.configuration.domain')
          accessKey=$(echo "$config" | jq -r '.configuration.credentials.rootUser')
          secretKey=$(echo "$config" | jq -r '.configuration.credentials.rootPassword')
          # List the buckets with the AWS CLI (S3-compatible).
          AWS_ACCESS_KEY_ID="$accessKey" AWS_SECRET_ACCESS_KEY="$secretKey" \
            aws --endpoint-url "https://$host" s3 ls
          echo "✅ MinIO is reachable from CI."
          # You can run your own test suite here using the credentials above ...

      - name: Delete the service (always, even on failure)
        if: always()
        run: |
          if [ -n "${SERVICE_ID:-}" ]; then
            stackhero service-delete --service="$SERVICE_ID" --confirm
          fi

The deletion step is configured with if: always(), so it always runs: after a failed test, or if you cancel the run. Adding the service and waiting for it are two separate steps, so the service ID is already saved if the wait fails.

You can save this configuration as .gitlab-ci.yml. With this setup, each pipeline run launches a fresh real MinIO instance for your tests.

test:
  image: ubuntu:24.04
  timeout: 30m
  variables:
    STACK: "CI"                           # The stack created in step 2
    INSTANCE: "100G"   # Change this as needed (see step 4)
    REGION: "europe"
    SERVICE_STORE: "minio"
  # STACKHERO_TOKEN comes from the CI/CD variable you created in step 1.
  script:
    - set -euo pipefail
    - apt-get update && apt-get install -y --no-install-recommends ca-certificates jq curl awscli
    - curl -fsSL https://www.stackhero.io/install.sh | sh
    - SERVICE_ID=$(stackhero --format=script service-add --stack="$STACK" --service-store="$SERVICE_STORE" --instance="$INSTANCE" --region="$REGION")
    - echo "SERVICE_ID=$SERVICE_ID" > service.env
    - timeout 15m stackhero service-wait-for --service="$SERVICE_ID"
    - config=$(stackhero service-configuration-get --service="$SERVICE_ID" --format=json)
    - host=$(echo "$config" | jq -r '.configuration.domain')
    - accessKey=$(echo "$config" | jq -r '.configuration.credentials.rootUser')
    - secretKey=$(echo "$config" | jq -r '.configuration.credentials.rootPassword')
    # List the buckets with the AWS CLI (S3-compatible).
    - AWS_ACCESS_KEY_ID="$accessKey" AWS_SECRET_ACCESS_KEY="$secretKey" \
    -   aws --endpoint-url "https://$host" s3 ls
    - echo "✅ MinIO is reachable from CI."
    # You can run your own test suite here using the credentials above ...
  after_script:
    - test -f service.env && . ./service.env || true
    - >
      if [ -n "${SERVICE_ID:-}" ]; then
        stackhero service-delete --service="$SERVICE_ID" --confirm
      fi

In GitLab, deletion is handled in after_script. This section runs even if the job fails, so your MinIO service is removed and you are not charged for an unused service.

In GitLab, after_script runs in a fresh shell. To handle this, the script writes the service ID to service.env as soon as the service is added, and reloads it before deletion. This ensures that even if something fails mid-job, your service is still deleted.

A runner that is abruptly stopped (for example, a lost machine) cannot perform its clean-up. To see the services remaining in your CI stack, run:

stackhero services-list --stack="CI"

Between two runs, this list should be empty. You can delete any leftover service with stackhero service-delete --service=svc-xxxxxx --confirm.

That is the complete CI lifecycle for MinIO: add the service to your CI stack, wait, retrieve credentials, smoke-test, and always delete it. Each pipeline run gets a real, isolated service, and nothing is left running when you are finished. For more information about available commands and non-interactive STACKHERO_TOKEN authentication, you may wish to consult the full CLI documentation.