Merge ~cjwatson/launchpad:doc-running into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: c0aa9fd25045126782fd67c4e1bb59e4997bd465
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:doc-running
Merge into: launchpad:master
Diff against target: 439 lines (+416/-0)
3 files modified
doc/index.rst (+8/-0)
doc/running-details.rst (+57/-0)
doc/running.rst (+351/-0)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+412405@code.launchpad.net

Commit message

Add "Running Launchpad" tutorial from dev.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Only made it halfway through until it got too late.

Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

LGTM

I try to see a pattern for the four different kinds of documentation Daniele told us about.

I think the "Details section" would belong to the "Explanation" mode.

That is nothing that needs to be done now.

Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve
Revision history for this message
Colin Watson (cjwatson) wrote :

I think you're right - I pushed the "Details" section out to a separate document and added a link. How's this?

Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/doc/index.rst b/doc/index.rst
2index ed599e7..1677578 100644
3--- a/doc/index.rst
4+++ b/doc/index.rst
5@@ -22,6 +22,14 @@ Overview
6 values
7 faq
8
9+Tutorials
10+=========
11+
12+.. toctree::
13+ :maxdepth: 1
14+
15+ running
16+
17 Guides
18 ======
19
20diff --git a/doc/running-details.rst b/doc/running-details.rst
21new file mode 100644
22index 0000000..aad600b
23--- /dev/null
24+++ b/doc/running-details.rst
25@@ -0,0 +1,57 @@
26+==============================
27+Launchpad installation details
28+==============================
29+
30+What the installation process does
31+----------------------------------
32+
33+The ``rocketfuel-setup`` script first determines what release of Ubuntu
34+you're running, then installs various lines into files under ``/etc``, to
35+enable you to run Launchpad services locally. For example, it adds entries
36+for "launchpad.test", "bazaar.launchpad.test", "lists.launchpad.test", and
37+others to your ``/etc/hosts`` file, so that after you build Launchpad you
38+can browse to ``launchpad.test`` and see a locally-running instance. It
39+also installs some packages, dependencies that Launchpad needs in order to
40+run. This is why the ``sudo`` access is necessary; consult the script for
41+details of what it's doing.
42+
43+Once it's got the system preparation out of the way, the script clones
44+Launchpad's Git repository (that's the ``launchpad`` directory above). That
45+will take a while.
46+
47+After it gets that, it fetches the other dependencies, the third-party
48+libraries, by invoking a separate script,
49+``launchpad/utilities/rocketfuel-get``. That will take a while too, as
50+there are over 200 such libraries.
51+
52+Once it has all the dependencies, it links them into the trunk working tree,
53+using the script ``launchpad/utilities/link-external-sourcecode``.
54+
55+Do-it-yourself installation
56+---------------------------
57+
58+**We only support using rocketfuel-setup to set up Launchpad.** It adjusts
59+a lot of things to get the development process running smoothly, as
60+summarized above. However, sometimes you might want to just get a build of
61+Launchpad to run its tests, or to run a script packaged with Launchpad, or
62+to do your own manual changes of the files that ``rocketfuel-setup`` would
63+normally touch. These are the basics of what needs to be done for that
64+route - **unsupported hints**.
65+
66+You'll need packages from a PPA: ``ppa:launchpad/ubuntu/ppa``.
67+
68+.. code-block:: shell-session
69+
70+ $ sudo apt-add-repository ppa:launchpad/ubuntu/ppa
71+
72+Install the ``launchpad-developer-dependencies`` package.
73+
74+Get the code:
75+
76+.. code-block:: shell-session
77+
78+ $ git clone https://git.launchpad.net/launchpad
79+ $ cd launchpad
80+ $ utilities/update-sourcecode
81+ $ git clone --depth=1 https://git.launchpad.net/lp-source-dependencies download-cache
82+ $ make
83diff --git a/doc/running.rst b/doc/running.rst
84new file mode 100644
85index 0000000..304138d
86--- /dev/null
87+++ b/doc/running.rst
88@@ -0,0 +1,351 @@
89+=================
90+Running Launchpad
91+=================
92+
93+.. note::
94+
95+ `Ask for help <https://dev.launchpad.net/Help>`_ right away if you run
96+ into problems.
97+
98+This page explains how to set up and run Launchpad (for development) on your
99+own machine, using a `LXD
100+<https://linuxcontainers.org/lxd/introduction/>`_-managed container to
101+isolate it from the rest of your system.
102+
103+Supported operating systems
104+===========================
105+
106+For the host system, any reasonably modern Ubuntu release should work.
107+Other Linux distributions that have LXD should work too, though we don't
108+test on them.
109+
110+For the containers, these instructions should work with Ubuntu 16.04 LTS or
111+later. We currently test on 16.04 and 18.04, with the aim of upgrading
112+production to 18.04 soon. 20.04 is known not to work yet.
113+
114+Launchpad requires at least Python 3.5 (i.e. newer than Ubuntu 14.04 LTS).
115+
116+We'd like Launchpad to run on other operating systems, especially `Debian
117+GNU/Linux <https://www.debian.org/>`_, so that more people can contribute to
118+Launchpad development. If you're interested in working on Launchpad
119+portability, please `let us know <https://dev.launchpad.net/Help>`_. Note
120+that our focus is on getting Launchpad to build easily so more people can
121+participate in Launchpad development. Running a stable production instance
122+would be *much* harder than running a single-developer test instance, and we
123+don't recommend it. Unlike many open source projects, we're not seeking to
124+maximize the number of installations; our goal is to improve the `instance
125+we're already running <https://launchpad.net/>`_.
126+
127+Why use LXD containers?
128+=======================
129+
130+Launchpad development setup makes significant changes to your machine; it's
131+nice to be unaffected by those when you're not doing such development.
132+Using containers means that the version of Ubuntu on your host system
133+doesn't need to match Launchpad's requirements. Multiple containers can be
134+used to work around Launchpad's limitations regarding concurrent test runs
135+on a single machine.
136+
137+LXD also has some nice snapshotting and ZFS capabilities, and is what other
138+Launchpad developers use, so other people will be able to help you debug
139+your setup if needed.
140+
141+The installation script is written with the assumption that it will be
142+running inside such a container. If you run it on your host system, it may
143+well break your host system.
144+
145+Create a LXD container
146+======================
147+
148+This assumes you already have LXD set up. If not, follow the `instructions
149+<https://linuxcontainers.org/lxd/getting-started-cli/>`_ for getting it
150+installed and configured on your network.
151+
152+1. If you haven't done so already, run this script to set up LXD to let you
153+ use your home directory inside the container. Some developers prefer to
154+ only mount a subdirectory of their home directory in the container: to do
155+ that, replace ``$HOME`` with ``$HOME/src`` or similar.
156+
157+.. code-block:: sh
158+
159+ #! /bin/sh
160+
161+ id=400000 # some large uid outside of typical range, and outside of already mapped ranges in /etc/sub{u,g}id
162+ uid=$(id -u)
163+ gid=$(id -g)
164+ user=$(id -un)
165+ group=$(id -gn)
166+
167+ # give lxc permission to map your user/group id through
168+ sudo usermod --add-subuids ${uid}-${uid} --add-subgids ${gid}-${gid} root
169+
170+ # create a profile to control this
171+ lxc profile create $user >/dev/null 2>&1
172+
173+ # configure profile
174+ cat << EOF | lxc profile edit $user
175+ name: $user
176+ description: allow home dir mounting for $user
177+ config:
178+ raw.idmap: |
179+ uid $uid $id
180+ gid $gid $id
181+ user.user-data: |
182+ #cloud-config
183+ runcmd:
184+ - "groupadd $group --gid $id"
185+ - "useradd $user --uid $id --gid $group --groups adm,sudo --shell /bin/bash"
186+ - "echo '$user ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/90-cloud-init-users"
187+ - "chmod 0440 /etc/sudoers.d/90-cloud-init-users"
188+ devices:
189+ home:
190+ type: disk
191+ source: $HOME
192+ path: $HOME
193+ EOF
194+
195+2. Create a container. This command creates a Ubuntu 16.04 unprivileged
196+ container using the profile created in the previous step.
197+
198+.. code-block:: sh
199+
200+ lxc launch ubuntu:16.04 lpdev -p default -p $USER
201+
202+3. Find the container IP, either from ``lxc list`` or ``lxc info lpdev``.
203+
204+4. In order to be able to ssh into the container, you need to add your
205+ public key to your local ``.ssh/authorized_keys`` configuration. Also
206+ make sure that both ``.ssh`` (700) and ``authorized_keys`` (600) have the
207+ correct permissions.
208+
209+5. Connect as follows. (The -A permits you to access Launchpad code hosting
210+ from within the container without needing to reenter passphrases.)
211+
212+.. code-block:: sh
213+
214+ ssh -A $user@IP_ADDRESS_FROM_LXC_LS
215+
216+Getting Launchpad
217+=================
218+
219+Do all this *inside* the container you set up previously. Be aware that
220+changes in your home directory inside the container will also be seen
221+outside the container and vice versa.
222+
223+If your Launchpad username differs from your local one, then put this in
224+``~/.ssh/config`` in the container before doing anything else, replacing
225+``LPUSERNAME`` with your Launchpad username::
226+
227+ Host bazaar.launchpad.net
228+ User LPUSERNAME
229+ Host git.launchpad.net
230+ User LPUSERNAME
231+
232+Then:
233+
234+.. code-block:: shell-session
235+
236+ $ mkdir ~/launchpad
237+ $ cd ~/launchpad
238+ $ curl https://git.launchpad.net/launchpad/plain/utilities/rocketfuel-setup >rocketfuel-setup
239+
240+Read through the rocketfuel-setup script at this point and make sure you're
241+OK with what it's going to do. (See :doc:`running-details` if you want to
242+know more.)
243+
244+.. code-block:: shell-session
245+
246+ $ chmod a+x rocketfuel-setup
247+ $ ./rocketfuel-setup
248+
249+This will take a while -- maybe a few hours to get everything, depending on
250+your Internet connection.
251+
252+Note that you will be prompted for your ``sudo`` password, and for a
253+Launchpad login ID (that is, your username on ``launchpad.net``). The sudo
254+access is necessary to get Launchpad running on your box; the Launchpad
255+login is not strictly necessary, and you can just hit Return there if you
256+want. See below for an explanation.
257+
258+Note that this will make changes to your Apache configuration if you already
259+have an Apache server in your container. It will also add entries to
260+``/etc/hosts``, and it will setup a PostgreSQL server in your container.
261+
262+If you are running ``rocketfuel-setup`` to bring up a new container but your
263+home directory already has a usable Launchpad tree, you can pass
264+``--no-workspace`` to only perform the system-wide setup.
265+
266+Note that if ``rocketfuel-setup`` bails out with instructions to fix
267+something, you just need to run it again and it should pick up where it left
268+off.
269+
270+.. code-block:: shell-session
271+
272+ $ sudo apt-get dist-upgrade
273+
274+This is just to make doubly-sure everything from the Launchpad PPA gets
275+installed.
276+
277+.. code-block:: shell-session
278+
279+ $ ls
280+ launchpad/ lp-sourcedeps/
281+ $ cd launchpad
282+
283+You are now in a newly-cloned Git repository, with one branch ('master'),
284+into whose working tree the other source dependencies have been symlinked.
285+The source dependencies actually live in ``../lp-sourcedeps``.
286+
287+Installing the pre-commit hook
288+==============================
289+
290+If you intend to make any changes to Launchpad, you should also set up
291+`pre-commit <https://pre-commit.com/>`_ now:
292+
293+1. Install ``pre-commit`` itself. If your host system is Ubuntu 20.10 or
294+ newer, then ``sudo apt install pre-commit`` is enough; otherwise, you can
295+ install it in your user account (`pipx <https://pypi.org/project/pipx/>`_
296+ works well to keep it isolated; whatever you do, don't run ``pip``
297+ system-wide as root!). We require this to be installed separately rather
298+ than including it in Launchpad's virtual environment because developers
299+ commonly run ``git commit`` outside the container used for running
300+ Launchpad.
301+
302+2. Install the ``pre-commit`` git hook by running ``pre-commit install`` in
303+ your newly-cloned ``launchpad`` repository.
304+
305+Building
306+========
307+
308+Before you can run Launchpad for the first time, you need to set up PostgreSQL.
309+
310+.. note::
311+
312+ **DO NOT run the database setup script below if you use PostgreSQL for
313+ anything other than Launchpad!** Running the script will destroy any
314+ PostgreSQL databases on your system. See
315+ https://dev.launchpad.net/DatabaseSetup for details.
316+
317+.. code-block:: shell-session
318+
319+ $ ./utilities/launchpad-database-setup $USER
320+
321+**(Please have read the previous comment before you run the above command!)**
322+
323+Finally, build the database schema (this may take several minutes):
324+
325+.. code-block:: shell-session
326+
327+ $ make schema
328+
329+Running
330+=======
331+
332+Now you should be able to start up Launchpad:
333+
334+.. code-block:: shell-session
335+
336+ $ make run
337+
338+This only runs the basic web application. `Codehosting
339+<Code/HowToUseCodehostingLocally>`_ and `Soyuz
340+<Soyuz/HowToUseSoyuzLocally>`_ require additional steps.
341+
342+For subsequent builds, you can just do ``make run`` right away. You don't
343+need to do ``make schema`` every time, and you should avoid it because it's
344+expensive and because it will clean out any data you might have put into
345+your test instance (through the web UI or by running other scripts).
346+
347+Setting up remote access
348+========================
349+
350+Unless the only thing you're doing is running parts of the test suite, you
351+probably want to make your new Launchpad instance accessible from other
352+machines on the same local network, or in particular from the host system.
353+
354+Amending the Apache configuration
355+---------------------------------
356+
357+Launchpad's default development Apache config
358+(``/etc/apache2/sites-available/local-launchpad.conf``) only listens on
359+127.0.0.88. This can be overridden with the ``LISTEN_ADDRESS`` environment
360+variable when running ``make install``. You probably want to make it listen
361+on everything:
362+
363+.. code-block:: shell-session
364+
365+ $ sudo make LISTEN_ADDRESS='*' install
366+
367+Amending the hosts file
368+-----------------------
369+
370+Launchpad makes extensive use of virtual hosts, so you'll need to add
371+entries to ``/etc/hosts`` on any machine from which you want to access the
372+Launchpad instance. You'll see the relevant hostnames in ``/etc/hosts`` on
373+the machine running the instance - they need to be added to the remote
374+machine, mapped to the server machine or container's external IP address.
375+
376+If some of those other machines run Windows, it may be helpful to know that
377+the Windows equivalent of ``/etc/hosts`` is located at
378+``C:\WINDOWS\system32\drivers\etc\hosts``. Note that Windows' version has a
379+line length limit, so you might have to split it across multiple lines or
380+only include the hostnames that you need.
381+
382+You should now be able to access ``https://launchpad.test/`` in a web
383+browser on a suitably configured remote computer. Accept the local
384+self-signed certificate. You can log in as ``admin@canonical.com`` without
385+a password. (This is only for development convenience, and assumes that you
386+trust machines that can route to your LXD containers; of course a production
387+deployment would need real authentication.)
388+
389+Accessing launchpad.test from a single host over SSH
390+----------------------------------------------------
391+
392+As an alternative to the above, SSH provides a SOCKS proxy. By running that
393+proxy on the target machine, you can view its Launchpad web site as if you
394+were on that machine, without having to open non-SSH ports to a wider
395+network. To do so:
396+
397+.. code-block:: shell-session
398+
399+ $ ssh -D8110 target-machine
400+
401+Then set your browser's SOCKS proxy settings to use ``target-machine:8110``.
402+
403+Stopping
404+========
405+
406+You can stop Launchpad by hitting **Control-C** in the terminal where you
407+started it:
408+
409+.. code-block:: shell-session
410+
411+ ^C
412+ [...shutting down Launchpad...]
413+ $
414+
415+Or you can be at a prompt in the same directory and run this:
416+
417+.. code-block:: shell-session
418+
419+ $ make stop
420+
421+Troubleshooting
422+===============
423+
424+"The LXC container is not getting an IPv4 address assigned and the network
425+connectivity inside the container doesn't work."
426+
427+On Ubuntu 21.10, ``ufw`` uses ``nftables`` by default, so if you are using
428+Ubuntu 21.10 on the host and ``ufw`` is enabled with the default policy of
429+blocking incoming and routed traffic, the rules added by LXD will not take
430+effect, and hence LXD's traffic will be dropped.
431+
432+The fix is to add ``ufw allow`` rules to allow incoming and routed traffic
433+on the bridge interface, like this (replacing ``lxdbr0`` with the name of
434+the bridge interface on your computer):
435+
436+.. code-block:: sh
437+
438+ sudo ufw allow in on lxdbr0
439+ sudo ufw route allow in on lxdbr0

Subscribers

People subscribed via source and target branches

to status/vote changes: