Skip to content

Commit

Permalink
adding httpd to binary builder
Browse files Browse the repository at this point in the history
[#94536764]

Signed-off-by: Sai To Yeung <[email protected]>
Signed-off-by: Matt Horan <[email protected]>
  • Loading branch information
mhoran committed Jun 1, 2015
1 parent 005c468 commit 6578597
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 10 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ This tool provides a mechanism for building binaries.
When building binaries for CloudFoundry, it may be useful to run `binary-builder` from within a CF rootfs. The cflinuxfs2 rootfs may be used as follows:

```bash
docker run -v /absolute/path/to/binary-builder:/binary-builder -it cloudfoundry/cflinuxfs2 bash
cd /binary-builder
docker run -w /binary-builder -v `pwd`:/binary-builder -it cloudfoundry/cflinuxfs2 bash
./bin/binary-builder [binary_name] [binary_version]
```
1 change: 1 addition & 0 deletions lib/architect/architects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
require_relative 'ruby_architect'
require_relative 'jruby_architect'
require_relative 'python_architect'
require_relative 'httpd_architect'
14 changes: 14 additions & 0 deletions lib/architect/httpd_architect.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module BinaryBuilder
class HttpdArchitect < Architect
HTTPD_TEMPLATE_PATH = File.expand_path('../../../templates/httpd_blueprint', __FILE__)

def blueprint
contents = read_file(HTTPD_TEMPLATE_PATH)
contents
.gsub('$HTTPD_VERSION', binary_version)
.gsub('$APR_UTIL_VERSION', '1.5.4')
.gsub('$APR_ICONV_VERSION', '1.2.1')
.gsub('$APR_VERSION', '1.5.2')
end
end
end
3 changes: 2 additions & 1 deletion lib/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def tar_installed_binary
'node' => NodeArchitect,
'ruby' => RubyArchitect,
'jruby' => JRubyArchitect,
'python' => PythonArchitect
'python' => PythonArchitect,
'httpd' => HttpdArchitect
}

def architect_for_binary(binary)
Expand Down
9 changes: 3 additions & 6 deletions spec/assets/binary-exerciser.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/bin/sh
#!/usr/bin/env bash
set +e

tar_name=$1
exec_path=$2
exec_flag=$3
exec_test=$4
tar_name=$1; shift

mkdir binary-exerciser
cd binary-exerciser

tar xzf /binary-builder/${tar_name}
${exec_path} $exec_flag "${exec_test}"
eval $(printf '%q ' "$@")
19 changes: 19 additions & 0 deletions spec/integration/build_a_binary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,23 @@
FileUtils.rm(binary_tarball_location)
end
end

context 'when httpd is specified', binary: 'httpd' do
let(:binary_name) { 'httpd' }
let(:binary_version) { '2.4.12' }
let(:rootfs) { 'cflinuxfs2' }

it 'builds the specified binary, tars it, and places it in your current working directory' do
binary_tarball_location = File.join(Dir.pwd, 'httpd-2.4.12-linux-x64.tgz')
expect(File.exist?(binary_tarball_location)).to be(true)

docker_exerciser = "docker run -v #{File.expand_path('../../..', __FILE__)}:/binary-builder:ro -e LD_LIBRARY_PATH=/binary-exerciser/httpd/lib cloudfoundry/cflinuxfs2 /binary-builder/spec/assets/binary-exerciser.sh"
exerciser_args = "httpd-2.4.12-linux-x64.tgz ./httpd/bin/httpd -v"

script_output = `#{docker_exerciser} #{exerciser_args}`.chomp
expect($?).to be_success
expect(script_output).to include('2.4.12')
FileUtils.rm(binary_tarball_location)
end
end
end
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ def run_binary_builder(binary_name, binary_version, rootfs, flags = '')
Open3.capture2e("#{boot2docker_shellinit_cmd} && #{docker_run_cmd} '#{binary_builder_cmd}'")[0]
end
end

31 changes: 31 additions & 0 deletions spec/unit/httpd_architect_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'

module BinaryBuilder
describe HttpdArchitect do
subject(:architect) { HttpdArchitect.new(binary_version: '2.4.12') }

describe '#new' do

it 'sets a binary version' do
expect(architect.binary_version).to eq('2.4.12')
end
end

describe 'blueprint' do
let(:template_file) { double(read: 'BINARY_VERSION') }

before do
allow(File).to receive(:open).and_return(template_file)
end

it 'uses the httpd_blueprint template' do
expect(File).to receive(:open).with(File.expand_path('../../../templates/httpd_blueprint', __FILE__))
architect.blueprint
end

it 'adds the binary version' do
expect(architect.blueprint).to include '2.4.12'
end
end
end
end
90 changes: 90 additions & 0 deletions templates/httpd_blueprint
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash
set -e

STAGING_DIR="/tmp/staged/app"

INSTALLATION_DIR=$1

ln -sf $INSTALLATION_DIR /app/httpd

function build_apr() {
curl -f -L -O "http://apache.mirrors.tds.net/apr/apr-$APR_VERSION.tar.gz"
tar zxf "apr-$APR_VERSION.tar.gz"
pushd "apr-$APR_VERSION"
./configure --prefix="$STAGING_DIR/libapr-$APR_VERSION"
make -j 3
make install
popd
}

function build_apr_iconv() {
curl -f -L -O "http://apache.mirrors.tds.net/apr/apr-iconv-$APR_ICONV_VERSION.tar.gz"
tar zxf "apr-iconv-$APR_ICONV_VERSION.tar.gz"
pushd "apr-iconv-$APR_ICONV_VERSION"
./configure \
--prefix="$STAGING_DIR/libapr-iconv-$APR_ICONV_VERSION" \
--with-apr="$STAGING_DIR/libapr-$APR_VERSION/bin/apr-1-config"
make -j 3
make install
popd
}

function build_apr_util() {
curl -f -L -O "http://apache.mirrors.tds.net/apr/apr-util-$APR_UTIL_VERSION.tar.gz"
tar zxf "apr-util-$APR_UTIL_VERSION.tar.gz"
pushd "apr-util-$APR_UTIL_VERSION"
./configure \
--prefix="$STAGING_DIR/libapr-util-$APR_UTIL_VERSION" \
--with-iconv="$STAGING_DIR/libapr-iconv-$ICONV_VERSION" \
--with-crypto \
--with-openssl \
--with-mysql \
--with-pgsql \
--with-gdbm \
--with-ldap \
--with-apr="$STAGING_DIR/libapr-$APR_VERSION"
make -j 3
make install
popd
}

function build_required_libs() {
build_apr
build_apr_iconv
build_apr_util
}

function build_httpd_24() {
curl -f -L -O "http://apache.osuosl.org/httpd/httpd-$HTTPD_VERSION.tar.bz2"
tar jxf "httpd-$HTTPD_VERSION.tar.bz2"
pushd "httpd-$HTTPD_VERSION"
./configure \
--prefix="/app/httpd" \
--with-apr="$STAGING_DIR/libapr-$APR_VERSION" \
--with-apr-util="$STAGING_DIR/libapr-util-$APR_UTIL_VERSION" \
--enable-mpms-shared="worker event" \
--enable-mods-shared=reallyall \
--disable-isapi \
--disable-dav \
--disable-dialup
make -j 3
make install
popd
}

# build required libs & httpd
build_required_libs
build_httpd_24

# Remove unnecessary files and config
cd "/app/httpd"
rm -rf build/ cgi-bin/ error/ icons/ include/ man/ manual/ htdocs/
rm -rf conf/extra/* conf/httpd.conf conf/httpd.conf.bak conf/magic conf/original

# Install required libraries
mkdir "/app/httpd/lib"
cp "$STAGING_DIR/libapr-$APR_VERSION/lib/libapr-1.so.0" "/app/httpd/lib"
cp "$STAGING_DIR/libapr-util-$APR_UTIL_VERSION/lib/libaprutil-1.so.0" "/app/httpd/lib"
cp "$STAGING_DIR/libapr-iconv-$APR_ICONV_VERSION/lib/libapriconv-1.so.0" "/app/httpd/lib"

echo "Done!"

0 comments on commit 6578597

Please sign in to comment.