Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

Commit

Permalink
Better code structure for packaging
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Lucas <xavier.lucas@corp.ovh.com>
  • Loading branch information
Xavier Lucas committed Apr 4, 2016
1 parent 6b25b72 commit e9bbf53
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 59 deletions.
13 changes: 3 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby

require 'rake/testtask'
require_relative 'scripts/package.rb'

package = {
:name => 'svfs',
Expand All @@ -25,16 +26,8 @@ end
# -----------------------------------------
desc 'Release a new version'
task :release, [:version] => [:prepare_release] do |t, args|
system(%Q(scripts/package.rb \
"#{package[:path]}" \
"#{package[:name]}" \
"#{package[:maintainer]}" \
"#{package[:vendor]}" \
"#{package[:url]}" \
"#{package[:info]}" \
"#{package[:licence]}" \
"#{args.version}"
))
mkdir_p package[:path]
release(package, args.version)
end

# -----------------------------------------
Expand Down
89 changes: 40 additions & 49 deletions scripts/package.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#!/usr/bin/env ruby

pkg_path = ARGV[0]
pkg_name = ARGV[1]
pkg_main = ARGV[2]
pkg_vend = ARGV[3]
pkg_url = ARGV[4]
pkg_info = ARGV[5]
pkg_lic = ARGV[6]
pkg_vers = ARGV[7]

# Package dependencies
DEPENDENCIES = {
'fuse' => '> 2.8',
Expand All @@ -29,53 +20,53 @@
'armel' => 5,
}

pkg_deps = ""

# Make release directory
unless File.directory?("#{pkg_path}")
Dir.mkdir("#{pkg_path}")
end
def build(package, type, version, os, arch, deps)
go_arch = arch
pkg_deps = ""

# Build dependencies chain
DEPENDENCIES.each do |pkg, constraint|
pkg_deps << "-d '#{pkg} #{constraint}' "
end
deps.each do |pkg, constraint|
pkg_deps << "-d '#{pkg} #{constraint}' "
end

# Build go binary and package it
TARGETS.each do |target|
target.each do |os, pkgmap|
pkgmap.each do |pkg, archs|
archs.each do |arch|
if arch.start_with?('arm')
go_arch = 'arm'
go_extra = "GOARM=#{ARM_VERSIONS[arch]}"
end

go_arch = arch
go_build_target = "#{package[:path]}/go-#{package[:name]}-#{os}-#{arch}"
sh %{GOARCH=#{go_arch} GOOS=#{os} #{go_extra} go build -o #{go_build_target}}
sh %{chmod 755 #{go_build_target}}
sh %{fpm --force \\
-s dir \\
-t #{type} \\
-a #{arch} \\
-n #{package[:name]} \\
-p #{package[:path]} \\
#{pkg_deps} \\
--maintainer "#{package[:maintainer]}" \\
--description "#{package[:info]}" \\
--license "#{package[:licence]}" \\
--url "#{package[:url]}" \\
--vendor "#{package[:vendor]}" \\
--version "#{version}" \\
#{go_build_target}=/usr/local/bin/#{package[:name]} \\
scripts/mount.#{package[:name]}=/sbin/mount.#{package[:name]} \\
scripts/hubic-application.rb=/usr/local/bin/hubic-application
}

if arch.start_with?('arm')
go_arch = 'arm'
go_extra = "GOARM=#{ARM_VERSIONS[arch]}"
end

pkg_fullname = "#{pkg_path}/go-#{pkg_name}-#{os}-#{arch}"
system("GOARCH=#{go_arch} GOOS=#{os} #{go_extra} go build -o #{pkg_fullname}")
system("chmod 755 #{pkg_fullname}")
system(%{fpm --force \
-s dir \
-t #{pkg} \
-a #{arch} \
-n #{pkg_name} \
-p #{pkg_path} \
#{pkg_deps} \
--maintainer "#{pkg_main}" \
--description "#{pkg_info}" \
--license "#{pkg_lic}" \
--url "#{pkg_url}" \
--vendor "#{pkg_vend}" \
--version "#{pkg_vers}" \
#{pkg_fullname}=/usr/local/bin/#{pkg_name} \
scripts/mount.#{pkg_name}=/sbin/mount.#{pkg_name} \
scripts/hubic-application.rb=/usr/local/bin/hubic-application
})
end

def release(package, version)
TARGETS.each do |target|
target.each do |os, pkgmap|
pkgmap.each do |pkg, archs|
archs.each do |arch|
build(package, pkg, version, os, arch, DEPENDENCIES)
end
end
end
end
end


0 comments on commit e9bbf53

Please sign in to comment.