Millet Porridge

English version of https://corvo.myseu.cn

0%

Docker Series 8: Trick, build old version software

Background

I’m in charging a system with Debian8 + Ruby2.1 + Puppet3.7. We need to migrate to Debian9, It relies on Puppet3.7 so much that we couldn’t change it. We need to build a static linked Ruby+Puppet, and ensure it will run in Debian9 or Debian10

Why Docker?

Why would we bother Docker to build instead of using a Debian8 machine simply?

  1. Unless we get a pure Debian8 host, there are plenty dependicies binding with the system
  2. It seems that Virtual Machine could do this job, but it’s a little overweight.

The official Debian image is pure and easily to start and stop, what’s more, we could use the cached layers.

Dockerfile

Here is the dockerfile to build Ruby and Puppet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
FROM debian:jessie

# upgrade & install required packages
RUN echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib\n \
deb-src http://mirrors.163.com/debian/ jessie main non-free contrib\n \
deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib\n \
deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib" > /etc/apt/sources.list

# Ruby build system
RUN apt-get update && apt-get upgrade && apt-get install -y wget ruby-build

WORKDIR /home

# Download source package
RUN wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz
RUN wget https://downloads.puppetlabs.com/puppet/puppet-3.7.2.tar.gz
RUN tar -zxf ruby-2.1.5.tar.gz
RUN tar -zxf puppet-3.7.2.tar.gz

RUN cd ruby-2.1.5 \
&& ./configure --prefix=/opt/puppet37 --disable-install-doc --disable-install-rdoc --disable-install-capi \
&& make -j8 \
&& make install

# In debian9, there is no library, wo need copy it.
RUN cp /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 /opt/puppet37/lib/
RUN cp /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 /opt/puppet37/lib/

# Must specify the version, newer facter will block the puppet.
RUN /opt/puppet37/bin/gem install hiera -v 1.3.4
RUN /opt/puppet37/bin/gem install facter -v 2.2.0

# Install Puppet
RUN /opt/puppet37/bin/ruby /home/puppet-3.7.2/install.rb --no-rdoc

# make a package
RUN tar -cf puppet37_2_1_5.tar /opt/puppet37
RUN xz -9 puppet37_2_1_5.tar

# 构建
# docker build -t pp37 .
# docker run --rm --entrypoint cat pp37 /home/puppet37_2_1_5.tar.xz > ./puppet37_2_1_5.tar.xz

# 安装
# cp puppet37_2_1_5.tar.xz /tmp
# xz -d /tmp/puppet37_2_1_5.tar.xz
# tar -xf /tmp/puppet37_2_1_5.tar -C /

Conclution

As you can see, we create a building system only by a Dockerfile. It helps a lot to our migration.

We also use this method to build Nginx+Lua and ss5 inside the docker. Hope it could help you.