Skip to main content

Running a Batch Command with ioBuster Coordinator in GitLab CI

1. Storing SSH Key Pairs as Files in GitLab CI/CD:

  • Navigate to your project in GitLab.
  • Go to Settings -> CI/CD.
  • Under the Variables section:
    • Click on Add Variable.
    • Set the variable type to File.
      • Name: SSH_PRIVATE_KEY_FILE and upload your private SSH key file.
      • Name: SSH_PUBLIC_KEY_FILE and upload your public SSH key file.

2. Understand the CLI_WORKSPACE Concept:

CLI_WORKSPACE is used to specify the working directory for the coordinator executable. This is where the coordinator will look for your recipes and test scripts.

Sample Directory Structure:

my_project (This represents $CI_PROJECT_DIR)

├── .gitlab-ci.yml

├── source_code
│ ├── main.c
│ ├── utility.c
│ └── ...

├── tests
│ ├── test_script1.js
│ ├── test_script2.js
│ └── ...

└── recipes
├── lab1-add-host.yaml
├── lab2-remove-host.yaml
└── ...

In the structure above, you'd set CLI_WORKSPACE to $CI_PROJECT_DIR as both recipes and test scripts are immediate subdirectories.

3. Configure .gitlab-ci.yml:

ioBuster_job:
image:
name: us-docker.pkg.dev/io-buster/release/qam-coordinator:IBC-23.09.1
entrypoint: ['']

before_script:
# Create SSH directory and copy the key pairs
- mkdir -p /data/.ssh
- cp "$SSH_PRIVATE_KEY_FILE" /data/.ssh/id_rsa
- cp "$SSH_PUBLIC_KEY_FILE" /data/.ssh/id_rsa.pub
- chmod 600 /data/.ssh/id_rsa
- chmod 644 /data/.ssh/id_rsa.pub

script:
# Set the workspace for the coordinator
- export CLI_WORKSPACE=$CI_PROJECT_DIR
# Run a batch command with the coordinator
- coordinator batch submit recipes/lab1-add-host.yaml

4. Ensure Docker Runner Configuration:

Ensure you're using a GitLab Runner that supports Docker. If not, the Docker image won't execute as expected.

5. Trigger the CI Job:

Either push a change to your repository or manually start the pipeline in GitLab to run the ioBuster_job.

6. Security Precaution:

Always ensure that the private SSH key (id_rsa) is never printed, logged, or exposed during the CI process. Keep sensitive data confidential.

With this updated tutorial, you should be fully equipped to use the batch submit command from the coordinator to run your recipes in GitLab CI, considering that these recipes might reference JavaScript test scripts.