Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a linux dockerfile... #19

Closed
anthraxn8b opened this issue Sep 2, 2018 · 6 comments
Closed

Creating a linux dockerfile... #19

anthraxn8b opened this issue Sep 2, 2018 · 6 comments

Comments

@anthraxn8b
Copy link

anthraxn8b commented Sep 2, 2018

Currently I use this issue for "parking" my current status.

FROM haskell:7.10.3 AS build-tttool

RUN mkdir /project
WORKDIR /project

RUN apt-get -y update      && \
    apt-get -y install git

RUN git -c http.sslVerify=false clone https://github.com/entropia/tip-toi-reveng.git tttool
WORKDIR /project/tttool

RUN cabal update
RUN cabal install --only-dependencies && \
    cabal install --bindir=.

###################################################################################################
FROM perl:5.28.0 AS build-ttmp32gme

RUN \
    cpan -i    Log::Log4perl && \
    cpan -i    common::sense && \
    cpan -i    Canary::Stability && \
    cpan -i    EV && \
    cpan -i    inc::latest && \
    cpan -i    AnyEvent && \
    cpan -i -f AnyEvent::Util && \
    cpan -i    Path::Class && \
    cpan -i -f Cwd && \
    cpan -i    File::Basename && \
    cpan -i    File::Find && \
    cpan -i    List::MoreUtils && \
    cpan -i    PAR && \
    cpan -i    Encode && \
    cpan -i    Text::Template && \
    cpan -i    JSON::XS && \
    cpan -i    URI::Escape && \
    cpan -i    Getopt::Long && \
    cpan -i    Perl::Version && \
    cpan -i    DBI && \
    cpan -i    DBIx::MultiStatementDo && \
    cpan -i    Log::Message::Simple && \
    cpan -i    Test::Pod && \
    cpan -i    Locale::Country && \
    cpan -i    Ref::Util::XS && \
    cpan -i    MIME::Charset && \
    cpan -i    Role::Tiny && \
    cpan -i    Role::Tiny::With && \
    cpan -i    Sub::Quote && \
    cpan -i    Class::Data::Inheritable && \
    cpan -i    Exception::Class && \
    cpan -i    Specio && \
    cpan -i    Test2::Plugin::NoWarnings && \
    cpan -i    Test2::Require::Module && \
    cpan -i    Test2::V0 && \
    cpan -i    Test::Without::Module && \
    cpan -i    IPC::Run3 && \
    cpan -i    Test2::Bundle::Extended && \
    cpan -i    Test2::Require::Module && \
    cpan -i    Importer && \
    cpan -i    Module::Pluggable && \
    cpan -i    Scope::Guard && \
    cpan -i    Sub::Info && \
    cpan -i    Term::Table && \
    cpan -i    Test2::API && \
    cpan -i    Class::Inspector && \
    cpan -i    File::ShareDir && \
    cpan -i -f IPC::System::Simple && \
    cpan -i    Params::ValidationCompiler && \
    cpan -i    Specio::Declare && \
    cpan -i    Specio::Library::String && \
    cpan -i    Capture::Tiny && \
    cpan -i    Class::Tiny && \
    cpan -i    Path::Tiny && \
    cpan -i    Test::utf8 && \
    cpan -i    Test::File && \
    cpan -i    File::Copy::Recursive && \
    cpan -i    Test::File::ShareDir::Dist && \
    cpan -i    namespace::autoclean && \
    cpan -i    DateTime::Locale && \
    cpan -i    Class::Singleton && \
    cpan -i    DateTime::TimeZone && \
    cpan -i    Params::ValidationCompiler && \
    cpan -i    Specio && \
    cpan -i    Specio::Declare && \
    cpan -i    Specio::Exporter && \
    cpan -i    Specio::Library::Builtins && \
    cpan -i    Specio::Library::Numeric && \
    cpan -i    Specio::Library::String && \
    cpan -i    Date::Parse && \
    cpan -i    DateTime && \
    cpan -i    Class::Factory::Util && \
    cpan -i    DateTime::Format::Strptime && \
    cpan -i    Params::Validate && \
    cpan -i    DateTime::Format::Builder && \
    cpan -i    Test::MockTime && \
    cpan -i    Test::NoWarnings && \
    cpan -i    DateTime::Format::Flexible && \
    cpan -i    Set::Infinite && \
    cpan -i    DateTime::Set && \
    cpan -i    DateTime::Event::Recurrence && \
    cpan -i    DateTime::Event::ICal && \
    cpan -i    DateTime::Format::ICal && \
    cpan -i    Clone && \
    cpan -i    boolean && \
    cpan -i    Module::Util && \
    cpan -i    Carp::Clan && \
    cpan -i    Bit::Vector && \
    cpan -i    Date::Calc && \
    cpan -i    DateTime::Format::Natural && \
    cpan -i    Algorithm::Diff && \
    cpan -i    Text::Diff && \
    cpan -i    Test::Differences && \
    cpan -i    Test::Warn && \
    cpan -i    Data::Dumper::Names && \
    cpan -i    Test::Most && \
    cpan -i    Config::Options && \
    cpan -i    DateTimeX::Easy && \
    cpan -i    Digest::SHA1 && \
    cpan -i    File::Slurp && \
    cpan -i    Readonly && \
    cpan -i    Text::Unaccent::PurePerl && \
    cpan -i    MP3::Info && \
    cpan -i    MP3::Tag && \
    cpan -i -f Music::Tag::Test && \
    cpan -i -f Music::Tag::MP3 && \
    cpan -i -f Ogg::Vorbis::Header::PurePerl && \
    cpan -i -f Music::Tag::OGG && \
    cpan -i    Error && \
    cpan -i    Cache::FileCache && \
    cpan -i    Text::Levenshtein && \
    cpan -i    Mojolicious && \
    cpan -i -f WebService::MusicBrainz && \
    cpan -i -f Music::Tag::MusicBrainz && \
    cpan -i    Log::Dispatch && \
    cpan -i    Test::Inter && \
    cpan -i    Date::Manip && \
    cpan -i    Log::Dispatch::FileRotate && \
    cpan -i    Log::Log4perl && \
    cpan -i    Music::Tag::Auto && \
    cpan -i    Image::Base && \
    cpan -i    XML::NamespaceSupport && \
    cpan -i    XML::SAX::Base && \
    cpan -i    Encode::Locale && \
    cpan -i    HTTP::Date && \
    cpan -i    File::Listing && \
    cpan -i    HTML::Tagset && \
    cpan -i    IO::HTML && \
    cpan -i    LWP::MediaTypes && \
    cpan -i    HTML::Entities && \
    cpan -i    HTTP::Cookies && \
    cpan -i    HTTP::Daemon && \
    cpan -i    HTTP::Negotiate && \
    cpan -i    Net::HTTP && \
    cpan -i    Test::RequiresInternet && \
    cpan -i    WWW::RobotRules && \
    cpan -i    LWP::UserAgent && \
    cpan -i    XML::Parser && \
    cpan -i    XML::SAX && \
    cpan -i    XML::SAX::Base && \
    cpan -i    XML::SAX::Exception && \
    cpan -i    XML::SAX::Expat && \
    cpan -i    Image::Info && \
    cpan -i    AnyEvent::HTTP && \
    cpan -i    Object::Event && \
    cpan -i -f AnyEvent::HTTPD && \
    cpan -i -f WebService::MusicBrainz::Artist

COPY --from=build-tttool /project/tttool/tttool /bin/

RUN mkdir /project && \
    chown nobody:nogroup /project && \
    cd /project && \
    git -c http.sslVerify=false clone https://github.com/thawn/ttmp32gme.git ttmp32gme

COPY config_anyhost.sqlite /project/ttmp32gme/src/config.sqlite

RUN cpan -i PAR::Packer
WORKDIR /project/ttmp32gme/src/
RUN pp -o /bin/ttmp32gme ttmp32gme.pl
# TODO: Try to use the created executable instead of the script.

RUN useradd -ms /bin/bash executor
USER executor
RUN mkdir ~/.ttmp32gme

WORKDIR /project/ttmp32gme/src/

EXPOSE 10020

ENTRYPOINT ["perl", "ttmp32gme.pl"]

Build it like this:

sudo docker build -t ttmp32gme .

Start it like this:

sudo docker run -p 8081:10020 -it ttmp32gme
@thawn
Copy link
Owner

thawn commented Sep 3, 2018

A docker image for ttmp32gme sounds great! Would you be willing to share the docker image with other users?

Regarding your questions:
a) building (i.e. creating an executable binary) is indeed not supported for linux. Instead ttmp32gme is meant to be run as a normal perl script. Therefore, you need to change the last two RUN lines to cd ttmp32gme/src && perl ttmp32gme.pl. The buildit.pl script is only meant for building the mac and windows binaries (hence the report of missing Win32/Exe.pm)

You also need to install tttool and ffmpeg within the container and make sure that they are on the PATH (you could try to use the statically linked binaries from the ttmp32gme/lib/mac directory but I never tried them under linux.

Finally, you will need to make sure the container exposes port 10020 to the host.

I updated the installation instructions to be a bit more comprehensive - thanks for providing the incentive ;-)

b) I also had to add the -f options to install some of the perl modules. Most likely the respective modules are simply not maintained well. They did what I needed them to so I did not worry about it...

Let me know if it works or if you need more help.

@anthraxn8b anthraxn8b changed the title For perl noobs it would be great to get a detailed build explenation Creating a linux dockerfile... Sep 4, 2018
@anthraxn8b
Copy link
Author

Hi! I currently have the problem of accessing the service from the outer world. It seems as if the server only allows connections from within localhost - which will not work :-) How do I configure the server to accept connections on all network interfaces?

@thawn
Copy link
Owner

thawn commented Sep 5, 2018

@anthraxn8b You need to set the host config parameter to 0.0.0.0.
Because you cannot access the web interface within the container, I attach a modified config.sqlite file where that parameter is already changed.
Extract the zip file, rename the config_anyhost.sqlite to config.sqlite and move it to ttmp32gme/src within the container. Within the container remove the ~/.ttmp32gme folder (note the dot at the beginning of the folder name; this is the folder containing the configuration and library) in order to make sure that the modified config is used.
Hope this solves the issue.

@anthraxn8b
Copy link
Author

@thawn THX! I replaced the file and the service is reachable (not tested any kind of functionality yet...).
Now I have to install ffmpeg and I will try to use the created executable (by pp) and to minimize the image.

@thawn
Copy link
Owner

thawn commented Sep 6, 2018

@anthraxn8b if you create an executable with pp, I don't understand why you would need a docker image. pp does something very similar to a docker image: the pp executable contains a perl interpreter and all required perl modules. Therefore, a pp executable should run on any linux system (if you include all necessary binaries and libraries, it would not even need dependencies). Also, creating the pp executable is not so trivial because you need to include several libraries and binaries (check the buildit.pl for how I did that for windows and mac).
Of course it is up to you how you do this but I would recommend to create either a docker image or a pp executable.

  1. The docker image could be based on a perl docker image (and thus does not need to include perl itself because docker will dynamically install the perl image as needed) and only include the necessary perl modules, tttool, ffmpeg and the ttmp32gme source files. From the ttmp32gme directory you only need the src subdirectory. you don't need the 'lib' directory, it only contains the tttool and ffmpeg binaries for mac and windows you can also delete the .git directory which should save you >200MB of space. That way, the resulting docker image should be ~50MB.
  2. You could include the binary for tttool in the pp executable. That way the executable would only depend on libc6, libxml2, zlib and ffmpeg. In principle, you could even include statically linked versions of these libraries into the executable but these libraries are available on all distros and thus easily installed as dependencies the resulting pp executable would be ~50mB (including all libraries) or ~6mb (without libraries).

Since you seem to be are already there with the docker image, I recommend you go with 1. and simply clean up the docker image :)

@thawn
Copy link
Owner

thawn commented Apr 25, 2019

We now have a docker image. thanks to @maystar!

@thawn thawn closed this as completed Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants