save
This commit is contained in:
parent
0fb2502e53
commit
57cc223477
2 changed files with 59 additions and 9 deletions
34
lib/make.rb
34
lib/make.rb
|
@ -28,7 +28,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
|
attr_accessor :target, :archive, :source_type
|
||||||
|
|
||||||
def initialize(options: OpenStruct.new)
|
def initialize(options: OpenStruct.new)
|
||||||
@target = options.target || :user
|
@target = options.target || :user
|
||||||
|
@ -52,7 +52,21 @@ module Make
|
||||||
# puts makefile
|
# puts makefile
|
||||||
|
|
||||||
@packages = makefile["packages"] || []
|
@packages = makefile["packages"] || []
|
||||||
|
|
||||||
|
project_sources = {
|
||||||
|
repository: makefile["repository"] != nil,
|
||||||
|
archive: makefile["archive"] != nil
|
||||||
|
}.select { |_, v| v }
|
||||||
|
|
||||||
|
if project_sources.size == 1
|
||||||
|
@source_type = project_sources.keys.first
|
||||||
|
else
|
||||||
|
raise "Exactly one type of source: 'repository' or 'archive'"
|
||||||
|
end
|
||||||
|
puts @source_type
|
||||||
|
|
||||||
@repository = Make.rostruct(makefile["repository"] || OpenStruct.new)
|
@repository = Make.rostruct(makefile["repository"] || OpenStruct.new)
|
||||||
|
@archive = Make.rostruct(makefile["archive"] || OpenStruct.new)
|
||||||
@steps = makefile["steps"] || []
|
@steps = makefile["steps"] || []
|
||||||
|
|
||||||
@environment = ENV.to_h.merge(
|
@environment = ENV.to_h.merge(
|
||||||
|
@ -147,7 +161,14 @@ module Make
|
||||||
install
|
install
|
||||||
@context.rpd do | path |
|
@context.rpd do | path |
|
||||||
@cwd = path
|
@cwd = path
|
||||||
checkout
|
|
||||||
|
case @context.source_type
|
||||||
|
when :repository
|
||||||
|
checkout
|
||||||
|
when :archive
|
||||||
|
download_and_extract
|
||||||
|
end
|
||||||
|
|
||||||
puts "path: #{path}"
|
puts "path: #{path}"
|
||||||
Dir.chdir(path)
|
Dir.chdir(path)
|
||||||
|
|
||||||
|
@ -160,6 +181,13 @@ module Make
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def download_and_extract
|
||||||
|
archive = @context.archive
|
||||||
|
|
||||||
|
puts archive
|
||||||
|
exit -1
|
||||||
|
end
|
||||||
|
|
||||||
def checkout
|
def checkout
|
||||||
repo_path = @context.local_repo
|
repo_path = @context.local_repo
|
||||||
|
@ -195,4 +223,4 @@ module Make
|
||||||
builder = Builder.new(context)
|
builder = Builder.new(context)
|
||||||
builder.build
|
builder.build
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,27 +3,47 @@ require 'erb'
|
||||||
|
|
||||||
class NGINXProxy
|
class NGINXProxy
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :domain, :port, :service
|
attr_accessor :domain, :port, :service, :user
|
||||||
|
|
||||||
def domain(value = nil)
|
def domain(value = nil)
|
||||||
@domain = value unless value.nil?
|
@domain = value unless value.nil?
|
||||||
@domain
|
@domain
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def user(value = nil)
|
||||||
|
@user = value unless value.nil?
|
||||||
|
@user
|
||||||
|
end
|
||||||
|
|
||||||
def port(value = nil)
|
def port(value = nil)
|
||||||
@port = value unless value.nil?
|
@port = value unless value.nil?
|
||||||
@port
|
@port
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This is name of the daemon that will be installed
|
||||||
|
# This is also master name user as user if not provided
|
||||||
def service(value = nil)
|
def service(value = nil)
|
||||||
@service = value unless value.nil?
|
@service = value unless value.nil?
|
||||||
@service
|
@service
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate
|
def generate
|
||||||
template = File.read("proxy.erb")
|
template = File.read("proxy.erb")
|
||||||
template = ERB.new(template)
|
template = ERB.new(template)
|
||||||
template.result(binding)
|
template.result(binding)
|
||||||
|
end
|
||||||
|
|
||||||
|
def available_path
|
||||||
|
"/etc/nginx/sites-available/#{service}.#{domain}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def enabled_path
|
||||||
|
"/etc/nginx/sites-available/#{service}.#{domain}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def install
|
||||||
|
config = generate
|
||||||
|
File.write
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -31,7 +51,9 @@ end
|
||||||
class ExampleProxy < NGINXProxy
|
class ExampleProxy < NGINXProxy
|
||||||
domain "gurgul.org"
|
domain "gurgul.org"
|
||||||
service "forgejo"
|
service "forgejo"
|
||||||
|
user "git"
|
||||||
port 3000
|
port 3000
|
||||||
end
|
end
|
||||||
|
|
||||||
puts ExampleProxy.generate
|
puts ExampleProxy.generate
|
||||||
|
puts ExampleProxy.path
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue