@@ -63,29 +63,27 @@ To re-create your development container from the latest image, run:
6363## Working on Cockpit's session pages
6464
6565Most contributors want to work on the web (HTML, JavaScript, CSS) parts of Cockpit.
66+
67+ ### Install Cockpit
68+
6669First, install Cockpit on your local machine as described in:
6770
6871< https://cockpit-project.org/running.html >
6972
73+ ### Build session pages
74+
7075Next, run this command from your top level Cockpit checkout directory, and make
7176sure 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
7782locally built package output directory instead of using the system-installed Cockpit
7883files.
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
8987work 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
103109You often need to test code changes in a VM. You can set the ` $RSYNC ` env
104110variable 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+
112120To make Cockpit use system packages again, instead of your checkout directory,
113121remove 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
119127Cockpit uses autotools, so there are familiar ` ./configure ` script and
120128Makefile 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
153161tests 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
160184There are also static code and syntax checks which you should run often:
161185
@@ -182,45 +206,47 @@ git submodules:
182206Refer to the [ testing README] ( test/README.md ) for details on running the Cockpit
183207integration 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
191223subdirectory 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
199231To make it easy to test out channels without having to write out messages
200232manually, ` 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
204236These 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-
215241To 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
217243you 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
226252source directory.
@@ -273,10 +299,39 @@ During fast iterative development, you can also choose to not run stylelint, by
273299running ` ./build.js ` with the ` -s ` /` --no-stylelint ` option. This speeds up the
274300build 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
0 commit comments