diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..e99980d8bc7e5398a7be118efc0651b8f6286ab5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM alpine:latest AS dev +MAINTAINER Mose Schmiedel + +RUN apk update && apk add \ + pkgconf \ + musl \ + make \ + g++ \ + wget \ + perl \ + perl-dev \ + perl-app-cpanminus \ + gd-dev \ + expat-dev \ + graphviz \ + readline-dev \ + krb5-dev \ + openssl \ + openssl-dev \ + zlib-dev \ + sqlite \ + perl-dbd-sqlite \ + perl-dbd-sqlite-dev \ + && true + +WORKDIR /usr/src/coocook + +COPY cpanfile . + +RUN cpanm --notest --installdeps --with-recommends --with-suggests --with-develop . + +COPY script/coocook_docker.pl script/coocook_docker.pl + +ENTRYPOINT [ "script/coocook_docker.pl" ] + +EXPOSE 3000 + +CMD [ "help" ] diff --git a/README.md b/README.md index 08a8dfa931eb607625ccd462d14fb953586d12ef..b0808f7669925dd80935866d9b5922af556f2aa0 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Web application for collecting recipes and making food plans ## Quick start +### Run with native Perl (works best on Unix-like Operating Systems) Prerequisites: * [Perl5](https://www.perl.org/get.html) @@ -57,6 +58,9 @@ Install database into a local SQLite file and start development server in debug Hint: With the `--restart` option the development server restarts automatically when files in `lib/` are changed. This requires `Catalyst::Restarter`. +### Using Docker +Goto [https://hub.docker.com/r/coocook/coocook-dev](https://hub.docker.com/r/coocook/coocook-dev) and follow the instructions there to use the Dockerimage for Development. + ## Mailing list * diff --git a/cpanfile b/cpanfile index e8c9d7f002fce83f58c276f7be741e863f8379cb..17571e11ea73aa3e6c1448fb5a015048005d99c5 100644 --- a/cpanfile +++ b/cpanfile @@ -104,4 +104,5 @@ on 'develop' => sub { recommends "Catalyst::Plugin::StackTrace" => "0"; recommends "Catalyst::Restarter" => "0"; recommends "CatalystX::LeakChecker" => "0"; + recommends "Term::Size::Any" => "0"; }; diff --git a/dist.ini b/dist.ini index 4cd6a27790b19d1a909fd9b97f78cb462fb54cc7..c611ce0131d3e9c76cf058ff39550eb8e07c9f73 100644 --- a/dist.ini +++ b/dist.ini @@ -58,6 +58,7 @@ Test::Pod::Coverage = 0 Catalyst::Plugin::StackTrace = 0 Catalyst::Restarter = 0 CatalystX::LeakChecker = 0 +Term::Size::Any = 0 [Prereqs / Suggests] Sys::Hostname::FQDN = 0 diff --git a/script/coocook_docker.pl b/script/coocook_docker.pl new file mode 100755 index 0000000000000000000000000000000000000000..f77b039d44afc5d60d6a056fbef593ea646ec77b --- /dev/null +++ b/script/coocook_docker.pl @@ -0,0 +1,170 @@ +#!/usr/bin/env perl + +# ABSTRACT: helper script to control the coocook instance inside a Dockerimage from the host OS + +use v5.30.0; +use strict; +use warnings; +use utf8; +use sigtrap qw/die normal-signals/; + +use Term::ANSIColor; +use File::Basename; +use Cwd 'abs_path'; +use Getopt::Long; +Getopt::Long::Configure("bundling"); + +# Directory where current script is located used to find other Coocook scripts +my $dir = abs_path( dirname(__FILE__) ); + +my $install = ''; +my $upgrade = ''; +my $debug = ''; +my $restart = ''; + +GetOptions( + 'install' => \$install, + 'upgrade' => \$upgrade, + 'debug' => sub { $debug = '--debug' }, + 'restart' => sub { $restart = '--restart' }, +) or exit(1); + +if ( defined $ARGV[0] ) { + if ( $ARGV[0] eq 'deploy' ) { + if ( $install and not $upgrade ) { + deploy('install'); + + } + elsif ( $upgrade and not $install ) { + deploy('upgrade'); + + } + elsif ( $install and $upgrade ) { + error("'--install' and '--upgrade' may not be used together."); + help(); + + } + else { + say error("'$ARGV[1]' is not a valid flag for command 'deploy'."); + say help(); + exit(1); + } + + } + elsif ( $ARGV[0] eq 'serve' ) { + if ( defined $ARGV[1] ) { + say error("'$ARGV[1]' is not a valid flag for command 'serve'"); + say help(); + exit(1); + + } + else { + server("$debug $restart"); + } + + } + elsif ( $ARGV[0] eq 'help' ) { + if ( defined $ARGV[1] ) { + usage( $ARGV[1] ); + exit(); + + } + else { + usage('commands'); + exit(); + + } + + } + else { + say error("'$ARGV[0]' is not a valid command for $0."); + say help(); + exit(1); + } + +} +else { + say warning( "You provided no command to run. You probably meant to run " + . colored( "'$0 serve --debug --reload'", 'blue' ) + . '?' ); + say help(); + exit(1); + +} + +sub deploy { + my $flags = shift; + + system "$dir/coocook_deploy.pl " . $flags; +} + +sub server { + my $flags = shift || ''; + + system "$dir/coocook_server.pl " . $flags; +} + +sub error { + my $msg = shift; + + return colored( 'ERROR:', 'red' ) . " $msg"; +} + +sub warning { + my $msg = shift; + + return colored( 'WARNING:', 'yellow' ) . " $msg"; +} + +sub usage { + my $command = shift; + my %help = ( + commands => qq{Usage: + $0 [command] [flags] + + CLI Tool for managing Coocook instances. + + Commands: + + deploy Manage the database of the Coocook instance + serve Run the local development server + help Display this and exit + help [command] Display help for specific command + }, + + deploy => qq{Usage: + $0 deploy [flags] + + Manage the database of the Coocook instance. + + flags: + + -i --install create new database + -u --upgrade upgrade existing database to fit new schema + }, + + serve => qq{Usage: + $0 serve [flags] + + Run the local development server. + + flags: + + -d --debug Enable debug output + -r --restart Enable live reload when files are changed + }, + help => qq{Usage: + $0 help [command] + + Display help for specific command. + }, + ); + + defined $help{$command} or say error("$command is not a valid command for $0.") and exit(1); + + say $help{$command}; +} + +sub help { + return "You can use " . colored( "'$0 help'", 'blue' ) . " to get help on how to use this script."; +}