Skip to content

Instantly share code, notes, and snippets.

@yaasita
Created May 19, 2020 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaasita/f17f9cea21694ddb97dfa494de91ef8b to your computer and use it in GitHub Desktop.
Save yaasita/f17f9cea21694ddb97dfa494de91ef8b to your computer and use it in GitHub Desktop.

Perl Custom Runtime for App Engine

Simple guide to running Mojolicious on Google App Engine.

  1. Create a new Mojolicious app.

  2. Create an app.yaml in the root of your application with the following contents:

    runtime: custom
    env: flex
  3. Create a Dockerfile in the root of your application.

  4. Create a project in the Google Developers Console.

  5. Make sure you have the Google Cloud SDK installed. When you're ready, initialize it:

    $ gcloud init
  6. Deploy your app:

    gcloud app deploy

You are now running Perl on Google App Engine. How cool is that?

runtime: custom
env: flex
manual_scaling:
instances: 1
# Use the latest perl image from dockerhub
FROM perl:latest
# Install the web framework mojolicious
RUN curl -L https://cpanmin.us | perl - -M https://cpan.metacpan.org -n Mojolicious
# Instruct mojolicious to listen on port 8080 and open the port
ENV MOJO_LISTEN http://*:8080
EXPOSE 8080
# add your application code and set the working directory
ADD . /app
WORKDIR /app
# change the permissions and run the application
RUN chmod +x main.pl
CMD ["./main.pl", "daemon"]
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/' => sub {
my $c = shift;
my %headers;
{
my %h = %{$c->req->headers};
$headers{method} = $c->req->method;
$headers{url} = $c->req->url;
for (keys %{$h{headers}}){
$headers{$_} = join(", ", @{$h{headers}->{$_}});
}
}
$c->render(json => \%headers);
};
app->start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment