Changed crystal template, picked latest flask one

This commit is contained in:
2023-06-01 18:52:39 -03:00
parent f2be91d628
commit 1cc3ef2e82
22 changed files with 242 additions and 112 deletions

View File

@ -0,0 +1,38 @@
FROM crystallang/crystal:1.8.0 as builder
RUN apt update \
&& apt install -y curl \
&& echo "Pulling watchdog binary from Github." \
&& curl -sSL https://github.com/openfaas/faas/releases/download/0.9.6/fwatchdog > /usr/bin/fwatchdog \
&& chmod +x /usr/bin/fwatchdog
WORKDIR /home/app
COPY . .
COPY function/shard.yml shard.yml
RUN shards install
RUN crystal build main.cr -o handler --release
FROM crystallang/crystal:1.8.0
RUN apt install ca-certificates
# Add non root user
RUN adduser app
RUN mkdir -p /home/app
WORKDIR /home/app
COPY --from=builder /usr/bin/fwatchdog .
COPY --from=builder /home/app/function/ .
COPY --from=builder /home/app/handler .
RUN chown -R app /home/app
USER app
ENV fprocess="./handler"
EXPOSE 8080
HEALTHCHECK --interval=2s CMD [ -e /tmp/.lock ] || exit 1
CMD ["./fwatchdog"]

View File

@ -0,0 +1,7 @@
require "json"
class Handler
def run(req : String)
return JSON::Any.new("Hello, Crystal. You said: #{req}")
end
end

View File

@ -0,0 +1,7 @@
name: crystal_faas_function
version: 0.1.0
# dependencies:
# pg:
# github: will/crystal-pg
# version: "~> 0.5"

11
template/crystal/main.cr Normal file
View File

@ -0,0 +1,11 @@
# Copyright (c) Thomas Peikert 2018. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
require "json"
require "./function/handler"
req = STDIN.gets_to_end
handler = Handler.new
res = handler.run req
puts res

View File

@ -0,0 +1,6 @@
language: crystal
fprocess: ./handler
welcome_message: |
You have created a new function which uses crystal 1.7.3 🎉
To include third-party dependencies, use a vendoring tool like shards:
shards documentation: https://github.com/crystal-lang/shards