Skip to content

Commit 7a516cc

Browse files
authored
Update external docs
1 parent 4e8e0c6 commit 7a516cc

File tree

4 files changed

+167
-70
lines changed

4 files changed

+167
-70
lines changed

external/bots/README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ For managing these images:
3232

3333
- `image-download`: Download selected or all test images
3434
- `image-create`: Create test machine images from scratch (usually through
35-
virt-install or downloading a cloud image), with common build and test
36-
dependencies for Cockpit projects preinstalled
35+
downloading a cloud image), with common build and test dependencies for
36+
Cockpit projects preinstalled
3737
- `image-upload`: Upload a locally built test image to the official image servers
3838

3939
For running and debugging the images:
@@ -210,6 +210,39 @@ progress and at the end there will be links to commits with the new
210210
images. You can then include these commits into the pull request in
211211
any way you like.
212212

213+
### Creating a new image
214+
215+
Creating a new image from scratch requires some
216+
[images/scripts/](./images/scripts) files. For a new image called `tux` we need:
217+
218+
- `tux.bootstrap`: Download or create an initial qcow2 image which boots and has SSH
219+
acccess. If available, this should be the latest available cloud image,
220+
but it may also invoke some other VM build tool or build service.
221+
This script runs in the [cockpit/tasks](https://github.com/cockpit-project/cockpituous/tree/main/tasks/container)
222+
container, and thus can only use the tools installed there. If necessary, add
223+
them first.
224+
- `tux.setup`: The setup script runs inside the downloaded test image,
225+
install all required build and test dependencies, and sets up an `admin`
226+
user.
227+
228+
For a new image it is recommended to follow the existing setup/bootstrap scripts,
229+
for example the `fedora` one.
230+
231+
Run `./image-create -v tux` to build the image. If that succeeds, a new image
232+
is saved in `images` as `images/tux` (a symlink to the real qcow2 file).
233+
Test-boot it with `./vm-run tux`, and ensure you can:
234+
235+
- Log in with SSH as the `admin` and `root` user with our usual test SSH key
236+
- Become root with `sudo` as admin works (password "foobar")
237+
238+
To add that image to our CI, create a PR and follow the "Creating new
239+
images for a pull request" section. External contributors will need to ask a
240+
Cockpit team member to create a copy of the PR and follow this workflow.
241+
242+
For the initial PR it is recommended to add the new image to the `_manual`
243+
testmap of `starter-kit` or other project to prove that the created image is
244+
functional.
245+
213246
### Updating CI to a new Fedora release
214247

215248
`TEST_OS_DEFAULT` is usually set to the latest (stable) Fedora released,

external/source/HACKING.md

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,27 @@ To re-create your development container from the latest image, run:
6363
## Working on Cockpit's session pages
6464

6565
Most contributors want to work on the web (HTML, JavaScript, CSS) parts of Cockpit.
66+
67+
### Install Cockpit
68+
6669
First, install Cockpit on your local machine as described in:
6770

6871
<https://cockpit-project.org/running.html>
6972

73+
### Build session pages
74+
7075
Next, run this command from your top level Cockpit checkout directory, and make
7176
sure to run it as the same user that you'll use to log into Cockpit below.
7277

7378
mkdir -p ~/.local/share/
7479
ln -s $(pwd)/dist ~/.local/share/cockpit
7580

76-
This will cause cockpit to read JavaScript, HTML, and CSS files directly from the
81+
This will cause Cockpit to read JavaScript, HTML, and CSS files directly from the
7782
locally built package output directory instead of using the system-installed Cockpit
7883
files.
7984

80-
Now you can log into Cockpit on your local Linux machine at the following
81-
address. Use the same user and password that you used to log into your Linux
82-
desktop.
83-
84-
<http://localhost:9090>
85-
86-
After every change to the source files, bundles need to be rebuilt. The
87-
recommended and fastest way is to do that is using the "watch" mode (`-w` or
88-
`--watch`) on the page that you are working on. For example, if you want to
85+
The recommended way to build bundles is to use the "watch" mode
86+
(`-w` or`--watch`) on the page you are working on. For example, if you want to
8987
work on anything in [pkg/systemd](https://github.com/cockpit-project/cockpit/tree/main/pkg/systemd/), run:
9088

9189
./build.js -w systemd
@@ -97,8 +95,16 @@ pkg/lib/), you can also build all pages:
9795

9896
./build.js -w
9997

100-
Reload cockpit in your browser after page is built. Press `Ctrl`-`C` to
101-
stop watch mode once you are done with changing the code.
98+
Now you can log into Cockpit on your local Linux machine at the following
99+
address, using the same username and password as your desktop login:
100+
101+
<http://localhost:9090>
102+
103+
Watch mode automatically rebuilds when source files are modified. Once it
104+
finishes building, refresh your browser to see the changes in Cockpit.
105+
Press `Ctrl-C` to stop watch mode when you are done changing the code.
106+
107+
### Testing
102108

103109
You often need to test code changes in a VM. You can set the `$RSYNC` env
104110
variable to copy the built page into the given SSH target's
@@ -109,12 +115,14 @@ one of these commands:
109115
RSYNC=c ./build.js -w kdump
110116
RSYNC=c ./build.js -w
111117

118+
### Returning to system packages
119+
112120
To make Cockpit use system packages again, instead of your checkout directory,
113121
remove the symlink with the following command and log back into Cockpit:
114122

115123
rm ~/.local/share/cockpit
116124

117-
## Working on the non-web parts of Cockpit
125+
## Building and unit tests
118126

119127
Cockpit uses autotools, so there are familiar `./configure` script and
120128
Makefile targets.
@@ -152,10 +160,26 @@ which will output a URL to connect to with a browser, such as
152160
<http://localhost:8765/qunit/base1/test-dbus.html>. Adjust the path for different
153161
tests and inspect the results there.
154162

155-
You can also run individual tests by specifying the `TESTS` environment
156-
variable:
163+
QUnit tests are run as part of a pytest test called `test_browser`. You can
164+
run individual tests via `pytest -k`, like so:
165+
166+
pytest -k test-fsinfo.html
167+
168+
You can see JavaScript code coverage information for QUnit tests. For a
169+
summary table:
170+
171+
pytest -k test_browser --js-cov
172+
173+
And for detailed output on uncovered sections in a specific file, something
174+
like:
157175

158-
make check TESTS=qunit/base1/test-chan.html
176+
pytest -k test-fsinfo.html --js-cov-files='*/fsinfo.ts'
177+
178+
Coverage information is gathered into the pytest tmpdir, regardless of which
179+
coverage-related commandline flags are given, so it's also possible to drill
180+
down after the fact — without re-running tests — using something like:
181+
182+
test/common/js_coverage.py -m '*/fsinfo.ts' /tmp/pytest-of-*/pytest-current/js-coverage/*
159183

160184
There are also static code and syntax checks which you should run often:
161185

@@ -182,45 +206,47 @@ git submodules:
182206
Refer to the [testing README](test/README.md) for details on running the Cockpit
183207
integration tests locally.
184208

185-
## Python bridge
209+
## Bridge
186210

187-
Most distro releases now ship a replacement for the C bridge written in Python.
188-
It resides in `src/cockpit` with most of its rules in `src/Makefile.am`. This
189-
directory was chosen because it matches the standard so-called "src layout"
190-
convention for Python packages, where each package (`cockpit`) is a
211+
The Cockpit bridge is the initial program launched in a Cockpit Linux session:
212+
Its stdin/out is connected to the web socket (and thus to JavaScript in the
213+
[pages](pkg/)), where it speaks a [JSON protocol](doc/protocol.md) that
214+
multiplexes "channels" -- abstractions of operating system APIs that the pages
215+
use to implement their functionality. This protocol is translated into
216+
operating system calls such as opening or writing files, D-Bus calls, or HTTP
217+
queries. Think of the bridge as the moral equivalent of "bash" in a human SSH
218+
session.
219+
220+
The bridge resides in `src/cockpit` with most of its rules in `src/Makefile.am`.
221+
This directory was chosen because it matches the standard so-called "src
222+
layout" convention for Python packages, where each package (`cockpit`) is a
191223
subdirectory of the `src` directory.
192224

193225
### Running the bridge
194226

195-
The Python bridge can be used interactively on a local machine:
227+
The bridge can be used interactively on a local machine out of the source tree:
196228

197229
PYTHONPATH=src python3 -m cockpit.bridge
198230

199231
To make it easy to test out channels without having to write out messages
200232
manually, `cockpit.misc.print` can be used:
201233

202-
PYTHONPATH=src python3 -m cockpit.misc.print open fslist1 path=/etc watch=False | PYTHONPATH=src python3 -m cockpit.bridge
234+
PYTHONPATH=src python3 -m cockpit.misc.print open fsinfo path=/etc 'attrs=["type", "entries"]' | PYTHONPATH=src python3 -m cockpit.bridge
203235

204236
These shell aliases might be useful when experimenting with the protocol:
205237

206238
alias cpy='PYTHONPATH=src python3 -m cockpit.bridge'
207239
alias cpf='PYTHONPATH=src python3 -m cockpit.misc.print'
208240

209-
When working with the Python bridge on test images, note that `rhel-8*` still
210-
uses the C bridge. So if you want to explicitly have the Python bridge on those
211-
images use:
212-
213-
./test/image-prepare --python
214-
215241
To enable debug logging in journal on a test image, you can pass `--debug` to
216242
`image-prepare`. This will set `COCKPIT_DEBUG=all` to `/etc/environment`, if
217243
you are only interested channel debug messages change `all` to
218244
`cockpit.channel`.
219245

220-
### Testing the Python bridge
246+
### Testing the bridge
221247

222-
There are a growing number of Python `unittest` tests being written to test
223-
parts of the new bridge code. You can run these with `make pytest` or
248+
There are a growing number of [pytest](https://docs.pytest.org) tests being written to test
249+
the bridge code. You can run these with `make pytest` or
224250
`make pytest-cov`. Those are both just rules to make sure that the
225251
`systemd_ctypes` submodule is checked out before running `pytest` from the
226252
source directory.
@@ -273,10 +299,39 @@ During fast iterative development, you can also choose to not run stylelint, by
273299
running `./build.js` with the `-s`/`--no-stylelint` option. This speeds up the
274300
build and avoids build failures due to ill-formatted CSS or other issues.
275301

302+
## Working on your local machine: systemd-sysext
303+
304+
If you want to safely test your local changes directly on it, Cockpit supports
305+
installation as a [systemd-sysext](https://www.freedesktop.org/software/systemd/man/latest/systemd-sysext.html).
306+
This covers all parts of Cockpit (ws, tls, session, bridge, login page, systemd
307+
units, PAM configuration, and the session pages) except for the SELinux policy.
308+
It gets installed into `/run/extensions/`, so nothing ever hits the disk and
309+
this also works on read-only installations (CoreOS, OSTree, bootc).
310+
311+
Just run:
312+
313+
tools/make-sysext
314+
315+
This runs `./autogen.sh` if necessary, and then just re-`make`s your tree,
316+
re-installs it into `/run/extensions`, and reloads the sysext in systemd.
317+
Afterwards you can connect to http://localhost:9090 as usual.
318+
319+
To remove this, reboot or run
320+
321+
tools/make-sysext stop
322+
323+
**Attention**: This is not currently compatible with SELinux in enforcing mode.
324+
If you have that, you need to disable it:
325+
326+
sudo setenforce 0
327+
276328
## Working on your local machine: Web server
277329

278-
To test changes to the login page or any other resources, you can bind-mount the
279-
build tree's `dist/static/` directory over the system one:
330+
If the above systemd-sysext approach does not work for you, you can also test
331+
changes with some bind mounts.
332+
333+
To test changes to the login page, you can bind-mount the build tree's
334+
`dist/static/` directory over the system one:
280335

281336
sudo mount -o bind dist/static/ /usr/share/cockpit/static/
282337

external/source/test/README.md

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ You first need to build cockpit, and install it into a VM:
2525

2626
test/image-prepare
2727

28-
This uses the default OS image, which is currently Fedora 39. See `$TEST_OS`
29-
below how to select a different one.
28+
This uses the default OS image. See `$TEST_OS` below how to select a different one.
29+
30+
See `test/image-prepare --help` for some special modes, like skipping unit
31+
tests, building overlays, or preparing an image with the
32+
[cockpit/ws container](https://quay.io/repository/cockpit/ws) instead of RPMs.
33+
See our scenarios in [test/run](./run) for how they are being used.
3034

3135
In most cases you want to run an individual test in a suite, for example:
3236

@@ -167,38 +171,23 @@ to push pixel tests.
167171

168172
You can set these environment variables to configure the test suite:
169173

170-
TEST_OS The OS to run the tests in. Currently supported values:
171-
"centos-9-stream"
172-
"centos-10"
173-
"debian-stable"
174-
"debian-testing"
175-
"fedora-39"
176-
"fedora-40"
177-
"fedora-coreos"
178-
"rhel-9-4"
179-
"rhel4edge",
180-
"ubuntu-2204"
181-
"ubuntu-stable"
182-
"fedora-39" is the default (TEST_OS_DEFAULT in bots/lib/constants.py)
183-
184-
TEST_JOBS How many tests to run in parallel. The default is 1.
185-
186-
TEST_CDP_PORT Attach to an actually running browser that is compatible with
187-
the Chrome Debug Protocol, on the given port. Don't use this
188-
with parallel tests.
189-
190-
TEST_BROWSER What browser should be used for testing. Currently supported values:
191-
"chromium"
192-
"firefox"
193-
"chromium" is the default.
194-
195-
TEST_SHOW_BROWSER Set to run browser interactively. When not specified,
196-
browser is run in headless mode. When set to "pixels",
197-
the browser will be resized to the exact dimensions that
198-
are used for pixel tests.
199-
200-
TEST_TIMEOUT_FACTOR Scale normal timeouts by given integer. Useful for
201-
slow/busy testbeds or architectures.
174+
* `TEST_OS`: The OS to run the tests in, like "fedora-coreos" or
175+
"debian-stable". See the "cockpit-project/cockpit" section in the
176+
[test map](https://github.com/cockpit-project/bots/blob/main/lib/testmap.py)
177+
for all supported values. "fedora-40" is the default (`TEST_OS_DEFAULT` in
178+
bots' [constants.py](https://github.com/cockpit-project/bots/blob/main/lib/constants.py)).
179+
180+
* `TEST_JOBS`: How many tests to run in parallel. The default is 1.
181+
182+
* `TEST_BROWSER`: What browser should be used for testing. Currently supported
183+
values are "chromium" and "firefox". "chromium" is the default.
184+
185+
* `TEST_SHOW_BROWSER`: Set to run browser interactively. When not specified,
186+
browser is run in headless mode. When set to "pixels", the browser will be
187+
resized to the exact dimensions that are used for pixel tests.
188+
189+
* `TEST_TIMEOUT_FACTOR`: Scale normal timeouts by given integer. Useful for
190+
slow/busy testbeds or architectures.
202191

203192
See the [bots documentation]({{ site.baseurl }}/external/bots/README.html)
204193
for details about the tools and configuration for these.

external/wiki/Proxying-Cockpit-over-Apache-with-LetsEncrypt.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ Change this file so it looks like the following.
101101
</IfModule>
102102
```
103103

104+
With Apache 2.4.47 or later, this could also be written as:
105+
106+
```apacheconf
107+
<IfModule mod_ssl.c>
108+
<VirtualHost *:443>
109+
ServerName cockpit.your-domain.com
110+
SSLCertificateFile /etc/letsencrypt/live/cockpit.your-domain.com/fullchain.pem
111+
SSLCertificateKeyFile /etc/letsencrypt/live/cockpit.your-domain.com/privkey.pem
112+
Include /etc/letsencrypt/options-ssl-apache.conf
113+
114+
ProxyPreserveHost On
115+
ProxyRequests Off
116+
117+
# Proxy to your local cockpit instance
118+
ProxyPass / http://127.0.0.1:9090/ upgrade=websocket
119+
ProxyPassReverse / http://127.0.0.1:9090/
120+
</VirtualHost>
121+
</IfModule>
122+
```
123+
104124
Save and close the file. Then restart Apache web server.
105125

106126
`sudo systemctl restart apache2`

0 commit comments

Comments
 (0)