]> git.openstreetmap.org Git - chef.git/blob - CONTRIBUTING.md
blogs: fix build in test
[chef.git] / CONTRIBUTING.md
1 # Contribution Guidelines
2
3 ## Workflow
4
5 We operate the "Fork & Pull" model explained at
6
7 https://help.github.com/articles/using-pull-requests
8
9 You should fork the project into your own repo, create a topic branch
10 there and then make one or more pull requests back to the openstreetmap/chef repository.
11 Your pull requests will then be reviewed and discussed.
12
13 ## Running the Infrastructure Tests locally
14
15 - **[Cookstyle](https://docs.chef.io/workstation/cookstyle/)** is used for linting, ensuring that our Chef recipes follow style guidelines and best practices.
16 - **[Test Kitchen](https://kitchen.ci/)** combined with **InSpec** and [Dokken](https://github.com/test-kitchen/kitchen-dokken) is used to verify the functionality of our Chef code, ensuring it behaves as expected.
17
18 The following guidelines are to help set up and run these checks locally:
19
20 #### **1. Install Docker**
21 - Visit [Docker's official site](https://www.docker.com/products/docker-desktop) to download and install Docker.
22
23 #### **2. Install Homebrew (Apple MacOS only)**
24 - Install Homebrew by following the instructions [here](https://brew.sh/).
25
26 #### **3. Install rbenv (recommended)**
27 - Install rbenv by following the instructions [here](https://github.com/rbenv/rbenv#installation).
28
29 rbenv is a ruby version manager. rbenv allows projects to use a different version of ruby than the version of install with your operating system.
30
31 > *Note on rbenv: While we recommend using rbenv for managing Ruby versions, it's not strictly necessary. If you have Ruby already installed feel free to use that. If you're not using rbenv, simply omit the `rbenv exec` prefix from the commands below.*
32
33 #### **4. Increase File Limit (Important for MacOS)**
34
35 To avoid errors when running tests on MacOS, you might need to increase the number of files your system can open at once. Here's how:
36
37 1. Run the command:
38 ```bash
39 ulimit -n 1024
40 ```
41 2. To make the change permanent, add the above line to either `~/.zshrc` or `~/.bash_profile`, depending on your shell.
42
43 **Note:** MacOS has a low default limit of just 256 open files. If you exceed this while testing, you'll see an error like: `Too many open files - getcwd (Errno::EMFILE)`. This step helps prevent that.
44
45 #### **5. Install Required Ruby Version (recommended)**
46 Navigate to the git checkout of the OpenStreetMap chef repo and run:
47 ```bash
48 rbenv install
49 ```
50 This will install the recommended version of ruby for running the tests. The recommended version of ruby is defined in the [.ruby-version](.ruby-version) file.
51
52 #### **6. Install Dependencies with Bundler**
53 ```bash
54 rbenv exec gem install bundler
55 rbenv exec bundler install
56 ```
57 This will install the [bundler](https://bundler.io/), the ruby gem packages manager, and then uses `bundler`` to install the required gem packages for the tests.
58
59 #### **7. Run Cookstyle for Linting and Style Checks**
60 ```bash
61 rbenv exec bundle exec cookstyle
62 ```
63 This will run [cookstyle](https://docs.chef.io/workstation/cookstyle/) a linting tool which reports on any linting issues.
64
65 > *Automatically run cookstyle lint: We have a sample [git pre-commit hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) in the `hooks/pre-commit` file which can be copied to the local checkout of this repo to the file `.git/hooks/pre-commit`  to ensure the lint passes when running a git commit.*
66
67 #### **8. List Available Tests**
68 ```bash
69 rbenv exec bundler exec kitchen list
70 ```
71 This lists the [Test Kitchen](https://kitchen.ci/) tests which are available. The list of tests is generated from the definitions in the [.kitchen.yml](.kitchen.yml) file. The individual tests are written in [InSpec](https://docs.chef.io/inspec/) and are stored in the `test/integration/` directory.
72
73 #### **9. Run an Example Test**
74 ```bash
75 rbenv exec bundler exec kitchen test dns-ubuntu-2204
76 ```
77 This runs the [Test Kitchen](https://kitchen.ci/) [InSpec](https://docs.chef.io/inspec/) `dns` tests using the `Ubuntu 22.04` platform. The tests are run inside a Docker container using the Test Kitchen [Dokken driver](https://github.com/test-kitchen/kitchen-dokken).