Remote development of ROM and Framework is a development mode that our department has been practicing for a long time. Due to the lack of working environment, we have to work on the cloud. In this special time, telecommuting is popular, I share with you the way we use this remote ROM development, hoping to help those who need it. The following includes Docker and VS Code content, if not interested or too low, can be removed 😏😶. 🤥 leave a suggestion is good ~~~

A ROM source has about 10GB, and compiled, plus some intermediate files, a total of about 100GB. We need to maintain more than 20 of these ROMs. And the compilation ROM is generally using multi-threaded compilation, if the CPU performance is not strong or CPU core number is not many, or disk performance is weak, the compilation will be slow. Developing ROMs using notebooks is cumbersome, may require frequent deletion of build directories, and performance is inadequate. And everyone to match a workstation, more than a few hard disk, the cost of use is very high, the company will not allow.

Therefore, we initially directly applied for a cloud host or cloud physical machine with large space, and directly built the ROM development environment on the cloud host. The development of burning goose things will not always be so smooth, we found that the cloud host space will not be enough, the company’s cloud host environment will change, which leads to we often need to migrate the environment, resulting in the consequence is, the hard installation from Android4.4 to Android8.0 compilation environment and some supporting tools need to reinstall again. Sadly, our environment had always been based on Ubuntu14, and after the migration, the company only provided an image of Ubuntu16. As a result, compilations on older versions like Android4.4 were problematic, and some tools were missing on Ubuntu16.

Without these problems, we wouldn’t have thought of a better strategy — to put the environment inside a Docker container. Then we package the container as an image, and we just maintain the image.

For remote development, some students who develop the Framework may not adapt to the use of VIM to develop, remote replacement of resources such work tedious, repetitive and painful. So IN early 2018 I was looking for a remote development tool called Visual Studio Code. We were probably the first ROM team to use VS Code’s remote development features.

So much nonsense, that is to say two artifacts:

  • Docker
  • VS Code

The following is the specific process of setting up the environment. If you have better methods or suggestions, please leave a message and comment to me.

Environment to prepare

1. Modify the software source

Speed up the installation of software packages and prevent some tools from not being installed.

$ mv /etc/apt/sources.list /etc/apt/sources.list.bak
$ sudo vim /etc/apt/sources.list
# USTC (University of Science and Technology of Thina)deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/  xenial-security main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/  xenial-security main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb https://packages.grafana.com/oss/deb stable main# deb-src https://packages.grafana.com/oss/deb stable main
Copy the code

2. Docker installation and configuration

Docker installation:

wget -qO- https://get.docker.com/ | sh
sudo service docker start
#Run as a non-root user
sudo usermod -aG docker rom
Copy the code

Mirror acceleration:

$ vim /etc/docker/daemon.json
{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}
Copy the code

Modify the storage location of containers and images:

$ sudo vim /etc/systemd/system/multi-user.target.wants/docker.service
#Modify the following line, --graph specifies the directory
ExecStart=/usr/bin/dockerd --graph=/opt/docker -H fd:// --containerd=/run/containerd/containerd.sock

$ sudo service docker restart
$ docker info
Copy the code

Create a container based on an image:

#Installing lamp Images
$docker pull linode/lamp
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
linode/lamp         latest              2359fa12fded        4 years ago         372MB
#Rename the LAMP mirror to Romer
docker tag 2359fa12fded romer
#Create a container and name it romer
mkdir /opt/www
touch /opt/www/apache2.conf
touch /opt/www/my.cnf
docker run --name romer -p 80:80 -p 3306:3306 -it linode/lamp /bin/bash
Copy the code

Description of Linode/LAMP mirroring

www.linode.com/docs/applic…

Linode /lamp is an image based on Ubuntu14, so if you don’t need linode/lamp, you can go to Docker’s mirror repository to find another image.

ROM compilation environment installation

The last name performed above creates a container for the Linode /lamp image and logs in to that Docker container. You can run the following command to view the container and log in.

#View all containers
$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a166e056b85b linode/lamp "/bin/bash" About a minute ago Exited (0)  5 seconds ago roman#Start the container
docker start a166e056b85b
#Into the container
docker exec -it a166e056b85b /bin/bash 
Copy the code

Install the ROM compilation environment

Android various versions of Linux tools rely on more, here I wrote a script to implement the installation, there may be a few tools are missing, need to be in the actual compilation ROM to add to the installation.

#! /bin/bash
failed_infos=()
log_error() {
    failed_infos[${#failed_infos[@]}]=$1
    echo $2
}

# install tools for rom buildingbuild_utils="libstdc++6 git flex bison gperf build-essential libx11-dev:i386 \ libreadline6-dev:i386 libgl1-mesa-dev Tofrodos python-markdown g++-multilib \ libxml2-utils xsltproc DPKG -dev libsdl1.2-dev libesd0-dev git-core gnupg flex \ bison gperf build-essential zip curl zlib1g-dev gcc-multilib libc6-dev-i386 \ lib32z-dev lib32ncurses5-dev x11proto-core-dev libx11-dev libgl1-mesa-dev \ libxml2-utils xsltproc unzip m4 bc lzop libesd0-dev squashfs-tools build-essential \ zip curl libncurses5-dev pngcrush schedtool libxml2 libxml2-utils \ gcc-multilib libswitch-perl Libssl1.0.0 libssl-dev git gnupg flex bison gperf \ build-essential zip curl libc6-dev x11proto-core-dev \ libgl1-mesa-dev g++-multilib tofrodos python-markdown libxml2-utils xsltproc \ mingw32 lib32readline-gplv2-dev Libwxgtk2.8 -dev zlib1g-dev:i386" IFS=" "build_utils_arr=($build_utils) for util in "${build_utils_arr[@]}" do echo "install $util >>>" sudo apt-get install -y $util || log_error $util "install $util failed!" done echo "${#failed_infos[*]} utils install failed. " echo ${failed_infos[*]}Copy the code

There are also some Java environments, please install yourself. (JDK6, JDK7, JDK8, OpenJDK7, OpenJDK8z are all used)

Packaging containers

Save changes:

$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ef6648391c18 linode/lamp "/bin/bash" 22 hours ago Up 4 minutes 0.0.0.0:80 - > 80 / TCP, 0.0.0.0:3306 - > 3306 / TCP romer#Create romer image with tag v1
$ docker commit -a "xxx" -m "install build utils" ef6648391c18 romer:v1
$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE Romer V1 52055c310a81 2 minutes ago 2.26GB Linode /lamp latest 2359fa12fded 4 years ago 372MB
#Generate a new container. Called romerv2
#docker run --name romerv2 -p 80:80 -p 3306:3306 -v /opt/roman:/android/Release -v /opt/workspace:/workspace -it romer:v1  /bin/bashDocker run - name romerv1.1 -p 80:80-3306: p. 3306 - p, 8080:8080-4000: p 4000 - v/opt/Roman: / android/Release - it Romer, v1.1 / bin/bashCopy the code

Once you’ve installed all the tools you need, it’s a good idea to pack the container away for easy backup and recovery.

# docker export: Exports the container file system as a tar archive to STDOUT
#-o: writes the input content to the file.
$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d047c7ac6534 phusion/baseimage "/bin/bash" 2 minutes ago Exited (0) About a minute ago test ef6648391c18 linode/lamp "/bin/bash" 21 hours ago Up 21 hours 0.0.0.0:80->80/ TCP, 0.0.0.0:3306 - > 3306 / TCP Roman$ docker export -o romer.tar ef6648391c18

#Docker import: Creates an image from an archive file.
# docker import romer.tar my_romer:v1 
Copy the code

In addition, we installed some tools (such as Jenkins, Tomcat) and our own software/scripts to work with our custom ROM. You end up with a 4GB image, which is easy to migrate. Since our mirror involves some business things, it is not convenient to share.

ROM compile

Compilation of our ROM is governed by a set of compilation scripts that involve the following processes:

Remote VSCode development

For this part, please refer to my VS Code remote plug-in tutorial or another student’s VS Code remote development tutorial.

Since we used to conduct remote development directly on the cloud host, now we need to move to the Docker container for remote development. In theory, you can log in to Docker container directly through SSH through port mapping. You can try it. I’ll share it with you after I solve the problem.

The appendix

Docker common command:

#View all containers
$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a166e056b85b linode/lamp "/bin/bash" About a minute ago Exited (0)  5 seconds ago roman#Remove the container
$ docker rm a166e056b85b
#Start the container
docker start a166e056b85b
#Stop the container
docker stop a166e056b85b
#Into the container
docker exec -it a166e056b85b /bin/bash  

#Look at mirror
docker images
#Remove the mirror
$ docker rmi $imageId

#File transfer between host and host
docker cp 30026605dcfe:/home/cloudera/RS-MapReduce /tmp/

#Container renamingDocker rename Original container name New container nameCopy the code