add possibility to create package

This commit is contained in:
Artur Gurgul1 2025-08-07 13:02:01 +02:00
parent a7807f089c
commit ed7fc9aa7f
6 changed files with 104 additions and 10 deletions

View file

@ -56,6 +56,14 @@ when :make
puts "making..."
require 'make'
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
puts "Ececuting: #{options.name}"
require 'execute'

View 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

View file

@ -10,6 +10,9 @@ require 'ostruct'
# dat execute progress
# dat execute < default Configfile
# dat execute --dry-run
# Execute single command
# dat command service zulip
module Execute
def dependency(name)
@ -59,6 +62,9 @@ module Execute
end
def self.file(options)
require 'make'
puts Make.context("postgresql")
puts "options: #{options}"
dsl = Object.new
dsl.extend(Execute)

View file

@ -29,7 +29,7 @@ module Make
class Context
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)
@target = options.target || :user
@ -55,15 +55,21 @@ module Make
@packages = makefile["packages"] || []
project_sources = {
repository: makefile["repository"] != nil,
archive: makefile["archive"] != nil
repository: makefile["repository"],
archive: makefile["archive"]
}.select { |_, v| v }
if project_sources.size == 1
source_data = project_sources.values.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
raise "Exactly one type of source: 'repository' or 'archive'"
end
puts @source_type
@repository = Make.rostruct(makefile["repository"] || OpenStruct.new)
@ -97,7 +103,7 @@ module Make
when :user
"#{ENV["HOME"]}/.local"
when :package
"#{sys_prefix}/pkg/#{@name}/#{@repository.branch}"
"#{sys_prefix}/pkg/#{@name}/#{@version}"
when :system
"#{sys_prefix}/"
else
@ -227,13 +233,45 @@ module Make
def install
System.install(context.packages)
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
# dat make -t pkg --cache --name dry-run
# dat make --name dry-run
def self.command(options)
context = Context.new(options: options)
builder = Builder.new(context)
builder.build
context = Context.new(options: options)
builder = Builder.new(context)
builder.build
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

View file

@ -5,14 +5,25 @@ module Setup
module PostgreSQL
extend Templates
# attr_accessor :te
def self.init_db
system(" -D /opt/pgsql/16/data")
end
def self.make_config
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
end

View file

@ -14,8 +14,10 @@ packages:
repository:
url: https://github.com/postgres/postgres.git
branch: REL_17_5
version: 17.5
steps:
- ./configure --prefix=$PREFIX
- make -j$CPUS
- make install
- $SUDO mkdir -p $PREFIX
- $SUDO make install