From 894da5ff613f50a50fcb26fcf6c8d09d953b0bf4 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Fri, 28 Jun 2024 19:15:42 -0300 Subject: [PATCH] Make work push ok, more log --- examples/hello_cr/function.cr | 4 ++-- src/faaso.cr | 13 +++++++------ templates/crystal/Dockerfile | 3 ++- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/hello_cr/function.cr b/examples/hello_cr/function.cr index 1ebbbf9..8625475 100644 --- a/examples/hello_cr/function.cr +++ b/examples/hello_cr/function.cr @@ -1,3 +1,3 @@ get "/" do - "Hello World!" -end \ No newline at end of file + "Hello World from Crystal!" +end diff --git a/src/faaso.cr b/src/faaso.cr index cc4d1cd..053f833 100644 --- a/src/faaso.cr +++ b/src/faaso.cr @@ -20,22 +20,23 @@ module Faaso def run @arguments.each do |arg| - puts "Building function... #{arg}" # A function is a folder with stuff in it # TODO: decide template based on file extensions or other metadata template = "templates/crystal" - # TODO: copy template and add function files to it 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" FileUtils.cp_r(template, tmp_dir) Dir.glob(arg + "/**/*").each do |file| FileUtils.cp(file, tmp_dir) end - # TODO: build Docker image docker_api = Docr::API.new(Docr::Client.new) - docker_api.images.build(context: tmp_dir, tags: ["func"]) { } - # TODO: push Docker image to registry - # TODO: return image name for testing + docker_api.images.build(context: tmp_dir, tags: [tag, "#{slug}:latest"]) { } + puts "Pushing to repo as #{tag}" + docker_api.images.tag(repo: repo, name: slug, tag: "latest") end end end diff --git a/templates/crystal/Dockerfile b/templates/crystal/Dockerfile index 44fbefb..366e83d 100644 --- a/templates/crystal/Dockerfile +++ b/templates/crystal/Dockerfile @@ -6,7 +6,8 @@ WORKDIR /home/app COPY shard.yml *.cr ./ RUN shards install -RUN shards build +RUN shards build --release +RUN strip bin/* FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as ship RUN apk update && apk upgrade && apk add openssl pcre2 libgcc gc libevent && apk cache clean