Navigation

    UBports Robot Logo

    UBports Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Guide: set up a clickable working environment inside a LXC contiainer

    App Development
    clickable
    4
    8
    2765
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Emanuele Sorce
      Emanuele Sorce last edited by NeoTheThird

      INTRODUCTION

      Clickable is the Brian Douglass' program to build, manage, install and in general develop for the Ubuntu Touch platform without the need of the whole ubuntu SDK.
      It can runs virtually in any linux environment, but like me maybe also you encoutered problems setting up it in your favourite distro; here I am going to guide you throught setting up it in a LXC container.
      In this way you aren't forced to change distro or run an expansive virtual machine, but you can use clickable almost like a native set up.
      In this guide I consider using the apt package manager. Adapt the 'apt-get' commands to your circustances.

      SET UP LXD

      We are going to use an ubuntu 16.04LTS container. To use it we have to install lxd, the lxc container hypervisor deamon. With the following command:
      "sudo apt-get install lxd"
      You could be on a distro which hasn't in the repository LXD. No problem, if your distro supports snap packages you can install the snap version of LXD.
      I used the snap package to achieve the final result, but I suggest use your distro LXD package if you can. So first install snapd, then install LXD snap:
      "sudo apt-get install snapd"
      "sudo snap install lxd"
      Here is a deeper guide about the LXD snap package: https://stgraber.org/2016/10/17/lxd-snap-available/. If your are going to use the snap package, take a look there.
      Now we have lxd installed, let's configure it:
      "lxd init"
      Just press enter until the end for a standard set up.
      Troubleshooting:
      if you stumble in any strange error when running lxd commands, check if your user is in the lxd group, if not add yourself there:
      "usermod -a -G lxd username"
      Another common issue could be to not have the lxd daemon running; if so just run:
      "sudo systemctl start lxd.service"

      SET UP THE CONTAINER

      Now we'll set up the ubuntu container:
      "lxc launch ubuntu:16.04 best_container_name_ever"
      and lxc will automatically download and set up our new container.
      Before enter the new environment, we need to change some container policy option to enable nested lxc container creation:
      "lxc config set best_container_name_ever security.privilegied true"
      "lxc config set best_container_name_ever security.nesting true"
      now we are ready to enter the matr...emm shell of our ubuntu container:
      "lxc exec best_container_name_ever -- /bin/bash"

      INSIDE THE CONTAINER

      Inside the container we have to do basically three things: basic configuration of the system, creation of a new not-root user and configuring clickable.
      First of all we need some basic utility:
      "apt-get update"
      "apt-get install nano sudo git"
      These packages may be already installed, but who know?
      Next step is to configure a not root user. These commands should work, but I haven't tested them:
      "useradd mr_nice_guy"
      "passwd mr_nice_guy"
      Enable him to run sudo
      "usermod -a -G sudo mr_nice_guy" // (Maybe this is not the most clean way to do it?)
      Now we are ready to being the nice guy.
      "su mr_nice_guy"
      Step in our home directory
      "cd"
      Let's install and configure LXD. See the previous 'SET UP LXD' section, here is the same story.

      CONFIGURE CLICKABLE (INSIDE THE CONTAINER)

      Here we are! Let's eventually download clickable:
      "git clone https://github.com/bhdouglass/clickable.git"
      Let's enter the master directory. Here we need to install the usdk-target executable to be able to run it.
      Inside the container we need to run sudo with the '-S' option, because without it will fail.
      "sudo -S cp usdk-target /bin"
      "sudo -S cp usdk-target /usr/bin"
      "sudo -S cp usdk-target /usr/sbin"
      "sudo -S cp usdk-target /sbin"
      I copyied it into all the four directoryes because I don't know in which one I should copy it; it's a quick-and-dirt solution, but I am too lazy.
      Now we need to patch the clickable executable. I said before that in this environment we have to run sudo with the '-S' option.
      "nano clickable"
      Look for the line:
      "subprocess.check_call(shlex.split('sudo {} usdk-target create -n {} -p {}'.format(env, name, fingerprint)))"
      And add the -S option. Here it is the result:
      "subprocess.check_call(shlex.split('sudo -S {} usdk-target create -n {} -p {}'.format(env, name, fingerprint)))"
      Save with CTRL-O and exit nano.
      You have succeffully set up clickable inside an lxd container!
      Now you can run clickable inside the lxc container like a charm without problems: see the clickable README for informations.
      Note that canonical server might not work, you can tell clickable to use a different image server with the 'USDK_TEST_REMOTE' environment variable.

      FINAL THOUGHTS
      Clickable is a wonderful tool to develop app for ubuntu touch, thanks Brian Douglass and all the devs for manteining it and for all the help they gave me 😃
      If you see any error or incongruence in this guide, please point it out, I'll be happy to correct, expand the guide or just help you.
      Good coding everyone!!!

      edit: fixed a typo

      So Long, and Thanks for All the Fish

      W 1 Reply Last reply Reply Quote 4
      • W
        wgarcia @Emanuele Sorce last edited by

        @Emanuele-Sorce Thanks a lot for such a detailed guide, I think it's crucial that we have a working development environment if we want to contribute.

        1 Reply Last reply Reply Quote 2
        • Emanuele Sorce
          Emanuele Sorce last edited by Emanuele Sorce

          I moved the guide to the wiki, where could be accessed, expanded and corrected with more ease: https://wiki.ubports.com/wiki/Set-up-a-Clickable-working-environment-inside-an-LXC-container Refer to it to have an updated guide

          So Long, and Thanks for All the Fish

          1 Reply Last reply Reply Quote 1
          • NeoTheThird
            NeoTheThird Administrators last edited by

            Wow, great guide! Thank you so much for your effort!

            1 Reply Last reply Reply Quote 0
            • Emanuele Sorce
              Emanuele Sorce last edited by

              @wgarcia @NeoTheThird
              You're welcome

              So Long, and Thanks for All the Fish

              1 Reply Last reply Reply Quote 1
              • mikhael
                mikhael last edited by mikhael

                Guide for creating working chroot-based environment

                The purpose of the post is to provide a guide similar to the one by @Emanuele-Sorce for creating Cordova-based (and maybe other HTML5-based) applications using LXC container. Such applications are built in chroot environment, and build system is for some time unsupported in Xenial. I don't know if there are still any developers who use Cordova for Ubuntu, but if there are some, I hope the guide will be useful.

                The steps needed to setup working environment is basicly the same as in original guide with few modifications specific to build environment.

                1. Set up LXD
                  The steps to set up LXD are the same as in original post

                2. Set up the container
                  We need 17.04+ container, because fixes for build system are published only there and not in 16.04.

                lxc launch ubuntu:17.04 best_container_name_ever
                lxc config set best_container_name_ever security.privilegied true
                lxc config set best_container_name_ever security.nesting true
                lxc exec best_container_name_ever -- /bin/bash
                
                1. Inside the container
                  Inside the container we have to do basically the same three things: basic configuration of the system, creation of a new not-root user and configuring clickable. Steps to create basic configuration of the system and a new not-root user are the same as in original post:

                  apt update  
                  apt install nano sudo git  
                  useradd mr_nice_guy  
                  passwd mr_nice_guy  
                  usermod -a -G sudo mr_nice_guy  
                  
                  # Now we are ready to being the nice guy  
                  su mr_nice_guy  
                  

                  We'll also need to install packages from proposed archive, and so we need to enable the archive by adding something like that to /etc/apt/sources.list:

                  deb http://archive.ubuntu.com/ubuntu zesty-proposed main restricted universe multiverse  
                  
                2. Configure Clickable

                • Download clickable and add it to PATH.
                • Install NodeJS:
                  sudo -S apt install nodejs-legacy npm  
                  
                • Install build tools
                  sudo -S apt install click-dev phablet-tools
                  
                • Download and Install cordova-cli package from Cordova PPA (the PPA is only for Xenial, so I downloaded it manually):
                  wget https://launchpad.net/~cordova-ubuntu/+archive/ubuntu/ppa/+build/9778583/+files/cordova-cli_4.3.1-ubuntu12_all.deb;  
                  sudo -S dpkg -i cordova-cli_4.3.1-ubuntu12_all.deb  
                  
                • Create chroot environment for building apps:
                  sudo -S click chroot -a armhf -f ubuntu-sdk-15.04 create  
                  
                  That's it. We now should have a working clickable environment for building Cordova apps.
                1. Notes on Cordova usage
                  There are number of unfixed long-standing issues with Cordova for Ubuntu. So if you'd like to create apps using Cordova, you might be interested in project's fork, i've created. It is based on last official version, but adds few fixes that make it more usable:
                • WebView is automatically resized when on-screen keyboard is shown/hidden
                • Copy/Paste operations are supported with touchscreen

                There is also repository with patched File plugin, which gives applications ability to list hidden files and directories.

                Emanuele Sorce 1 Reply Last reply Reply Quote 2
                • Emanuele Sorce
                  Emanuele Sorce @mikhael last edited by

                  Good guide 🙂 . Would be nice to have it in the ubports wiki...

                  So Long, and Thanks for All the Fish

                  mikhael 1 Reply Last reply Reply Quote 1
                  • mikhael
                    mikhael @Emanuele Sorce last edited by

                    @Emanuele-Sorce, finally I was able to actually reproduce all the required steps to setup build environment once again, so slightly updated guide is now on wiki

                    1 Reply Last reply Reply Quote 2
                    • First post
                      Last post