add possibility to create package
This commit is contained in:
parent
a7807f089c
commit
ed7fc9aa7f
6 changed files with 104 additions and 10 deletions
8
bin/dat
8
bin/dat
|
@ -56,6 +56,14 @@ when :make
|
||||||
puts "making..."
|
puts "making..."
|
||||||
require 'make'
|
require 'make'
|
||||||
Make.command(options)
|
Make.command(options)
|
||||||
|
when :pkgmake
|
||||||
|
puts "Making package #{options.name}"
|
||||||
|
require 'make'
|
||||||
|
Make.create_package(options)
|
||||||
|
when :pkginstall
|
||||||
|
require 'make'
|
||||||
|
# TODO: wrong naming it is not name, but path
|
||||||
|
Make.install_package(options.name)
|
||||||
when :execute
|
when :execute
|
||||||
puts "Ececuting: #{options.name}"
|
puts "Ececuting: #{options.name}"
|
||||||
require 'execute'
|
require 'execute'
|
||||||
|
|
29
lib/data/templates/postgresql/postgresql.service
Normal file
29
lib/data/templates/postgresql/postgresql.service
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
[Unit]
|
||||||
|
Description=PostgreSQL <%= version %> database server
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=notify
|
||||||
|
|
||||||
|
User=postgres
|
||||||
|
Group=services
|
||||||
|
|
||||||
|
ExecStart=<%= prefix %>/bin/postgres -D <%= database_path %>/data
|
||||||
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
KillMode=mixed
|
||||||
|
TimeoutSec=300
|
||||||
|
Restart=on-failure
|
||||||
|
NotifyAccess=all
|
||||||
|
|
||||||
|
# Security
|
||||||
|
ProtectSystem=full
|
||||||
|
ProtectHome=true
|
||||||
|
PrivateTmp=true
|
||||||
|
NoNewPrivileges=true
|
||||||
|
|
||||||
|
# Resource Limits
|
||||||
|
LimitNOFILE=65536
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -10,6 +10,9 @@ require 'ostruct'
|
||||||
|
|
||||||
# dat execute progress
|
# dat execute progress
|
||||||
# dat execute < default Configfile
|
# dat execute < default Configfile
|
||||||
|
# dat execute --dry-run
|
||||||
|
# Execute single command
|
||||||
|
# dat command service zulip
|
||||||
|
|
||||||
module Execute
|
module Execute
|
||||||
def dependency(name)
|
def dependency(name)
|
||||||
|
@ -59,6 +62,9 @@ module Execute
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.file(options)
|
def self.file(options)
|
||||||
|
require 'make'
|
||||||
|
puts Make.context("postgresql")
|
||||||
|
|
||||||
puts "options: #{options}"
|
puts "options: #{options}"
|
||||||
dsl = Object.new
|
dsl = Object.new
|
||||||
dsl.extend(Execute)
|
dsl.extend(Execute)
|
||||||
|
|
46
lib/make.rb
46
lib/make.rb
|
@ -29,7 +29,7 @@ module Make
|
||||||
|
|
||||||
class Context
|
class Context
|
||||||
attr_accessor :name, :use_cache, :environment, :steps, :packages, :repository
|
attr_accessor :name, :use_cache, :environment, :steps, :packages, :repository
|
||||||
attr_accessor :target, :archive, :source_type
|
attr_accessor :target, :archive, :source_type, :version
|
||||||
|
|
||||||
def initialize(options: OpenStruct.new)
|
def initialize(options: OpenStruct.new)
|
||||||
@target = options.target || :user
|
@target = options.target || :user
|
||||||
|
@ -55,15 +55,21 @@ module Make
|
||||||
@packages = makefile["packages"] || []
|
@packages = makefile["packages"] || []
|
||||||
|
|
||||||
project_sources = {
|
project_sources = {
|
||||||
repository: makefile["repository"] != nil,
|
repository: makefile["repository"],
|
||||||
archive: makefile["archive"] != nil
|
archive: makefile["archive"]
|
||||||
}.select { |_, v| v }
|
}.select { |_, v| v }
|
||||||
|
|
||||||
if project_sources.size == 1
|
if project_sources.size == 1
|
||||||
|
source_data = project_sources.values.first
|
||||||
@source_type = project_sources.keys.first
|
@source_type = project_sources.keys.first
|
||||||
|
@version = source_data["version"] || source_data["branch"]
|
||||||
|
|
||||||
|
raise "No version provided" if @version == nil
|
||||||
|
@version = @version.to_s
|
||||||
else
|
else
|
||||||
raise "Exactly one type of source: 'repository' or 'archive'"
|
raise "Exactly one type of source: 'repository' or 'archive'"
|
||||||
end
|
end
|
||||||
|
|
||||||
puts @source_type
|
puts @source_type
|
||||||
|
|
||||||
@repository = Make.rostruct(makefile["repository"] || OpenStruct.new)
|
@repository = Make.rostruct(makefile["repository"] || OpenStruct.new)
|
||||||
|
@ -97,7 +103,7 @@ module Make
|
||||||
when :user
|
when :user
|
||||||
"#{ENV["HOME"]}/.local"
|
"#{ENV["HOME"]}/.local"
|
||||||
when :package
|
when :package
|
||||||
"#{sys_prefix}/pkg/#{@name}/#{@repository.branch}"
|
"#{sys_prefix}/pkg/#{@name}/#{@version}"
|
||||||
when :system
|
when :system
|
||||||
"#{sys_prefix}/"
|
"#{sys_prefix}/"
|
||||||
else
|
else
|
||||||
|
@ -227,6 +233,13 @@ module Make
|
||||||
def install
|
def install
|
||||||
System.install(context.packages)
|
System.install(context.packages)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_package(options)
|
||||||
|
puts "Creating packahge for options: #{options}"
|
||||||
|
puts @context
|
||||||
|
puts "Prefix #{@context.get_prefix}"
|
||||||
|
system("tar --zstd -Pcf #{@context.name}-#{@context.version}.pkg #{@context.get_prefix}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# dat make -t pkg --cache --name dry-run
|
# dat make -t pkg --cache --name dry-run
|
||||||
|
@ -236,4 +249,29 @@ module Make
|
||||||
builder = Builder.new(context)
|
builder = Builder.new(context)
|
||||||
builder.build
|
builder.build
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# dat pkginstall {file-path}
|
||||||
|
# an example `dat pkginstall postgresql-17.5.pkg`
|
||||||
|
def self.install_package(path)
|
||||||
|
puts "Installing package: #{path}"
|
||||||
|
system("sudo tar --zstd -xf #{path} -C /")
|
||||||
|
end
|
||||||
|
|
||||||
|
# dat pkgmake {name}
|
||||||
|
def self.create_package(options)
|
||||||
|
options["target"] = :package if options["target"] == nil
|
||||||
|
context = Context.new(options: options)
|
||||||
|
builder = Builder.new(context)
|
||||||
|
builder.create_package(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: better name, it is just to obtain information
|
||||||
|
# about the package
|
||||||
|
def self.context(package_name, target = :package)
|
||||||
|
options = OpenStruct.new
|
||||||
|
options["target"] = target
|
||||||
|
options["name"] = package_name
|
||||||
|
Context.new(options: options)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,14 +5,25 @@ module Setup
|
||||||
module PostgreSQL
|
module PostgreSQL
|
||||||
extend Templates
|
extend Templates
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# attr_accessor :te
|
# attr_accessor :te
|
||||||
|
|
||||||
|
def self.init_db
|
||||||
|
system(" -D /opt/pgsql/16/data")
|
||||||
|
end
|
||||||
|
|
||||||
def self.make_config
|
def self.make_config
|
||||||
pg_hba = render("pg_hba.conf")
|
pg_hba = render("pg_hba.conf")
|
||||||
|
|
||||||
test = render("test", te: "This is a test string")
|
# test = render("test", te: "This is a test string")
|
||||||
|
posgresql_conf = render("postgresql")
|
||||||
|
service = render(
|
||||||
|
"postgresql.service",
|
||||||
|
prefix: "/pkg/postgresql/REL_17_5/",
|
||||||
|
version: "16.5",
|
||||||
|
data_url: "/data/postgresql/16/"
|
||||||
|
)
|
||||||
puts test
|
puts test
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,10 @@ packages:
|
||||||
repository:
|
repository:
|
||||||
url: https://github.com/postgres/postgres.git
|
url: https://github.com/postgres/postgres.git
|
||||||
branch: REL_17_5
|
branch: REL_17_5
|
||||||
|
version: 17.5
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- ./configure --prefix=$PREFIX
|
- ./configure --prefix=$PREFIX
|
||||||
- make -j$CPUS
|
- make -j$CPUS
|
||||||
- make install
|
- $SUDO mkdir -p $PREFIX
|
||||||
|
- $SUDO make install
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue