Diff for "Running/LXD"

Not logged in - Log In / Register

Differences between revisions 1 and 13 (spanning 12 versions)
Revision 1 as of 2016-05-18 18:37:05
Size: 2378
Editor: bryanquigley
Comment: initial
Revision 13 as of 2020-09-29 10:12:52
Size: 3160
Editor: cjwatson
Comment: no 14.04
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
This page explains how to set up and run Launchpad (for development) inside an LXD managed LXC container. [[Running/LXC]] is still the recommended development setup and what most developers currently use.  This page explains how to set up and run Launchpad (for development) inside an LXD managed LXC container, superseding [[Running/LXC]].
Line 6: Line 6:
LXD also has some nice snapshoting and ZFS capabilities that I find easier to use with LXD's frontend. LXD also has some nice snapshotting and ZFS capabilities that I find easier to use with LXD's frontend.
Line 8: Line 8:
These instructions should work on Ubuntu 14.04 LTS or later. It has only been tested on 16.04 though. These instructions should work on Ubuntu 16.04 LTS or later. We currently test on 16.04 and 18.04, with the aim of upgrading production to 18.04 soon.
Line 13: Line 13:
 1. If you haven't done so already, run this script to set up LXD to let you use your home directory inside the container:
{{{
#! /bin/sh

id=400000 # some large uid outside of typical range, and outside of already mapped ranges in /etc/sub{u,g}id
uid=$(id -u)
gid=$(id -g)
user=$(id -un)
group=$(id -gn)

# give lxc permission to map your user/group id through
sudo usermod --add-subuids ${uid}-${uid} --add-subgids ${gid}-${gid} root

# create a profile to control this
lxc profile create $user >/dev/null 2>&1

# configure profile
cat << EOF | lxc profile edit $user
name: $user
description: allow home dir mounting for $user
config:
  raw.idmap: |
    uid $uid $id
    gid $gid $id
  user.user-data: |
    #cloud-config
    runcmd:
      - "groupadd $group --gid $id"
      - "useradd $user --uid $id --gid $group --groups adm,sudo --shell /bin/bash"
      - "echo '$user ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/90-cloud-init-users"
      - "chmod 0440 /etc/sudoers.d/90-cloud-init-users"
devices:
  home:
    type: disk
    source: $HOME
    path: $HOME
EOF
}}}
Line 14: Line 53:
 This command creates a Ubuntu 12.04 32 bit privileged container.  Feel free to drop the i386 to use 64 bit if you have the RAM. As of this writing 32 bit takes 700MB and 64 bit takes 1.5GB of memory  This command creates a Ubuntu 16.04 unprivileged container using the profile created in the previous step.
Line 16: Line 55:
 lxc launch ubuntu:12.04/i386 lpdev -c security.privileged=true  lxc launch ubuntu:16.04 lpdev -p default -p $USER
Line 18: Line 57:
 1. Then share your home directory with the new container. This only works if you make it a privileged container above.
 {{{
 lxc config device add priv homedir disk source=/home/$USER path=/home/ubuntu
 }}}
Line 26: Line 62:
ssh -A ubuntu@IP_ADDRESS_FROM_LXC_LS
 
The -A permits you to access Launchpad code hosting from within the container without needing to reenter passphrases.
 ssh -A $user@IP_ADDRESS_FROM_LXC_LS
Line 30: Line 64:
 The -A permits you to access Launchpad code hosting from within the container without needing to reenter passphrases.
Line 34: Line 70:
 1. [Inside the container] You can now follow the normal LP [[Running]] instructions. Be warned that changes in your home directory will also be seen outside the container and vice versa. If your home directory already has a Launchpad work area set up you'll want to run rocketfuel-setup --no-workspace to avoid trying to recreate it, but all subsequent steps are still required.  1. [Inside the container] You can now follow the normal [[Running|LP installation instructions]]. Be warned that changes in your home directory will also be seen outside the container and vice versa. If your home directory already has a Launchpad work area set up you'll want to run rocketfuel-setup --no-workspace to avoid trying to recreate it, but all subsequent steps are still required.
Line 36: Line 72:
 1. Follow [[Running/RemoteAccess]] to set up access from the host's applications to the container's Launchpad instance or else going to launchpad.dev won't work.  1. Follow [[Running/RemoteAccess]] to set up access from the host's applications to the container's Launchpad instance or else going to launchpad.test won't work.

This page explains how to set up and run Launchpad (for development) inside an LXD managed LXC container, superseding Running/LXC.

Why?

Launchpad development setup makes significant changes to your machine; it's nice to be unaffected by those when you're not doing such development. Also, multiple containers can be used to work around Launchpad's limitations regarding concurrent test runs on a single machine.

LXD also has some nice snapshotting and ZFS capabilities that I find easier to use with LXD's frontend.

These instructions should work on Ubuntu 16.04 LTS or later. We currently test on 16.04 and 18.04, with the aim of upgrading production to 18.04 soon.

Create an LXD Container

This assumes you already have LXD setup. If not, follow the instructions for getting lxd installed and configured on your network: https://linuxcontainers.org/lxd/getting-started-cli/

  1. If you haven't done so already, run this script to set up LXD to let you use your home directory inside the container:

id=400000  # some large uid outside of typical range, and outside of already mapped ranges in /etc/sub{u,g}id
uid=$(id -u)
gid=$(id -g)
user=$(id -un)
group=$(id -gn)

# give lxc permission to map your user/group id through
sudo usermod --add-subuids ${uid}-${uid} --add-subgids ${gid}-${gid} root

# create a profile to control this
lxc profile create $user >/dev/null 2>&1

# configure profile
cat << EOF | lxc profile edit $user
name: $user
description: allow home dir mounting for $user
config:
  raw.idmap: |
    uid $uid $id
    gid $gid $id
  user.user-data: |
    #cloud-config
    runcmd:
      - "groupadd $group --gid $id"
      - "useradd $user --uid $id --gid $group --groups adm,sudo --shell /bin/bash"
      - "echo '$user ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/90-cloud-init-users"
      - "chmod 0440 /etc/sudoers.d/90-cloud-init-users"
devices:
  home:
    type: disk
    source: $HOME
    path: $HOME
EOF
  1. Create a container This command creates a Ubuntu 16.04 unprivileged container using the profile created in the previous step.
     lxc launch ubuntu:16.04 lpdev -p default -p $USER
  2. Find the container IP, either from lxc list or lxc info lpdev.

  3. Then connect with:
     ssh -A $user@IP_ADDRESS_FROM_LXC_LS
    The -A permits you to access Launchpad code hosting from within the container without needing to reenter passphrases.
  4. [Inside the container] Install Bazaar so you can run rocketfuel-setup.
     sudo apt-get install bzr
  5. [Inside the container] You can now follow the normal LP installation instructions. Be warned that changes in your home directory will also be seen outside the container and vice versa. If your home directory already has a Launchpad work area set up you'll want to run rocketfuel-setup --no-workspace to avoid trying to recreate it, but all subsequent steps are still required.

  6. Follow Running/RemoteAccess to set up access from the host's applications to the container's Launchpad instance or else going to launchpad.test won't work.

Running/LXD (last edited 2022-06-17 12:36:25 by cjwatson)