Compare commits
2 Commits
6eb9c49c22
...
2eb20aa09b
Author | SHA1 | Date | |
---|---|---|---|
2eb20aa09b | |||
42f43db2b1 |
3
examples/hello_crystal/README.md
Normal file
3
examples/hello_crystal/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# README
|
||||||
|
|
||||||
|
This is the readme for people trying to *use* this runtime.
|
4
runtimes/crystal/README.md
Normal file
4
runtimes/crystal/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# README
|
||||||
|
|
||||||
|
This is the readme for people wanting to change this runtime,
|
||||||
|
not for people trying to use it
|
11
runtimes/crystal/template/README.md.j2
Normal file
11
runtimes/crystal/template/README.md.j2
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Readme for {{name | title}}
|
||||||
|
|
||||||
|
This is a funko using the Crystal runtime for [FaaSO](https://git.ralsina.me/ralsina/faaso)
|
||||||
|
|
||||||
|
## What is {{name | title}}
|
||||||
|
|
||||||
|
Write here what it is
|
||||||
|
|
||||||
|
## How to use {{name | title}}
|
||||||
|
|
||||||
|
And so on.
|
16
runtimes/crystal/template/funko.cr
Normal file
16
runtimes/crystal/template/funko.cr
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
require "kemal"
|
||||||
|
|
||||||
|
# This is a kemal app, you can add handlers, middleware, etc.
|
||||||
|
|
||||||
|
# A basic hello world get endpoint
|
||||||
|
get "/" do
|
||||||
|
"Hello World Crystal!"
|
||||||
|
end
|
||||||
|
|
||||||
|
# The `/ping/` endpoint is configured in the container as a healthcheck
|
||||||
|
# You can make it better by checking that your database is responding
|
||||||
|
# or whatever checks you think are important
|
||||||
|
#
|
||||||
|
get "/ping/" do
|
||||||
|
"OK"
|
||||||
|
end
|
2
runtimes/crystal/template/funko.yml.j2
Normal file
2
runtimes/crystal/template/funko.yml.j2
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
name: {{ name }}
|
||||||
|
runtime: crystal
|
@ -1,4 +1,4 @@
|
|||||||
name: function
|
name: {{ name }}
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
|
||||||
targets:
|
targets:
|
@ -22,15 +22,58 @@ module Faaso
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create folder with a preconfigured funko for this runtime
|
# Get runtime template files list
|
||||||
|
template_base = ""
|
||||||
|
template_files = [] of String
|
||||||
if @@known.includes? "./runtimes/#{runtime}"
|
if @@known.includes? "./runtimes/#{runtime}"
|
||||||
Log.info { "Using known runtime #{runtime}" }
|
Log.info { "Using known runtime #{runtime}" }
|
||||||
|
template_base = "./runtimes/#{runtime}/template"
|
||||||
|
template_files = @@filelist.select(&.starts_with?(template_base))
|
||||||
elsif File.exists? runtime
|
elsif File.exists? runtime
|
||||||
Log.info { "Using directory #{runtime} as runtime" }
|
Log.info { "Using directory #{runtime} as runtime" }
|
||||||
|
template_base = "#{runtime}/template"
|
||||||
|
template_files = Dir.glob("#{template_base}/**/*")
|
||||||
else
|
else
|
||||||
Log.error { "Can't find runtime #{runtime}" }
|
Log.error { "Can't find runtime #{runtime}" }
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Create new folder
|
||||||
|
if Dir.exists? folder
|
||||||
|
Log.error { "Folder #{folder} already exists" }
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
Dir.mkdir_p folder
|
||||||
|
|
||||||
|
template_files.each do |t_file|
|
||||||
|
content = IO::Memory.new
|
||||||
|
# We need to use RUCKSACK_MODE=0 so it
|
||||||
|
# fallbacks to the filesystem
|
||||||
|
rucksack(t_file).read(content)
|
||||||
|
if content.nil?
|
||||||
|
Log.error { "Can't find file #{t_file}" }
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
# t_file is like "#{template_base}/foo"
|
||||||
|
# dst is like #{folder}/foo
|
||||||
|
dst = Path[folder] / Path[t_file].relative_to(template_base)
|
||||||
|
# Render templated files
|
||||||
|
if t_file.ends_with? ".j2"
|
||||||
|
dst = dst.sibling(dst.stem)
|
||||||
|
Log.info { " Creating file #{dst} from #{t_file}" }
|
||||||
|
File.open(dst, "w") do |file|
|
||||||
|
file << Crinja.render(content.to_s, {"name" => Path[folder].basename})
|
||||||
|
end
|
||||||
|
else # Just copy the file
|
||||||
|
Log.info { " Creating file #{dst} from #{t_file}" }
|
||||||
|
File.open(dst, "w") do |file|
|
||||||
|
file << content.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user