Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions perl/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 /

Expand Down
9 changes: 9 additions & 0 deletions perl/builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions perl/examples/sourcepkg/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
cpanm -n $(cat ${SRC_PKG}/modules) -l ${SRC_PKG} && cp -r ${SRC_PKG} ${DEPLOY_PKG}


14 changes: 14 additions & 0 deletions perl/examples/sourcepkg/demo.pl
Original file line number Diff line number Diff line change
@@ -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'));
};


1 change: 1 addition & 0 deletions perl/examples/sourcepkg/modules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MIME::Base64
15 changes: 15 additions & 0 deletions perl/server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Getopt::Args;
use Plack::Handler::Twiggy;
use JSON;

opt codepath => (
isa => 'Str',
Expand Down Expand Up @@ -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);
};
Expand Down