Skip to content

Commit

Permalink
initial build:ubuntu task (#1231)
Browse files Browse the repository at this point in the history
1231 was not squashed, so this is the squashed commit of that pull
request.
  • Loading branch information
johrstrom committed Oct 19, 2021
1 parent 2b4f00a commit e594850
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
# Build artifacts
/apps/*/.built
/packaging/*.tar.gz
/build

lib-cov
*.seed
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ APPS_DIR = PROJ_DIR.join('apps')
GEMFILE = PROJ_DIR.join('Gemfile')
INSTALL_ROOT = Pathname.new(ENV["PREFIX"] || "/opt/ood")
VENDOR_BUNDLE = (ENV['VENDOR_BUNDLE'] == "yes" || ENV['VENDOR_BUNDLE'] == "true")
VENDOR_BUNDLE_PATH = Pathname.new(ENV['VENDOR_BUNDLE_PATH'] || "vendor/bundle")
PASSENGER_APP_ENV = ENV["PASSENGER_APP_ENV"] || "production"

require "#{TASK_DIR}/rake_helper"
require "#{TASK_DIR}/build"
require "#{TASK_DIR}/packaging"
require "#{TASK_DIR}/test"
require "#{TASK_DIR}/lint"
Expand All @@ -23,7 +25,7 @@ namespace :build do
task :gems do
bundle_args = ["--jobs 4", "--retry 2"]
if VENDOR_BUNDLE
bundle_args << "--path vendor/bundle"
bundle_args << "--path #{VENDOR_BUNDLE_PATH}"
end
if PASSENGER_APP_ENV == "production"
bundle_args << "--without doc"
Expand Down
8 changes: 8 additions & 0 deletions debian/README.Debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ondemand for Debian

Please edit this to provide information specific to
this ondemand Debian package.

(Automatically generated by debmake Version 4.3.1)

-- root <> Sun, 20 Jun 2021 23:14:31 +0000
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ondemand (2.0.10-1) UNRELEASED; urgency=low

* Initial release. Closes: #nnnn
<nnnn is the bug number of your ITP>

-- root <> Sun, 20 Jun 2021 23:14:31 +0000
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11
15 changes: 15 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Source: ondemand
Section: unknown
Priority: optional
Maintainer: root <>
Build-Depends: debhelper (>=11~), ruby
Standards-Version: 4.1.4
Homepage: <insert the upstream URL, if relevant>

Package: ondemand
Architecture: all
Multi-Arch: foreign
Depends: ${misc:Depends}, ${ruby:Depends}
Description: auto-generated package by debmake
This Debian binary package was auto-generated by the
debmake(1) command provided by the debmake package.
9 changes: 9 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: ondemand
Source: <url://example.com>
#
# Please double check copyright with the licensecheck(1) command.

#----------------------------------------------------------------------------
# Files marked as NO_LICENSE_TEXT_FOUND may be covered by the following
# license/copyright files.
1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# You must remove unused comment lines for the released package.
12 changes: 12 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
# export DH_VERBOSE = 1

%:
dh $@

override_dh_auto_configure:
# nothing to configure

override_dh_auto_build:
rake build
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (quilt)
2 changes: 2 additions & 0 deletions debian/source/local-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#abort-on-upstream-changes
#unapply-patches
2 changes: 2 additions & 0 deletions debian/watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# You must remove unused comment lines for the released package.
version=3
67 changes: 67 additions & 0 deletions lib/tasks/build.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require_relative 'build_utils'
include BuildUtils

namespace :build do

task :verify_build_args, [:platform, :version] do |task, args|
raise "Need to specify platform and version" if args[:platform].nil? || args[:version].nil?
end

desc "Create buildbox for Open OnDemand"
task :build_box, [:platform, :version] => [:verify_build_args] do |task, args|
platform = args[:platform].to_s
image_tag = "#{platform}-#{args[:version]}"
cmd = build_cmd(
template_file("Dockerfile.#{platform}.erb"),
image_names[:build_box],
image_tag: build_box_tag(args)
)

sh cmd unless image_exists?(build_box_image(args))
end

task :debuild, [:platform, :version] => [:build_box] do |task, args|
dir = build_dir(args)
Rake::Task['package:tar'].invoke(dir)
sh "#{tar} -xzf #{dir}/#{ood_package_tar} -C #{dir}"

work_dir = "/build/#{versioned_ood_package}"
bundle_ctr = "#{work_dir}/vendor/bundle"

base_args = ["--rm"]
base_args.concat ["-v", "#{dir}:/build", "-w", "#{work_dir}"]
base_args.concat [ "-e", "VENDOR_BUNDLE_PATH=#{bundle_ctr}", "-e", "VENDOR_BUNDLE=true"]
base_args.concat ["-e", "DEBUILD_DPKG_BUILDPACKAGE_OPTS='-us -uc -I -i'"]
base_args.concat [ build_box_image(args)]
sh "#{container_runtime} run #{base_args.join(' ')} debmake -b':ruby'"

debuild_args = ["debuild", "-e", "VENDOR_BUNDLE_PATH", "-e", "VENDOR_BUNDLE"]
debuild_args.concat ["--no-lintian"]
sh "#{container_runtime} run #{base_args.join(' ')} #{debuild_args.join(' ')}"
end

task :nginx, [:platform, :version] => [:build_box] do |task, args|
tar = "#{build_src_dir}/#{nginx_tar}"
sh "wget #{nginx_tar_url} -O #{tar}" unless File.exist?(tar)
end

task :passenger, [:platform, :version] => [:build_box] do |task, args|
tar = "#{build_src_dir}/#{passenger_tar}"
sh "wget #{passenger_tar_url} -O #{tar}" unless File.exist?(tar)

# agent tar isn't versioned, so let's do that now.
agent_tar = "#{build_src_dir}/passenger-agent-#{passenger_version}.tar.gz"
sh "wget #{passenger_agent_tar_url} -O #{agent_tar}" unless File.exist?(agent_tar)

work_dir = "/build"
passenger_host = "#{build_dir(args)}/passenger".tap { |p| sh "mkdir -p #{p}" }
sh "#{tar} --strip-components=1 -xzf #{tar} -C #{passenger_host}"

base_args = ["--rm", "-v", "#{passenger_host}:#{work_dir}", "-w", "#{work_dir}"]
base_args.concat [ build_box_image(args) ]
makefile_args = base_args + [ "ruby", "#{work_dir}/src/ruby_native_extension/extconf.rb" ]

sh "#{container_runtime} run #{makefile_args.join(' ')}"
sh "#{container_runtime} run #{base_args.join(' ')} make"
end
end
139 changes: 137 additions & 2 deletions lib/tasks/build_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ def proj_root
File.expand_path(File.join(File.dirname(__FILE__), '../..'))
end

def image_tag
def ood_image_tag
tag? ? numeric_tag : "#{numeric_tag}-#{git_hash}"
end

def ood_version
tag? ? git_tag : "#{git_tag}-#{git_hash}"
end

def ood_package_version
@ood_package_version ||= begin
if ! ENV['VERSION']
tag? ? git_tag : "#{git_tag}-#{build_timestamp}-#{git_hash}"
else
ENV['VERSION'].to_s
end
end
end

def build_timestamp
@build_timestamp ||= Time.now.strftime("%s")
end

def git_hash
@git_hash ||= `git rev-parse HEAD`.strip[0..6]
end
Expand All @@ -37,6 +51,23 @@ def container_runtime
podman_runtime? ? "podman" : "docker"
end

def tar
`which gtar 1>/dev/null 2>&1`
$?.success? ? 'gtar' : 'tar'
end

def ood_package_name
"ondemand"
end

def versioned_ood_package
"#{ood_package_name}-#{ood_package_version}"
end

def ood_package_tar
"#{versioned_ood_package}.tar.gz"
end

def test_image_name
"ood-test"
end
Expand All @@ -52,4 +83,108 @@ def image_name
def user
@user ||= Etc.getpwnam(Etc.getlogin)
end
end

def image_names
@image_names ||=
{
build_box: "ood-buildbox",
ood: "ood",
test: "ood-test",
dev: "ood-dev"
}.freeze
end

def build_dir(args)
"#{PROJ_DIR}/build/#{build_box_tag(args)}"
end

def build_src_dir
"#{PROJ_DIR}/build/src".tap { |p| sh "mkdir -p #{p}" }
end

def build_box_tag(args)
base_name = "#{args[:platform]}-#{args[:version]}"
@version_lookup ||= {
'ubuntu-20.04': "1"
}.freeze

"#{base_name}-#{@version_lookup[base_name.to_sym]}"
end

def build_box_image(args)
"#{image_names[:build_box]}:#{build_box_tag(args)}"
end

def image_exists?(image_name)
`#{container_runtime} inspect --type image --format exists #{image_name} || true`.chomp.eql?('exists')
end

def nginx_version
"1.18.0"
end

def passenger_version
"6.0.7"
end

def nginx_tar
"nginx-#{nginx_version}-x86_64-linux.tar.gz"
end

def nginx_tar_url
"#{passenger_release_url}/#{nginx_tar}"
end

def passenger_base_url
"https://github.com/phusion/passenger/releases/download"
end

def passenger_release_url
"#{passenger_base_url}/release-#{passenger_version}"
end

def passenger_tar
"passenger-#{passenger_version}.tar.gz"
end

def passenger_tar_url
"#{passenger_release_url}/#{passenger_tar}"
end

def passenger_agent_tar_url
"#{passenger_release_url}/agent-x86_64-linux.tar.gz"
end

def buildah_build_cmd(docker_file, image_name, image_tag: ood_image_tag, extra_args: [])
args = ["bud", "--build-arg", "VERSION=#{ood_version}"]
args.concat ["-t", "#{image_name}:#{image_tag}", "-f", docker_file]
args.concat extra_args

"buildah #{args.join(' ')}"
end

def docker_build_cmd(docker_file, image_name, image_tag: ood_image_tag, extra_args: [])
args = ["build", "--build-arg", "VERSION=#{ood_version}"]
args.concat ["-t", "#{image_name}:#{image_tag}", "-f", docker_file, "."]
args.concat extra_args

"docker #{args.join(' ')}"
end

def build_cmd(file, image_name, image_tag: ood_image_tag, extra_args: [])
if podman_runtime?
buildah_build_cmd(file, image_name, image_tag: image_tag, extra_args: extra_args)
else
docker_build_cmd(file, image_name, image_tag: image_tag, extra_args: extra_args)
end
end

def tag_latest_container_cmd(image_name, image_tag: ood_image_tag)
"#{container_runtime} tag #{image_name}:#{image_tag} #{image_name}:latest"
end

def template_file(filename)
cwd = "#{File.expand_path(__dir__)}"
"#{cwd}/templates/#{filename}"
end
end
Loading

0 comments on commit e594850

Please sign in to comment.