Blame README.md

c6b7f7e
# Getting started with Zuul on Fedora
f71cf1d
c6b7f7e
## Upstream documentation
18f64de
c545494
The upstream documentation is available at: https://zuul-ci.org/docs/zuul/index.html
f71cf1d
c6b7f7e
## Installation
18f64de
c6b7f7e
This section describes the installation process of the minimal set of Zuul components to
c6b7f7e
get a working Zuul deployment. Please refer to the upstream documentation for advanced
c6b7f7e
setup.
18f64de
c545494
Zuul requires a Web, a Zookeeper and SQL server running. This documentation covers all the step
c545494
to bootstrap Zuul.
18f64de
c545494
### Install and setup Zookeeper
18f64de
c545494
This process describes the minimal steps to get a Zookeeper service running. You
c545494
should refer to the Zookeeper documentation to get a production setup if needed.
18f64de
4e329e7
```
4e329e7
$ mkdir /tmp/zookeeper && cd /tmp/zookeeper
4e329e7
$ curl -OL https://downloads.apache.org/zookeeper/zookeeper-3.6.1/apache-zookeeper-3.6.1-bin.tar.gz
4e329e7
$ tar -xvzf apache-zookeeper-3.6.1-bin.tar.gz
4e329e7
$ cp apache-zookeeper-3.6.1-bin/conf/zoo_sample.cfg apache-zookeeper-3.6.1-bin/conf/zoo.cfg
4e329e7
$ sudo apache-zookeeper-3.6.1-bin/bin/zkServer.sh start
4e329e7
```
18f64de
c6b7f7e
### Install and setup postgresql
f71cf1d
c545494
This process describes the minimal steps to get a postgres service running. You
c545494
should refer to the postgrres documentation to get a production setup if needed.
c545494
4e329e7
```
4e329e7
$ sudo dnf install -y posgresql python3-psycopg2
4e329e7
$ su - postgres
4e329e7
$ psql
4e329e7
  ALTER USER postgres WITH PASSWORD 'mypassword';
4e329e7
$ createdb --owner=postgres zuul
4e329e7
$ exit
4e329e7
```
f71cf1d
c6b7f7e
Update the local access setting:
f71cf1d
4e329e7
```
686543e
$ sudo sed -i 's|127.0.0.1/32            ident|127.0.0.1/32            md5|' /var/lib/pgsql/data/pg_hba.conf
4e329e7
$ sudo systemctl restart posgreql
4e329e7
```
f71cf1d
c6b7f7e
Validate server connection by running:
f71cf1d
4e329e7
```
4e329e7
$ psql -h 127.0.0.1 -U postgres -W zuul
4e329e7
```
f71cf1d
c545494
### Install Zuul components
c545494
c545494
To install the packages run:
c545494
4e329e7
```
4e329e7
$ sudo dnf install zuul-scheduler zuul-executor zuul-web zuul-webui
4e329e7
```
c545494
c6b7f7e
### Update the zuul configuration to define the sql connection
f71cf1d
c6b7f7e
In /etc/zuul/zuul.conf add the following:
f71cf1d
4e329e7
```
4e329e7
[connection sqlreporter]
4e329e7
driver=sql
4e329e7
dburi=postgresql://postgres:mypassword@127.0.0.1:5432/zuul
4e329e7
```
f71cf1d
c6b7f7e
### Setup Ansible virtual environment for the Zuul executor
f71cf1d
c545494
The Zuul executor is the component in charge of running Zuul Jobs. A Zuul job is
c545494
a set of Ansible playbook. The Zuul executor supports multiple version of Ansible.
c6b7f7e
Zuul provides a tool to manage the Ansible virtual environments. To initialize them
c6b7f7e
run:
f71cf1d
4e329e7
```
4e329e7
$ sudo -u zuul bash -c "cd && zuul-manage-ansible -u -r /var/lib/zuul/ansible-bin" 
4e329e7
```
c6b7f7e
c6b7f7e
### Build the Zuul web UI
c6b7f7e
c545494
The Zuul web UI is a React application. The Zuul packaging provides the source code of
c6b7f7e
the application. The following process describe how to compile the source to get a
c6b7f7e
production build:
c6b7f7e
4e329e7
```
4e329e7
$ curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
4e329e7
$ sudo dnf install yarn
4e329e7
$ cd /usr/share/zuul-ui/
4e329e7
$ yarn install
4e329e7
$ REACT_APP_ZUUL_API='<api_url>' yarn build
4e329e7
```
c6b7f7e
c6b7f7e
Replace <api_url> by the URL where the zuul-web API is listening.
c6b7f7e
c6b7f7e
### Start the scheduler and executor
c6b7f7e
c6b7f7e
To do so run:
c6b7f7e
4e329e7
```
4e329e7
$ sudo -u zuul bash -c "ssh-keygen -t rsa -N '' -f /var/lib/zuul/.ssh/id_rsa"
4e329e7
$ sudo systemctl start zuul-scheduler
4e329e7
$ sudo systemctl start zuul-executor
4e329e7
```
c6b7f7e
c6b7f7e
The services logs are available into /var/log/zuul/zuul.log.
c6b7f7e
c6b7f7e
### Setup the web API
c6b7f7e
c6b7f7e
Install Apache:
c6b7f7e
4e329e7
```
4e329e7
$ sudo dnf install httpd
4e329e7
$ setsebool -P httpd_can_network_connect on
4e329e7
```
c6b7f7e
c6b7f7e
Then setup the reverve proxy by adding to /etc/httpd/conf.d/zuul.conf the
c6b7f7e
following content:
c6b7f7e
4e329e7
```
4e329e7
RewriteEngine on
4e329e7
RewriteRule ^/api/tenant/(.*)/console-stream ws://localhost:9000/api/tenant/$1/console-stream [P]
4e329e7
RewriteRule ^/(.*)$ http://localhost:9000/$1 [P]
4e329e7
```
c6b7f7e
c6b7f7e
Reload Apache:
c6b7f7e
4e329e7
```
4e329e7
$ sudo systemctl relead httpd
4e329e7
```
c6b7f7e
c6b7f7e
Finally start the zuul-web process
c6b7f7e
4e329e7
```
4e329e7
$ sudo systemctl start zuul-web
4e329e7
```
c6b7f7e
c6b7f7e
Validate the direct access to the API by running:
c6b7f7e
4e329e7
```
4e329e7
$ curl http://localhost:9000/api/tenants
4e329e7
```
c6b7f7e
c6b7f7e
Validate the access to the API via the reverse proxy:
c6b7f7e
4e329e7
```
4e329e7
$ curl http://<site_url>/api/tenants
4e329e7
```
c6b7f7e
c6b7f7e
## Run a first Zuul job
c6b7f7e
c545494
In this section, you'll find the steps to get a first periodic job running.
c545494
c545494
Please note that, this is a really basic configuration to ensure the services are working
c545494
as expected. To go further, please refer to the Zuul documentation to learn how to connect
c545494
Zuul to Code Review systems such as Github, Gerrit, Pagure. This demo uses the local system
c545494
to run jobs but this has serious limitation and should not be used in production.
c545494
Thus Nodepool must be used as the nodes and containers provider for Zuul.
c545494
Nodepool supports various cloud providers. Nodepool is packaged into Fedora and here is
c545494
its documentaion: https://zuul-ci.org/docs/nodepool/
c545494
c6b7f7e
### Prepare a Git repository to host the CI configuration
c6b7f7e
c6b7f7e
We need to prepare a local Git repository to host the pipelines and jobs configuration.
c545494
c6b7f7e
Follow the process below:
c6b7f7e
4e329e7
```
4e329e7
$ git init /home/fedora/zuul-config
4e329e7
```
c6b7f7e
c6b7f7e
In /home/fedora/zuul-config/.zuul.yaml add the following content:
f71cf1d
4e329e7
```
f71cf1d
- pipeline:
f71cf1d
    name: periodic
f71cf1d
    post-review: true
f71cf1d
    description: Jobs in this queue are triggered every minute.
f71cf1d
    manager: independent
f71cf1d
    precedence: low
f71cf1d
    trigger:
f71cf1d
      timer:
f71cf1d
        - time: '* * * * *'
c6b7f7e
    success:
c6b7f7e
      sqlreporter:
c6b7f7e
    failure:
c6b7f7e
      sqlreporter:
c6b7f7e
c6b7f7e
- job:
c6b7f7e
    name: my-noop
c6b7f7e
    description: Minimal working job
c6b7f7e
    parent: null
c6b7f7e
    run: my-noop.yaml
f71cf1d
f71cf1d
- project:
f71cf1d
    periodic:
f71cf1d
      jobs:
c6b7f7e
        - my-noop
4e329e7
```
c6b7f7e
c6b7f7e
Create the /home/fedora/zuul-config/my-noop.yaml and add the following content:
c6b7f7e
4e329e7
```
c6b7f7e
---
c6b7f7e
- hosts: localhost
c6b7f7e
  tasks:
c6b7f7e
    - name: List working directory
c6b7f7e
      command: ls -al {{ ansible_user_dir }}
c6b7f7e
    - name: Sleep 30 seconds
c6b7f7e
      wait_for:
c6b7f7e
        timeout: 30
4e329e7
```
c6b7f7e
c6b7f7e
Then commit the configuration by running:
c6b7f7e
4e329e7
```
4e329e7
$ cd /home/fedora/zuul-config/
4e329e7
$ git config user.name "John Doe"
4e329e7
$ git config user.email "john@localhost"
4e329e7
$ git add -A .
4e329e7
$ git commit -m"Init demo config"
4e329e7
```
c6b7f7e
c545494
### Run a Git deamon to serve the config repository
c6b7f7e
4e329e7
```
4e329e7
$ dulwich web-daemon -l 0.0.0.0 /
4e329e7
```
c6b7f7e
c6b7f7e
### Add the new connection in the Zuul configuration
c6b7f7e
c6b7f7e
In /etc/zuul/zuul.conf add the following:
c6b7f7e
4e329e7
```
4e329e7
[connection local_git]
4e329e7
driver=git
4e329e7
baseurl=http://localhost:8000/home/fedora
4e329e7
poll_delay=300
4e329e7
```
c6b7f7e
c6b7f7e
### Setup the Zuul tenant configuration file
c6b7f7e
c6b7f7e
In /etc/zuul/main.yaml add the following:
c6b7f7e
4e329e7
```
4e329e7
- tenant:
4e329e7
    name: default
4e329e7
    source:
4e329e7
      local_git:
4e329e7
        config-projects:
4e329e7
          - zuul-config
4e329e7
```
c6b7f7e
c6b7f7e
### Restart the Zuul services
c6b7f7e
4e329e7
```
4e329e7
$ sudo systemctl restart zuul-*
4e329e7
```
c6b7f7e
c545494
### Verify the job executed periodically
c545494
c545494
Run the following command to access the builds API endpoint and ensure the
c545494
my-noop job run as expected every minutes w/o errors.
c545494
4e329e7
```
4e329e7
$ curl http://<host>/api/tenant/default/builds | python -m json.tool
4e329e7
```
c6b7f7e
c545494
Access the build page, where you should see the periodic job my-noop runs
c6b7f7e
4e329e7
```
4e329e7
http://<host>/t/default/builds
4e329e7
```