github.com/canonical/ubuntu-image@v0.0.0-20240430122802-2202fe98b290/CONTRIBUTING.md (about) 1 # Contributing to ubuntu-image 2 3 This document covers the following topics: 4 5 * [Setting up](#setting-up) 6 * [Building](#building) 7 * [Testing](#testing) 8 * [Release process](#release-process) 9 10 11 ## Setting up 12 13 Ubuntu 18.04 LTS or later is recommended for ubuntu-image development. 14 Usually, the [latest LTS](https://releases.ubuntu.com/) would be the best choice. 15 16 Go 1.21 [(or later)](https://snapcraft.io/go) is required to build ubuntu-image. 17 18 19 ## Building 20 21 1. Clone this repository in a directory where you have read-write permissions, such as your home directory: 22 ``` 23 cd ~/ 24 git clone https://github.com/canonical/ubuntu-image.git` 25 ``` 26 2. Change into the newly cloned repository: 27 ``` 28 cd ubuntu-image 29 ``` 30 3. Run: 31 ``` 32 CGO_ENABLED=0 go build -o . ./... 33 ``` 34 35 The newly compiled executable `ubuntu-image` will be created in the current directory. 36 37 38 ## Testing 39 40 We value good tests, so when you fix a bug or add a new feature we highly encourage you to add tests. 41 42 To run the test suite locally, install all the build dependencies named in the `debian/control` file. Run the following command from the root directory of the repository: 43 ``` 44 sudo apt build-dep ./ 45 ``` 46 47 Alternatively, install the packages named in the `Build-Depends` field. 48 49 50 ### Running unit-tests 51 52 To run the various tests that we have to ensure a high quality source: 53 ``` 54 go test -timeout 0 ./... 55 ``` 56 57 ### Running integration tests 58 59 #### Downloading Spread framework 60 61 +To run the integration tests locally via QEMU, you need the latest version of the [Spread](https://github.com/snapcore/spread) framework. You can get Spread, QEMU, and the build tools to build QEMU images with: 62 ``` 63 sudo apt update && sudo apt install -y qemu-kvm autopkgtest 64 curl https://storage.googleapis.com/snapd-spread-tests/spread/spread-amd64.tar.gz | tar -xz -C <target-directory> 65 ``` 66 67 * `<target-directory>` can be any directory that is listed in `$PATH`, as it is assumed further in the guidelines of this document. Either create a dedicated directory and add it to `$PATH`, or use one of the conventional Linux directories (e.g. `/usr/local/bin`). 68 69 #### Building Spread VM images 70 71 To run the Spread tests via QEMU, create VM images in the 72 `~/.spread/qemu` directory: 73 ``` 74 mkdir -p ~/.spread/qemu 75 cd ~/.spread/qemu 76 ``` 77 78 Run the following to build a 64-bit Ubuntu 16.04 LTS (or later): 79 ``` 80 autopkgtest-buildvm-ubuntu-cloud -r <release-short-name> 81 mv autopkgtest-<release-short-name>-amd64.img ubuntu-<release-version>-64.img 82 ``` 83 84 For the correct values of `<release-short-name>` and `<release-version>`, see the official list of [Ubuntu releases](https://wiki.ubuntu.com/Releases). 85 86 * `<release-short-name>` is the first word in the release's full name, 87 e.g. for "Bionic Beaver" it is `bionic`. 88 89 If you are running Ubuntu 16.04 LTS, use `adt-buildvm-ubuntu-cloud` instead of `autopkgtest-buildvm-ubuntu-cloud` (the latter replaced the former in 18.04): 90 ``` 91 adt-buildvm-ubuntu-cloud -r xenial 92 mv adt-<release-name>-amd64-cloud.img ubuntu-<release-version>-64.img 93 ``` 94 95 #### Downloading Spread VM images 96 97 Alternatively, instead of building the QEMU images manually, you can download unofficial pre-built images from [spread.zygoon.pl](https://spread.zygoon.pl/). Extract these images with `gunzip` and place them into `~/.spread/qemu` as above. 98 99 * To download an image for the latest Ubuntu Core that is pre-built for KVM, see [cdimage.ubuntu.com/ubuntu-core](https://cdimage.ubuntu.com/ubuntu-core/). 100 101 102 #### Running Spread with QEMU 103 104 Finally, you can run the Spread tests for Ubuntu 18.04 LTS 64-bit with: 105 ``` 106 spread -v qemu:ubuntu-18.04-64 107 ``` 108 109 * To run for a different system, replace `ubuntu-18.04-64` with a different system name, which should be a basename of the [built](#building-spread-vm-images) or [downloaded](#downloading-spread-vm-images) Ubuntu image file. 110 111 For quick reuse, run: 112 ``` 113 spread -reuse qemu:ubuntu-18.04-64 114 ``` 115 116 It prints how to reuse the systems. Run `export REUSE_PROJECT=1` in your environment, too. 117 118 * Spread tests can be exercised on Ubuntu Core 20 and higher but need UEFI. UEFI support with a QEMU backend for Spread requires a BIOS from the [OVMF](https://wiki.ubuntu.com/UEFI/OVMF) package, which can be installed with `sudo apt install ovmf`. 119 120 ### Maintaining test helpers 121 122 Spread tests rely on [snapd-testing-tools](https://github.com/snapcore/snapd-testing-tools). To update the subtree of this project, run: 123 ``` 124 git subtree pull --prefix tests/lib/external/snapd-testing-tools/ https://github.com/snapcore/snapd-testing-tools.git main --squash 125 ``` 126 127 128 ## Release process 129 130 ubuntu-image is released as a snap on the [Snap Store](https://snapcraft.io/ubuntu-image). 131 132 When changes are merged in the `main` branch, a new snap is automatically built and pushed to the `latest/edge` channel. 133 134 When we think we have a "stable enough" version that we don't want to break with future merges in `main`, we promote it to `latest/candidate`. 135 136 To do so: 137 1. Create a new branch. 138 2. Update the version in `snapcraft.yaml`. 139 3. Add a changelog entry to `debian/changelog`. 140 4. Commit, create a version tag, and push. 141 5. Merge. 142 6. Wait for the build to appear in `latest/edge`. 143 7. Promote the build to `latest/candidate`. 144 145 After a couple of weeks, if our "early adopters" are happy and we did not break any build or if we did not spot any major fixes, we promote this version from `latest/candidate` to `latest/stable`. 146 147 This way, our users can choose between: 148 149 - The `latest/edge` channel update as soon as we merge changes. 150 - The `latest/candidate` channel with new features/bugfixes but with potentially some newly introduced bug. This channel would be good to let users test requested features. 151 - The `latest/stable` channel that should hopefully contain a rather "bug-free" version because it was tested in more various situations.