diff --git a/perl/Dockerfile b/perl/Dockerfile index 12e67ce6..315ff335 100644 --- a/perl/Dockerfile +++ b/perl/Dockerfile @@ -1,7 +1,10 @@ -FROM perl:latest +FROM perl:slim as builder -RUN cpanm -n Twiggy Getopt::Args Dancer2 +RUN apt-get update ; apt-get install -y gcc +RUN cpanm -n Twiggy Getopt::Args Dancer2 JSON lib::relative +FROM perl:slim +COPY --from=builder /usr/local /usr/local COPY server.pl /server.pl WORKDIR / diff --git a/perl/builder/Dockerfile b/perl/builder/Dockerfile new file mode 100644 index 00000000..3d143db4 --- /dev/null +++ b/perl/builder/Dockerfile @@ -0,0 +1,9 @@ +FROM fission/builder as PKG +FROM perl:slim + +RUN apt-get update ; apt-get install -y gcc +RUN cpanm -n Twiggy Getopt::Args Dancer2 lib::relative && rm -rf /root/.cpan* + +COPY --from=PKG /builder /builder + +EXPOSE 8001 diff --git a/perl/examples/sourcepkg/build.sh b/perl/examples/sourcepkg/build.sh new file mode 100755 index 00000000..45163ef5 --- /dev/null +++ b/perl/examples/sourcepkg/build.sh @@ -0,0 +1,4 @@ +#!/bin/sh +cpanm -n $(cat ${SRC_PKG}/modules) -l ${SRC_PKG} && cp -r ${SRC_PKG} ${DEPLOY_PKG} + + diff --git a/perl/examples/sourcepkg/demo.pl b/perl/examples/sourcepkg/demo.pl new file mode 100755 index 00000000..6202133f --- /dev/null +++ b/perl/examples/sourcepkg/demo.pl @@ -0,0 +1,14 @@ +use lib::relative 'lib/perl5','lib/perl5/x86_64-linux-gnu'; +use MIME::Base64; + +package App::Fission::Perl; +use utf8; +use strict; +use warnings; +use Dancer2; + +return sub { + return(encode_base64('Aladdin:open sesame')); +}; + + diff --git a/perl/examples/sourcepkg/modules b/perl/examples/sourcepkg/modules new file mode 100644 index 00000000..d9c5939e --- /dev/null +++ b/perl/examples/sourcepkg/modules @@ -0,0 +1 @@ +MIME::Base64 diff --git a/perl/server.pl b/perl/server.pl index 1145f998..680a0726 100755 --- a/perl/server.pl +++ b/perl/server.pl @@ -6,6 +6,7 @@ use Getopt::Args; use Plack::Handler::Twiggy; +use JSON; opt codepath => ( isa => 'Str', @@ -37,6 +38,20 @@ return ''; }; + post '/v2/specialize' => sub { + # print STDERR request->body; + my $specialize=decode_json(request->body); + if($userfunc) { + send_error('Not a generic container', 400); + } + + if (! -f $specialize->{'filepath'}.'/'.$specialize->{'functionName'} ) { + send_error('modules does not exist. Forgot to set spec.package.functionName in Function? - file was: '.$specialize->{'filepath'}.'/'.$specialize->{'functionName'}, 400); + } + $userfunc = require($specialize->{'filepath'}.'/'.$specialize->{'functionName'}); + return ''; + }; + any '/' => sub { return $userfunc ? $userfunc->(request) : send_error('Not yet specialized', 500); };