Make work push ok, more log

This commit is contained in:
Roberto Alsina 2024-06-28 19:15:42 -03:00
parent cbbe739b82
commit 894da5ff61
3 changed files with 11 additions and 9 deletions

View File

@ -1,3 +1,3 @@
get "/" do get "/" do
"Hello World!" "Hello World from Crystal!"
end end

View File

@ -20,22 +20,23 @@ module Faaso
def run def run
@arguments.each do |arg| @arguments.each do |arg|
puts "Building function... #{arg}"
# A function is a folder with stuff in it # A function is a folder with stuff in it
# TODO: decide template based on file extensions or other metadata # TODO: decide template based on file extensions or other metadata
template = "templates/crystal" template = "templates/crystal"
# TODO: copy template and add function files to it
tmp_dir = "tmp/#{UUID.random}" tmp_dir = "tmp/#{UUID.random}"
slug = arg.gsub("/","_").strip("_")
repo = "localhost:5000"
tag = "#{repo}/#{slug}:latest"
puts "Building function... #{arg} in #{tmp_dir}"
Dir.mkdir_p("tmp") unless File.exists? "tmp" Dir.mkdir_p("tmp") unless File.exists? "tmp"
FileUtils.cp_r(template, tmp_dir) FileUtils.cp_r(template, tmp_dir)
Dir.glob(arg + "/**/*").each do |file| Dir.glob(arg + "/**/*").each do |file|
FileUtils.cp(file, tmp_dir) FileUtils.cp(file, tmp_dir)
end end
# TODO: build Docker image
docker_api = Docr::API.new(Docr::Client.new) docker_api = Docr::API.new(Docr::Client.new)
docker_api.images.build(context: tmp_dir, tags: ["func"]) { } docker_api.images.build(context: tmp_dir, tags: [tag, "#{slug}:latest"]) { }
# TODO: push Docker image to registry puts "Pushing to repo as #{tag}"
# TODO: return image name for testing docker_api.images.tag(repo: repo, name: slug, tag: "latest")
end end
end end
end end

View File

@ -6,7 +6,8 @@ WORKDIR /home/app
COPY shard.yml *.cr ./ COPY shard.yml *.cr ./
RUN shards install RUN shards install
RUN shards build RUN shards build --release
RUN strip bin/*
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as ship FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as ship
RUN apk update && apk upgrade && apk add openssl pcre2 libgcc gc libevent && apk cache clean RUN apk update && apk upgrade && apk add openssl pcre2 libgcc gc libevent && apk cache clean