C, Debian , 码头工人 , linux

Docker容器中的Debian构建环境

最后发表 ,我与共享了一个Docker容器用于C语言福彩双色球开奖结果 缓存 colorgcc 包括。这次,我们将扩展该基础容器,以开发和包装Debian软件包。

考虑到Docker的性质,其捕获的覆盖层及其容量,不仅可以方便地配置和打包环境,而且还为优化提供了一些机会。

最后,它使从另一个发行版(例如Arch Linux)开始开发Debian软件包变得容易。

特征

  • GCC 6
  • Debian软件包开发工具: 林田 , 被子 , 破坏 , dh-make , 假根
  • 被子 配置用于Debian修补
  • 缓存 快速重新福彩双色球开奖结果。包含在debuild和dpkg-buildpackage调用中
  • eatmydata 加快福彩双色球开奖结果时间
  • 仅192 MB的未压缩额外层,整个容器总计435 MB

如果您正在阅读本文,则可能不需要这些工具的说明。否则,请参阅参考资料部分。

如果您想知道这与 建造 福彩双色球开奖结果器 ,这种方法确实非常相似。想法是相同的:在另一个干净且隔离的环境中进行福彩双色球开奖结果。这解决了几个问题:

  • 您可以为其他版本的Debian进行构建,例如 联合国 稳定的 或者 测试 ,而不用这些软件包弄乱您的系统。
  • 您可以确定依赖关系是正确的,因为环境很小。

好吧,Docker容器可以用作 chroot 在类固醇中使用,可以看作是使用cgroup和命名空间等现代内核功能对该概念进行的演变。

另一个好处是:管理Docker容器非常简单。您可以拉动它们,推动它们,将它们导出并保存。

最后,至少对我个人而言,巨大的好处是能够使用Arch之类的其他Linux发行版。

用法

登录开发环境

泊坞窗运行–rm -v “/workdir/path:/src”-ti ownyourbits / debiandev

现在,我们可以使用标准工具,即工作目录( / workdir /路径 在此示例中)是可从容器访问的外部文件夹,您可以在其中执行 适当获取源   and retrieve the .deb files.

示例:针对ARM64交叉福彩双色球开奖结果QEMU

以我的经验,并不是所有软件包都配置得足够好以支持交叉福彩双色球开奖结果。特别是大包装在包装上往往会失败 建立深度   步。我发现这个很好的例外 这个帖子 .

sudo dpkg --add-architecture arm64
sudo apt-get update
sudo apt-get build-dep -aarm64 qemu
apt-get source qemu
cd qemu-*
dpkg-buildpackage -aarm64 -b
示例:打包并调整PHP,并已填充CCACHE缓存

我喜欢将此容器用作每个特定项目的基础。这样,我可以利用Docker的捕获层来加快过程,同时,我最终得到在Dockerfile中福彩双色球开奖结果的构建指令。

如果您决定使用Docker卷,并且要从零开始,则始终可以将其删除。这样的好处是在运行容器时, / src 将使用结果填充并再次从Dockerfile步骤缓存。实时节省!

# PHP Debian build environment with GCC 6 and ccache, and all debian dev tools
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# Usage: 
#
#   docker run --rm  -v "src:/src" -ti ownyourbits/phpdev
#
# Then, inside:
#   cd php7.0-7.0.19
#   debuild -us -uc -b
#
# Note that with this invocation command, the code resides in a persistent volume called 'src'.
# See 'docker volume ls'
#
# It has already been build once with CCACHE, so you can just start tweaking, and recompilation will
# be very fast. If you do 'docker volume rm src', then next time you run the container it will be
# populated again with the fresh build ( but you would lose your code changes ).
#
# A second option is to do ` -v "/path:/src" and use "/path" from your system, but then you have to
# do 'apt-get source' and 'debuild' yourself, because "/path" will be originally empty.
#
# Details at ownyourbits.com


FROM ownyourbits/debiandev:latest

LABEL description="PHP build environment"
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>

## Get source
RUN sudo apt-get update;\
    mkdir -p /src; cd /src; \
    apt-get source -t stretch php7.0-fpm; 

## PHP build dependencies
RUN sudo apt-get update;\
    DEBIAN_FRONTEND=noninteractive sudo apt-get build-dep -y -t stretch php7.0-fpm; \
    sudo apt-get autoremove -y; sudo apt-get clean; sudo rm /var/lib/apt/lists/*; \
    sudo rm /var/log/alternatives.log /var/log/apt/* ; sudo rm /var/log/* -r; sudo rm -rf /usr/share/man/*; 

## Build first
# this will build the package without testing but with the CCACHE options, so we are 
# building and catching compilation artifacts
RUN cd $( find /src -maxdepth 1 -type d | grep php ); \
    CCACHE_DIR=/src/.ccache DEB_BUILD_OPTIONS=nocheck \
    eatmydata debuild \
   --prepend-path=/usr/lib/ccache --preserve-envvar=CCACHE_* --no-lintian -us -uc;


# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA

代码

# Debian build environment with GCC 6, ccache and all debian dev tools
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# Usage: 
#
#   docker run --rm  -v "/ workdir / path:/ src"-ti ownyourbits / debiandev
#
# Details at ownyourbits.com

FROM ownyourbits/mmake:latest

LABEL description="Debian package development environment"
MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com>

# install packages
RUN sudo sh -c "echo deb-src http://httpredir.debian.org/debian stretch main >> /etc/apt/sources.list"; \
    sudo apt-get update;\
    DEBIAN_FRONTEND=noninteractive sudo apt-get install --no-install-recommends -y dpkg-dev devscripts dh-make lintian fakeroot pbuilder quilt eatmydata vim; \
    sudo apt-get autoremove -y; sudo apt-get clean; sudo rm /var/lib/apt/lists/*; \
    sudo rm /var/log/alternatives.log /var/log/apt/*; sudo rm /var/log/* -r;

# configure session
RUN echo "alias debuild='eatmydata debuild --prepend-path=/usr/lib/ccache --preserve-envvar=CCACHE_*'" >> /home/builder/.bashrc; \
    echo "alias dpkg-buildpackage='eatmydata dpkg-buildpackage'"                                       >> /home/builder/.bashrc; \
# NOTE: dpkg-buildpackage and debuild do not play well with colorgcc
    echo 'export PATH="/usr/lib/ccache/:$PATH"'                                                        >> /home/builder/.bashrc; 

COPY _quiltrc /home/builder/.quiltrc

# prepare work dir
RUN sudo mkdir -p /src; sudo chown builder:builder /src; echo 'cd /src' >> /home/builder/.bashrc

# remove previous entrypoint
ENTRYPOINT []

CMD ["/bin/bash"]

# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA

参考

//www.debian.org/doc/manuals/maint-guide/build.en.html

//www.debian.org/doc/debian-policy/ch-source.html

//wiki.debian.org/BuildingTutorial

//wiki.debian.org/CrossCompiling

//wiki.debian.org/Multiarch/HOWTO

作者: nachoparker

谦虚地分享我认为有用的东西 [ 的github dockerhub ]

发表评论

您的电子邮件地址不会被公开。 必需的地方已做标记 *