Skip to content
Merged
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
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ RUN <<EOT
npm run build:min
EOT

HEALTHCHECK CMD [ "test", "-e", "root/assets/assets.json" ]

################### Web Server
# hadolint ignore=DL3007
FROM metacpan/metacpan-base:latest AS server
Expand Down Expand Up @@ -62,6 +64,8 @@ CMD [ \

EXPOSE 80

HEALTHCHECK --start-period=3s CMD [ "curl", "--fail", "http://localhost/healthcheck" ]

################### Development Server
FROM server AS develop

Expand Down
10 changes: 10 additions & 0 deletions lib/MetaCPAN/Web/Controller/Root.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ sub robots : Path("robots.txt") : Args(0) {
} );
}

sub healthcheck : Local : Args(0) {
my ( $self, $c ) = @_;

$c->res->content_type('application/json');
$c->stash( {
template => 'healthcheck.tx',
status => 'healthy',
} );
}

=head2 end

Attempt to render a view, if needed.
Expand Down
1 change: 1 addition & 0 deletions root/healthcheck.tx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[% { status => $status }.json() | raw %]
19 changes: 19 additions & 0 deletions t/controller/healthcheck.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use strict;
use warnings;
use lib 't/lib';

use Cpanel::JSON::XS qw( decode_json );
use MetaCPAN::Web::Test qw( app GET test_psgi );
use Test::More;

test_psgi app, sub {
my $cb = shift;
ok( my $res = $cb->( GET '/healthcheck' ), 'GET /healthcheck' );
is( $res->code, 200, 'code 200' );
is $res->header('Content-Type'), 'application/json',
'correct Content-Type';
my $data = decode_json( $res->content );
is $data->{status}, 'healthy', 'has correct status';
};

done_testing;