# Nonstick2 CI/CD Automation

This directory contains Ansible playbooks and configuration scripts for setting up and running the Continuous Integration environment for the Nonstick2 project.

## Directory Structure

*   **`ci.yml`**: The main entry point playbook for running the CI pipeline.
*   **`init-setup.yml`**: The main entry point playbook for the initial infrastructure setup and configuration of runner nodes.
*   **`inventory/`**: Contains host definitions and dynamic inventory scripts.
  *   `inventory.yml`: Static inventory defining host groups.
  *   `*_cloud_provision.sh`: Scripts for provisioning cloud instances (FreeBSD/Linux).
*   **`tasks/`**: Modular task lists included by the main playbooks.
  *   **`ci/`**: Steps for the CI pipeline (Setup -> Prepare Image -> Build ISO -> Test -> Cleanup).
  *   **`setup/`**: Steps for node initialization (OS config, storage, dependencies, user management, and GitLab Runner installation).

## Usage

### GitLab Runner Setup

To provision a new Gitlab runner:

You need your Gitlab runner token, create a vault file with the following command and provide the token when prompted:

```bash
ansible-vault encrypt_string --ask-vault-password --stdin-name 'gitlab_runner_token'
```

Then create a vault file (e.g., `~/.ansible/vault.yml`) and add the encrypted token:

```yaml
gitlab_runner_token: <encrypted_token_here>
```

Then run the setup playbook with the appropriate environment variables:

```bash
SETUP_GITLAB_RUNNER=true ANSIBLE_USER=<user> TARGET_HOST=<host> ansible-playbook -i inventory/inventory.yml ./init-setup.yml -k -K -e @~/.ansible/vault.yml --ask-vault-pass
```

The user is your ssh access user on the target host, and the target host is the IP or hostname of the machine where you want to set up the GitLab Runner. Note: we use -k and -K to prompt for the SSH password and sudo password respectively. We also use `--ask-vault-pass` to prompt for the vault password to decrypt the GitLab Runner token.

### Development Setup

To set up a local development environment (without GitLab Runner):

```bash
SETUP_GITLAB_RUNNER=false ANSIBLE_USER=<user> TARGET_HOST=<host> ansible-playbook -i inventory/inventory.yml ./init-setup.yml -k -K
```
It initilizes configures ssh access to ansible user.

### Running the CI Pipeline

To manually trigger the CI process (usually handled by the runner automatically):

```bash
OS=linux ANSIBLE_USER=ansible TARGET_HOST=<host> ansible-playbook -i inventory/inventory.yml ci.yml
```

You can specify the target OS (linux or freebsd) using the `OS` environment variable.

## Workflow Overview

1.  **Setup**: Installs necessary dependencies (QEMU, build tools).
2.  **Prepare Image**: Downloads or builds the base OS image.
3.  **Build ISO**: Generates the installation media.
4.  **Execute Tests**: Boots the ISO in a virtualized environment and runs integration tests.
5.  **Cleanup**: Removes temporary build artifacts.