Changed crystal template, picked latest flask one
This commit is contained in:
38
template/crystal/Dockerfile
Normal file
38
template/crystal/Dockerfile
Normal 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"]
|
7
template/crystal/function/handler.cr
Normal file
7
template/crystal/function/handler.cr
Normal file
@ -0,0 +1,7 @@
|
||||
require "json"
|
||||
|
||||
class Handler
|
||||
def run(req : String)
|
||||
return JSON::Any.new("Hello, Crystal. You said: #{req}")
|
||||
end
|
||||
end
|
7
template/crystal/function/shard.yml
Normal file
7
template/crystal/function/shard.yml
Normal 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
11
template/crystal/main.cr
Normal 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
|
6
template/crystal/template.yml
Normal file
6
template/crystal/template.yml
Normal 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
|
Reference in New Issue
Block a user