Difference between revisions of "Funtoo:Metro"

From Funtoo
Jump to navigation Jump to search
m (Update ego upstream location)
(36 intermediate revisions by one other user not shown)
Line 3: Line 3:
|name=Metro
|name=Metro
|authors=[[User:Drobbins|Daniel Robbins]]
|authors=[[User:Drobbins|Daniel Robbins]]
|description=Metro is the build system for Funtoo Linux and [[Gentoo Linux]] stages. It automates the bootstrapping process.}}
|description=Metro is the Funtoo Linux automated build system, and is used to build Funtoo Linux stage tarballs.
{{Subpages|AutoSetup,Data Model,Recipes}}
|source=[https://github.com/funtoo/metro GitHub]}}
{{Subpages|AutoSetup,Manual Setup,Concepts and Terminology,Configuring Metro,Recipes,Automation,Data Model}}
<translate>
<translate>
<!--T:1-->
<!--T:1-->
= Preface =  
== Introduction ==


{{Note|If you are unfamiliar with how metro works it is recommended that you continue reading this section so you can become familiar with it. If you are already familiar with it, you may wish to use the new [[Metro AutoSetup|autosetup]] script which uses a curses based menu and allows for quickly setting up and running builds base on your choices without requiring any manual steps. Please see the [[Metro AutoSetup]] page for more details}}
Metro is the tool used by Funtoo Linux to build new releases of Funtoo Linux. It is also available to the public and can be used to build custom versions of Funtoo Linux, or used by developers to perform build testing. This page documents how to install, configure and use Metro. Also note that there is various additional supplemental documentation available on sub-pages, with links above.


== How Metro Works == <!--T:5-->
== Installation ==
=== Prerequisites ===


<!--T:6-->
<!--T:22-->
Metro is the Funtoo Linux automated build system, and is used to build Funtoo Linux stage tarballs.
Ensure that {{Package|dev-vcs/git}}, {{Package|dev-python/requests}}, {{Package|dev-python/sqlalchemy}} and {{Package|dev-python/lxml}} are installed on your system.


<!--T:7-->
<!--T:23-->
Metro cannot create a stage tarball out of thin air. To build a new stage tarball, Metro must use an existing, older stage tarball called a "seed" stage. This seed stage typically is used as the ''build environment'' for creating the stage we want.
{{console|body=
# ##i##emerge dev-vcs/git dev-python/requests dev-python/sqlalchemy dev-python/lxml
}}


<!--T:8-->
=== Prerequisites for QEMU Support ===
Metro can use two kinds of seed stages. Traditionally, Metro has used a stage3 as a seed stage. This stage3 is then used to build a new stage1, which in turn is used to build a new stage2, and then a new stage3. This is generally the most reliable way to build [[Gentoo Linux]] or Funtoo Linux, so it's the recommended approach.


== Seeds and Build Isolation == <!--T:9-->
Metro now supports building arm-32bit and arm-64bit stages on x86-64bit systems, using qemu. To enable this functionality, it is
necessary to emerge {{Package|app-emulation/qemu}} with the following settings.


<!--T:10-->
First, add the following to{{f|/etc/portage/package.use}}:
Another important concept to mention here is something called ''build isolation''. Because Metro creates an isolated build environment, and the build environment is explicitly defined using existing, tangible entities -- a seed stage and a portage snapshot -- you will get consistent, repeatable results. In other words, the same seed stage, portage snapshot and build instructions will generate an essentially identical result, even if you perform the build a month later on someone else's workstation.


== Local Build == <!--T:11-->
{{file|name=/etc/portage/package.use|body=
app-emulation/qemu static-user
dev-libs/glib static-libs
sys-apps/attr static-libs
sys-libs/zlib static-libs
dev-libs/libpcre static-libs
}}


<!--T:12-->
Next, the following should be added to {{f|/etc/make.conf}}:
Say you wanted to build a new <tt>pentium4</tt> stage3 tarball. The recommended method of doing this would be to grab an existing <tt>pentium4</tt> stage3 tarball to use as your seed stage. Metro will be told to use this existing <tt>pentium4</tt> stage3 to build a new stage1 for the same <tt>pentium4</tt>. For this process, the generic <tt>pentium4</tt> stage3 would provide the ''build environment'' for creating our new stage1. Then, the new stage1 would serve as the build environment for creating the new <tt>pentium4</tt> stage2. And the new <tt>pentium4</tt> stage2 would serve as the build environment for creating the new <tt>pentium4</tt> stage3.


<!--T:13-->
{{file|name=/etc/make.conf|body=
In the Metro terminology this is called a '''local build''', which means a stage3 of a given architecture is used to seed a brand new build of the same architecture. Incidentally this will be the first exercise we are going to perform in this tutorial.
QEMU_USER_TARGETS="aarch64 arm"
 
}}
<!--T:14-->
A week later, you may want to build a brand new <tt>pentium4</tt> stage3 tarball. Rather than starting from the original <tt>pentium4</tt> stage3 again, you'd probably configure Metro to use the most-recently-built <tt>pentium4</tt> stage3 as the seed. Metro has built-in functionality to make this easy, allowing it to easily find and track the most recent stage3 seed available.
 
== Remote Build == <!--T:15-->
 
<!--T:16-->
Metro can also perform '''remote build''', where a stage3 of a different, but binary compatible, architecture is used as a seed to build a different architecture stage3. Consequentiality the second exercise we are going to perform in this tutorial will be to build a <tt>core2 32bit</tt> stage3 tarball from the <tt>pentium4</tt> stage3 tarball we have just built.
 
<!--T:17-->
TODO: add caveats about what archs can be seeded and what can be not (maybe a table?)
 
== Tailored Build == <!--T:18-->
 
<!--T:19-->
Last, it's also worthy noting that both in <tt>local</tt> and <tt>remote builds</tt>, Metro can be configured to add and/or remove individual packages to the final tarball.
Let's say you can't live without <tt>app-misc/screen</tt>, at the end of this tutorial, we will show how to have your tailored stage3 to include it.
 
== Installing Metro == <!--T:20-->
 
<!--T:21-->
'''The recommended and supported method''' is to use the Git repository of Metro. 


<!--T:22-->
Then, emerge qemu:
Ensure that {{Package|dev-vcs/git}}, {{Package|dev-python/requests}} and {{Package|dev-python/boto}} (optional; required for EC2 support) are installed on your system.


<!--T:23-->
{{console|body=
{{console|body=
# ##i##emerge dev-vcs/git dev-python/requests dev-python/boto
# ##i##emerge app-emulation/qemu
}}
}}


From this point forward, support for ARM on x86 systems should work transparently. Metro will take care of compiling a wrapper for qemu and temporarily installing the static version of qemu inside the stage chroot so that ARM binaries will run transparently on x86 systems. Metro will also automatically register qemu as a "binary format" with the kernel.
=== Cloning Metro ===
<!--T:24-->
<!--T:24-->
Next, clone the master git repository as follows:
'''The recommended and supported method for installing metro''' is to clone metro's git repository to {{f|/root}}. Clone the master git repository as follows:


<!--T:25-->
<!--T:25-->
{{console|body=
{{console|body=
# ##i##cd /root
# ##i##cd /root
# ##i##git clone git://github.com/funtoo/metro.git
# ##i##git clone https://code.funtoo.org/bitbucket/scm/core/metro.git
# ##i##cp /root/metro/metro.conf ~/.metro
# ##i##cp /root/metro/metro.conf ~/.metro
}}
}}


<!--T:26-->
{{Tip|The {{f|/root/.metro}} file contains the system metro configuration, and defines where the build repository and other files should be stored. Defaults are typically fine for most users, and {{f|/home/mirror/funtoo}} will be used as the build repository path. For more information on configuration settings available, see [[Metro/Configuring Metro]].}}
 
You will now have a directory called {{c|/root/metro}} that contains all the Metro source code.
You will now have a directory called {{c|/root/metro}} that contains all the Metro source code.


<!--T:27-->
=== Setting up ego===
=== Setting up ego===
Now, we will set the {{c|ego}}, administration tool of Funtoo/Linux. The way it is used with metro is independent from {{c|app-admin/ego}} installed on your box. Setup is easy as follows:
Now, we will set the {{c|ego}}, administration tool of Funtoo Linux. The way it is used with metro is independent from {{c|app-admin/ego}} installed on your box. This local cloned copy of ego allows metro to potentially use a newer version of ego than what is already installed on your system, or to function under other non-Funtoo distributions like Gentoo or Ubuntu. Set up as follows:
{{console|body=
{{console|body=
# ##i##cd /root
# ##i##cd /root
# ##i##git clone https://github.com/funtoo/ego.git
# ##i##git clone https://code.funtoo.org/bitbucket/scm/core/ego.git
}}
}}
This way you will have {{c|/root/ego}} directory with {{c|ego}} binary that is then used by metro.
This way you will have {{c|/root/ego}} directory with {{c|ego}} binary that is then used by metro.


<!--T:28-->
== Build Repository Setup ==
Metro is now installed.  It's time to customize it for your local system.
 
= Configuring Metro = <!--T:28-->
 
<!--T:29-->
{{Note|Metro is not currently able to build Gentoo stages. See {{Bug|FL-901}}.}}
 
<!--T:30-->
[[User:Drobbins|Daniel Robbins]] maintains Metro, so it comes pre-configured to successfully build Funtoo Linux releases. Before reading further, you might want to customize some basic settings like the number of concurrent jobs to fit your hardware's capabilities or the directory to use for produced stage archives. This is accomplished by editing {{c|~/.metro}} which is the Metro's master configuration file.
 
<!--T:31-->
Please note that {{c|path/install}} must point to where metro was installed. Point {{c|path/distfiles}} to where your distfiles reside. Also set {{c|path/mirror/owner}} and {{c|path/mirror/group}} to the owner and group of all the files that will be written to the build repository directory, which by default (as per the configuration file) is at {{c|/home/mirror/funtoo}}. The cache directory normally resides inside the temp directory -- this can be modified as desired. The cache directory can end up holding many cached .tbz2 packages, and eat up a lot of storage. You may want to place the temp directory on faster storage, for faster compile times, and place the cache directory on slower, but more plentiful storage.
 
<!--T:32-->
{{file|name=.metro|desc=Metro configuration|body=
# Main metro configuration file - these settings need to be tailored to your install:


<!--T:33-->
Metro uses a repository to store built stages and snapshots, which typically resides at {{f|/home/mirror/funtoo}}. There are two methods to set up your build repository -- it can be done [[Metro/Manual Setup|manually]] or [[Metro/AutoSetup|with our auto-setup script.]] The auto-setup script is of course faster and easier, while the manual method may give you a deeper understanding of how the build repository internals work.
[section path]
install: /root/metro
tmp: /var/tmp/metro
cache: $[path/tmp]/cache
distfiles: /var/src/distfiles
work: $[path/tmp]/work/$[target/build]/$[target/name]


<!--T:34-->
== First Build ==
[section path/mirror]


<!--T:35-->
Once your build repository has been set up, you can start your first build using a command similar to the one below:
: /home/mirror/funtoo
owner: root
group: repomgr
dirmode: 775


<!--T:36-->
[section portage]
<!--T:37-->
MAKEOPTS: auto
<!--T:38-->
[section emerge]
<!--T:39-->
options: --jobs=4 --load-average=4 --keep-going=n
<!--T:40-->
# This line should not be modified:
[collect $[path/install]/etc/master.conf]
}}
== Arch and Subarch == <!--T:41-->
<!--T:42-->
In the following example we are creating a pentium4 stage 3 compiled for x86-32bit binary compatibility. Pentium4 is a subarch of the x86-32bit architecture. Once you have metro installed you may find a full list of each subarch in your {{f|/var/git/meta-repo/kits/core-kit/profiles/funtoo-1.0/linux-gnu/arch/x86-32bit/subarch}} directory:
Example:
{{console|body=
{{console|body=
# ##i##ls /var/git/meta-repo/kits/core-kit/profiles/funtoo/1.0/linux-gnu/arch/x86-32bit/subarch/
# ##i##/root/metro/scripts/ezbuild.sh 1.3-release-std x86-64bit amd64-zen full
amd64-k8+sse3_32  athlon-4      athlon-xp  core2_32    i486  k6-2      pentium      pentium2  pentiumpro
amd64-k8_32      athlon-mp    atom_32    generic_32  i686  k6-3      pentium-m    pentium3  prescott
athlon            athlon-tbird  btver1    geode      k6    native_32  pentium-mmx  pentium4  xen-pentium4+sse3
}}
 
64-bit PC profiles can be found in the {{f|/var/git/meta-repo/kits/core-kit/profiles/funtoo/1.0/linux-gnu/arch/x86-64bit/subarch/}} directory:
{{console|body=
# ##i##ls /var/git/meta-repo/kits/core-kit/profiles/funtoo/1.0/linux-gnu/arch/x86-64bit/subarch/
amd64-bulldozer  amd64-k8+sse3      btver1_64  generic_64        intel64-nehalem      native_64
amd64-jaguar    amd64-piledriver  core-avx-i  intel64-broadwell  intel64-sandybridge  nocona
amd64-k10        amd64-steamroller  core2_64    intel64-haswell    intel64-silvermont  opteron_64
amd64-k8        atom_64            corei7      intel64-ivybridge  intel64-westmere    xen-pentium4+sse3_64
}}
 
= First stages build (local build) = <!--T:43-->
 
<!--T:44-->
To get this all started, we need to bootstrap the process by downloading an initial seed stage3 to use for building and place it in its proper location in {{f|/home/mirror/funtoo}}, so that Metro can find it. We will also need to create some special &quot;control&quot; files in {{f|/home/mirror/funtoo}}, which will allow Metro to understand how it is supposed to proceed.
 
== Step 1: Set up pentium4 repository (local build) == <!--T:45-->
 
<!--T:46-->
Assuming we're following the basic steps outlined in the previous section, and building {{f|funtoo-current}} build for the {{f|pentium4}}, using a generic {{f|pentium4}} stage3 as a seed stage, then here the first set of steps we'd perform:
 
<!--T:47-->
{{console|body=
# ##i##install -d /home/mirror/funtoo/funtoo-current/x86-32bit/pentium4
# ##i##install -d /home/mirror/funtoo/funtoo-current/snapshots
# ##i##cd /home/mirror/funtoo/funtoo-current/x86-32bit/pentium4
# ##i##install -d 2017-10-01
# ##i##cd 2017-10-01
# ##i##wget -c https://build.funtoo.org/funtoo-current/x86-32bit/pentium4/2017-10-01/stage3-pentium4-funtoo-current-2017-10-01.tar.xz
# ##i##cd ..
# ##i##install -d .control/version
# ##i##echo "2017-10-01" > .control/version/stage3
# ##i##install -d .control/strategy
# ##i##echo local >  .control/strategy/build
# ##i##echo stage3 > .control/strategy/seed
}}
 
<!--T:48-->
OK, let's review the steps above. First, we create the directory {{f|/home/mirror/funtoo/funtoo-current/x86-32bit/pentium4}}, which is where Metro will expect to find {{f|funtoo-current}} pentium4 builds -- it is configured to look here by default. Then we create a specially-named directory to house our seed x86 stage3. Again, by default, Metro expects the directory to be named this way. We enter this directory, and download our seed x86 stage3 from funtoo.org. Note that the {{f|2017-10-01}} version stamp matches. Make sure that your directory name matches the stage3 name too. Everything has been set up to match Metro's default filesystem layout.
 
<!--T:49-->
Next, we go back to the {{f|/home/mirror/metro/funtoo-current/x86-32bit/pentium4}} directory, and inside it, we create a {{f|.control}} directory. This directory and its subdirectories contain special files that Metro references to determine certain aspects of its behavior. The {{f|.control/version/stage3}} file is used by Metro to track the most recently-built stage3 for this particular build and subarch. Metro will automatically update this file with a new version stamp after it successfully builds a new stage3. But because Metro didn't actually ''build'' this stage3, we need to set up the {{f|.control/version/stage3}} file manually. This will allow Metro to find our downloaded stage3 when we set up our pentium4 build to use it as a seed. Also note that Metro will create a similar {{f|.control/version/stage1}} file after it successfully builds an pentium4 funtoo-current stage1.
 
<!--T:50-->
We also set up {{f|.control/strategy/build}} and {{f|.control/strategy/seed}} files with values of {{f|local}} and {{f|stage3}} respectively. These files define the building strategy Metro will use when we build pentium4 funtoo-current stages. With a build strategy of {{f|local}}, Metro will source its seed stage from funtoo-current pentium4, the current directory. And with a seed strategy of {{f|stage3}}, Metro will use a stage3 as a seed, and use this seed to build a new stage1, stage2 and stage3.
 
== Step 2: Building the pentium4 stages == <!--T:51-->
 
<!--T:52-->
Incidentally, if all you wanted to do at this point was to build a new pentium4 funtoo-current stage1/2/3 (plus openvz and vserver templates). You would begin the process by typing:
 
<!--T:53-->
{{console|body=
# ##i##cd /root/metro
# ##i##scripts/ezbuild.sh funtoo-current x86-32bit pentium4
}}
 
<!--T:54-->
If you have a slow machine, it could take several hours to be completed because several "heavy" components like gcc or glibc have to be recompiled in each stage. Once a stage has been successfully completed, it is placed in the {{f|"${METRO_MIRROR}/funtoo-current/x32-bit/pentium4/YYYY-MM-DD"}} subdirectory, where {{f|YYYY-MM-DD}} is today's date at the time the {{f|ezbuild.sh}} script was started or the date you put on the ezscript.sh command line.
 
= Building for another binary compatible architecture (remote build) = <!--T:55-->
 
<!--T:56-->
As written above, Metro is able to perform '''remote build''' building different architecture stage3 from a binary compatible seeding stage3 (e.g. using a pentium4 stage3 to seed a <tt>Intel Core2 32bits</tt> stage3).
 
<!--T:57-->
In the Metro terminology this is called a '''remote build''' (a stage 3 of a different, but binary compatible, architecture is used as a seed).
What's not compatible? You can't use a <tt>Sparc</tt> architecture to generate an <tt>x86</tt> or <tt>ARM</tt> based stage and vice-versa. If you use a 32bit stage then you don't want to seed a 64bit build from it. Be sure that you are using a stage from the same architecture that you are trying to seed. Check [http://ftp.osuosl.org/pub/funtoo/funtoo-current/ Funtoo-current FTP Mirror] for a stage that is from the same Architecture that you will be building. 
 
<!--T:58-->
{{Note|Often, one build (ie. funtoo-current) can be used as a seed for another build such as funtoo-stable. However, hardened builds require hardened stages as seeds in order for the build to complete successfully.}}
 
== Step 1: Set up Core_2 32bit repository == <!--T:59-->
 
<!--T:60-->
In this example, we're going to use this pentium4 funtoo-current stage3 to seed a new Core_2 32bit funtoo-current build. To get that done, we need to set up the pentium4 build directory as follows:
 
<!--T:61-->
{{console|body=
# ##i## cd /home/mirror/funtoo/funtoo-current/x86-32bit
# ##i##install -d core2_32
# ##i##cd core2_32
# ##i##install -d .control/strategy
# ##i##echo remote > .control/strategy/build
# ##i##echo stage3 > .control/strategy/seed
# ##i##install -d .control/remote
# ##i##echo funtoo-current > .control/remote/build
# ##i##echo x86-32bit > .control/remote/arch_desc
# ##i##echo pentium4 > .control/remote/subarch
}}
 
<!--T:62-->
The steps we follow are similar to those we performed for a ''local build'' to set up our pentium4 directory for local build. However, note the differences. We didn't download a stage, because we are going to use the pentium4 stage to build a new Core_2 32bit stage. We also didn't create the <tt>.control/version/stage{1,3}</tt> files because Metro will create them for us after it successfully builds a new stage1 and stage3. We are still using a <tt>stage3</tt> seed strategy, but we've set the build strategy to <tt>remote</tt>, which means that we're going to use a seed stage that's not from this particular subdirectory. Where are we going to get it from? The <tt>.control/remote</tt> directory contains this information, and lets Metro know that it should look for its seed stage3 in the <tt>/home/mirror/funtoo/funtoo-current/x86-32bit/pentium4</tt> directory. Which one will it grab? You guessed it -- the most recently built ''stage3'' (since our seed strategy was set to <tt>stage3</tt>) that has the version stamp of <tt>2010-12-24</tt>, as recorded in <tt>/home/mirror/funtoo-current/x86-32bit/pentium4/.control/version/stage</tt>. Now you can see how all those control files come together to direct Metro to do the right thing.
 
<!--T:63-->
{{Note|<code>arch_desc</code> should be set to one of: <code>x86-32bit</code>, <code>x86-64bit</code> or <code>pure64</code> for PC-compatible systems. You must use a 32-bit build as a seed for other 32-bit builds, and a 64-bit build as a seed for other 64-bit builds.}}
 
== Step 2: Building the Core_2 32bit stages == <!--T:64-->
 
<!--T:65-->
Now, you could start building your new Core_2 32bit stage1/2/3 (plus openvz and vserver templates) by typing the following:
 
<!--T:66-->
{{console|body=
# ##i##/root/metro/scripts/ezbuild.sh funtoo-current x86-32bit core2_32
}}
 
<!--T:67-->
In that case, the produced stages are placed in the <tt>/home/mirror/funtoo/funtoo-current/x32-bit/core2_32/YYYY-MM-DD</tt> subdirectory.
 
== Step 3: The Next Build == <!--T:68-->
 
<!--T:69-->
At this point, you now have a new Core_2 32bit stage3, built using a "remote" pentium4 stage3. Once the first remote build completes successfully, metro will automatically change {{c|.control/strategy/build}} to be {{c|local}} instead of {{c|remote}}, so it will use the most recently-built Core_2 32bit stage3 as a seed for any new Core_2 32bit builds from now on.
 
= Build your own tailored stage3 = <!--T:70-->
 
<!--T:71-->
Metro can be easily configured for building custom stage3 by including additional packages. You can find following directory {{c|/etc/builds/packages}} in your copy of metro repository and a corresponding {{c|arch}} configuration files inside:
{{file|name=/etc/builds/packages/x86-64bit.conf|body=
[section emerge]
 
packages: [
sys-kernel/debian-sources
]
}}
Notice a {{c|debian-sources}} ebuild is added for all 64-bit stages. Modify the file to include (or exclude in case Funtoo add additional) packages of your choice. They will be included in your custom stage3 portage's world file.
 
= Building Gentoo stages = <!--T:98-->
 
<!--T:99-->
Metro can also build Gentoo stages.  After switching to Funtoo profile, see http://www.funtoo.org/Funtoo_Profiles metro require additional steps for this. We have an open bug for this -- it is simply due to the fact that we focus on ensuring Funtoo Linux builds and building Gentoo is a lower priority. Historical note: Funtoo Linux originally started as a fork of Gentoo Linux so that metro could reliably build Gentoo stages.
http://www.funtoo.org/Funtoo_Profiles
 
= Advanced Features = <!--T:100-->
 
<!--T:101-->
Metro also includes a number of advanced features that can be used to automate builds and set up distributed build servers. These features require you to {{c|emerge sqlalchemy}}, as SQLite is used as a dependency and also {{c|emerge dev-python/lxml}} as this is needed for index file generation.
 
== Repository Management == <!--T:102-->
 
<!--T:103-->
Metro includes a script in the {{c|scripts}} directory called {{c|buildrepo}}. Buildrepo serves as the heart of Metro's advanced repository management features.
 
=== Initial Setup === <!--T:104-->
 
<!--T:105-->
To use {{c|buildrepo}}, you will first need to create a {{f|.buildbot}} configuration file. Here is the file I use on my AMD Jaguar build server:
 
<!--T:106-->
{{file|name=/root/.buildbot|lang=python|body=
builds = (
"funtoo-current",
"funtoo-current-hardened",
)
 
<!--T:107-->
arches = (
"x86-64bit",
"pure64"
)
 
<!--T:108-->
subarches = (
"amd64-jaguar",
"amd64-jaguar-pure64",
)
 
<!--T:109-->
def map_build(build, subarch, full, full_date):
# arguments refer to last build...
if full == True:
buildtype =  ( "freshen", )
else:
buildtype =  ("full", )
        # return value can be a string like "full+openvz" or a sequence type like [ "freshen", "openvz" ]
return buildtype
}}
 
<!--T:110-->
This file is actually a python source file that defines the tuples {{c|builds}}, {{c|arches}} and {{c|subarches}}. These variables tell {{c|buildrepo}} which builds, arches and subarches it should manage. A {{c|map_build()}} function is also defined which {{c|buildbot}} uses to determine what kind of build to perform. The arguments passed to the function are based on the last successful build. The function can read these arguments and return a string to define the type of the next build. In the above example, the {{c|map_build()}} function will cause the next build after a freshen build to be a full build, and the next build after a full build to be a freshen build, so that the build will alternate between full and freshen.
 
== Automated Builds == <!--T:111-->
 
<!--T:112-->
Once the {{c|.buildbot}} file has been created, the {{c|buildrepo}} and {{c|buildbot.sh}} tools are ready to use. Here's how they work. These tools are designed to keep your repository ({{c|path/mirror}} in {{f|/root/.metro}} up-to-date by inspecting your repository and looking for stages that are out-of-date.
 
<!--T:113-->
To list the next build that will be performed, do this -- this is from my ARM build server:
 
<!--T:114-->
{{console|body=
# ##i##./buildrepo nextbuild
build=funtoo-current
arch_desc=arm-32bit
subarch=armv7a_hardfp
fulldate=2015-02-08
nextdate=2015-02-20
failcount=0
target=full
extras=''
}}
 
<!--T:115-->
If no output is displayed, then all your builds are up-to-date.
 
<!--T:116-->
To actually run the next build, run {{c|buildbot.sh}}:
 
<!--T:117-->
{{console|body=
# ##i##./buildbot.sh
}}
 
<!--T:118-->
If you're thinking that {{c|buildbot.sh}} would be a good candidate for a cron job, you've got the right idea!
 
=== List Builds === <!--T:119-->
 
<!--T:120-->
To get a quick look at our repository, let's run the {{c|buildrepo fails}} command:
 
<!--T:121-->
{{console|body=
# ##i##./buildrepo fails
  0  2015-02-18 /home/mirror/funtoo/funtoo-current/x86-64bit/amd64-jaguar
  0  2015-02-18 /home/mirror/funtoo/funtoo-current/pure64/amd64-jaguar-pure64
  0  2015-02-18 /home/mirror/funtoo/funtoo-current-hardened/x86-64bit/amd64-jaguar
  0  2015-02-18 /home/mirror/funtoo/funtoo-current-hardened/pure64/amd64-jaguar-pure64
}}
 
<!--T:122-->
On my AMD Jaguar build server, on Feb 20, 2015, this lists all the builds that {{c|buildrepo}} has been configured to manage. The first number on each line is a '''failcount''', which is the number of consecutive times that the build has failed. A zero value indicates that everything's okay. The failcount is an important feature of the advanced repository management features. Here are a number of behaviors that are implemented based on failcount:
 
<!--T:123-->
* If {{c|buildbot.sh}} tries to build a stage and the build fails, the failcount is incremented.
* If the build succeeds for a particular build, the failcount is reset to zero.
* Builds with the lowest failcount are prioritized by {{buildrepo}} to build next, to steer towards builds that are more likely to complete successfully.
* Once the failcount reaches 3 for a particular build, it is removed from the build rotation.
 
=== Resetting Failcount === <!--T:124-->
 
<!--T:125-->
If a build has issues, the failcount for a build will reach 3, at which point it will be pulled out of build rotation. To clear failcount, so that these builds are attempted again -- possibly fixed by new updates to the Portage tree -- use {{c|buildrepo zap}}:
 
<!--T:126-->
{{console|body=
# /root/metro/scripts/buildrepo zap
Removing /mnt/data/funtoo/funtoo-current/arm-32bit/armv7a_hardfp/.control/.failcount...
Removing /mnt/data/funtoo/funtoo-current/arm-32bit/armv6j_hardfp/.control/.failcount...
Removing /mnt/data/funtoo/funtoo-current/arm-32bit/armv5te/.control/.failcount...
}}
 
== Repository Maintenance == <!--T:127-->
 
<!--T:128-->
A couple of repository maintenance tools are provided:
 
<!--T:129-->
* {{c|buildrepo digestgen}} will generate hash files for the archives in your repository, and clean up stale hashes.
* {{c|buildrepo index.xml}} will create an index.xml file at the root of your repository, listing all builds available.
* {{c|buildrepo clean}} will output a shell script that will remove old stages. No more than the three most recent stage builds for each build/arch/subarch are kept.
 
== Distributed Repositories == <!--T:130-->
 
<!--T:131-->
In many situation, you will have a number of build servers, and each will build a subset of your master repository, and then upload builds to the master repository. This is an area of Metro that is being actively developed. For now, automated upload functionality is not enabled, but is expected to be implemented in the relatively near future. However, it is possible to have your master repository differentiate between subarches that are built locally, and thus should be part of that system's {{c|buildbot}} build rotation, and those that are stored locally and built remotely. These builds should be cleaned when {{c|buildrepo clean}} is run, but should not enter the local build rotation. To set this up, modify {{f|/root/.buildbot}} and use the {{c|subarches}} and {{c|all_subarches}} variables:
 
<!--T:132-->
{{file|name=/root/.buildbot|desc=Excerpt of .buildbot config for master repository|body=
# subarches we are building locally:
 
<!--T:133-->
subarches = (
        "pentium4",
        "athlon-xp",
        "corei7",
        "corei7-pure64",
        "generic_32",
        "i686",
        "amd64-k8",
        "amd64-k8-pure64",
        "core2_64",
        "core2_64-pure64",
        "generic_64",
        "generic_64-pure64",
)
 
# Things we need to clean, even if we may not be building:
 
all_subarches = subarches + (
        "atom_32",
        "atom_64",
        "atom_64-pure64",
        "amd64-k10",
        "amd64-k10-pure64",
        "amd64-bulldozer",
        "amd64-bulldozer-pure64",
        "amd64-steamroller",
        "amd64-steamroller-pure64",
        "amd64-piledriver",
        "amd64-piledriver-pure64",
        "amd64-jaguar",
        "amd64-jaguar-pure64",
        "intel64-haswell",
        "intel64-haswell-pure64",
        "intel64-ivybridge-pure64",
        "intel64-ivybridge",
        "armv7a_hardfp",
        "armv6j_hardfp",
        "armv5te"
)
}}
== Using binary cache ==
Metro has built-in feature which allows to use binary packages cache rather then building same list of packages from sources. For example, core packages, such as @system are updated at slower pace and it makes sense to enable binary cache to make stage building blazing fast. However, the real disadvantage with using binary cache could be a core package update that due to internal ABI changes require rebuilding of numerous packages from sources. Good example is {{c|sys-libs/ncurses-5}} to {{c|sys-libs/ncurses-6}} major update. This is the case when you would need to disable binary cache and use regular ebuild installation from sources.  To enable binary cache, in your metro git repository copy, edit the {{c|common.conf}}
{{file|name=/etc/builds/common.conf|desc=Excerpt of default common.conf|body=
[section metro]
 
options:
options/stage:
target: gentoo
}}
and set {{c|cache/package}}
{{file|name=/etc/builds/common.conf|desc=Excerpt of common.conf with binary cache enabled|body=
[section metro]
 
options:
options/stage: cache/package
target: gentoo
}}
}}


During stage build metro will save package cache in {{c|/var/tmp/metro/cache/package-cache}}. With any next builds this binary package  cache will be used.
<!--T:134-->
[[Category:HOWTO]]
[[Category:HOWTO]]
[[Category:Metro]]
[[Category:Metro]]

Revision as of 17:19, May 8, 2019

Other languages:
English • ‎Türkçe • ‎português do Brasil • ‎日本語
Description:
Metro is the Funtoo Linux automated build system, and is used to build Funtoo Linux stage tarballs.
Source Code:

Introduction

Metro is the tool used by Funtoo Linux to build new releases of Funtoo Linux. It is also available to the public and can be used to build custom versions of Funtoo Linux, or used by developers to perform build testing. This page documents how to install, configure and use Metro. Also note that there is various additional supplemental documentation available on sub-pages, with links above.

Installation

Prerequisites

Ensure that dev-vcs/git, No results, No results and No results are installed on your system.

root # emerge dev-vcs/git dev-python/requests dev-python/sqlalchemy dev-python/lxml

Prerequisites for QEMU Support

Metro now supports building arm-32bit and arm-64bit stages on x86-64bit systems, using qemu. To enable this functionality, it is necessary to emerge No results with the following settings.

First, add the following to/etc/portage/package.use:

   /etc/portage/package.use
app-emulation/qemu static-user
dev-libs/glib static-libs
sys-apps/attr static-libs
sys-libs/zlib static-libs
dev-libs/libpcre static-libs

Next, the following should be added to /etc/make.conf:

   /etc/make.conf
QEMU_USER_TARGETS="aarch64 arm"

Then, emerge qemu:

root # emerge app-emulation/qemu

From this point forward, support for ARM on x86 systems should work transparently. Metro will take care of compiling a wrapper for qemu and temporarily installing the static version of qemu inside the stage chroot so that ARM binaries will run transparently on x86 systems. Metro will also automatically register qemu as a "binary format" with the kernel.

Cloning Metro

The recommended and supported method for installing metro is to clone metro's git repository to /root. Clone the master git repository as follows:

root # cd /root
root # git clone https://code.funtoo.org/bitbucket/scm/core/metro.git
root # cp /root/metro/metro.conf ~/.metro
   Tip

The /root/.metro file contains the system metro configuration, and defines where the build repository and other files should be stored. Defaults are typically fine for most users, and /home/mirror/funtoo will be used as the build repository path. For more information on configuration settings available, see Metro/Configuring Metro.

You will now have a directory called /root/metro that contains all the Metro source code.

Setting up ego

Now, we will set the ego, administration tool of Funtoo Linux. The way it is used with metro is independent from app-admin/ego installed on your box. This local cloned copy of ego allows metro to potentially use a newer version of ego than what is already installed on your system, or to function under other non-Funtoo distributions like Gentoo or Ubuntu. Set up as follows:

root # cd /root
root # git clone https://code.funtoo.org/bitbucket/scm/core/ego.git

This way you will have /root/ego directory with ego binary that is then used by metro.

Build Repository Setup

Metro uses a repository to store built stages and snapshots, which typically resides at /home/mirror/funtoo. There are two methods to set up your build repository -- it can be done manually or with our auto-setup script. The auto-setup script is of course faster and easier, while the manual method may give you a deeper understanding of how the build repository internals work.

First Build

Once your build repository has been set up, you can start your first build using a command similar to the one below:

root # /root/metro/scripts/ezbuild.sh 1.3-release-std x86-64bit amd64-zen full