Docker: switch to alpinelinux and cpm
Change-Id: I78210b14a3620fcba36ee7a49f83cd5cd8acc1f3
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..9c75081
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,49 @@
+# Ignore the .git directory
+.git/
+
+# Ignore the .idea directory
+.idea/
+
+# Ignore compiled Perl files
+_Inline/
+
+# Ignore version control folders and metadata
+.gitignore
+.gitattributes
+.gitlab-ci.yml
+.gitlab-ci.local/
+.github/
+
+# Ignore the Dockerfile itself
+Dockerfile
+Dockerfile.*
+
+# Ignore test files
+t/
+test/
+*.t
+
+# Ignore Perl-specific files
+*.swp # Vim swap files
+*.bak # Backup files
+*.tmp # Temporary files
+
+# Ignore common temporary files and folders
+*.log
+*.tmp
+*.bak
+*.old
+*.orig
+
+# Ignore Perl modules installation folder (local::lib)
+local/
+
+# Ignore documentation files
+**/*.md
+
+# Ignore distribution build and packaging files
+Build/
+MYMETA.*
+Makefile
+Makefile.old
+pm_to_blib
diff --git a/.gitignore b/.gitignore
index 8107e76..1336b0e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,5 +20,4 @@
**/LOG
**/LOG.old.*
example-models/wpd19_10000/wpd19_10000.rocksdb/LOG
-
-
+!.dockerignore
diff --git a/Dockerfile b/Dockerfile
index 93f9a07..b1da33b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,28 +1,37 @@
-FROM metacpan/metacpan-api AS builder
+FROM alpine:latest AS derekovecs
-# Copy repository respecting .dockerignore
-COPY . /derekovecs
+RUN apk update && \
+ apk add --no-cache git \
+ perl \
+ perl-io-socket-ssl \
+ perl-dev \
+ perl-inline-c \
+ g++ \
+ make \
+ cmake gflags-dev snappy-dev zlib-dev zstd-dev lz4-dev bzip2-dev linux-headers \
+ curl && \
+ set -o pipefail
+
+RUN curl -fsSL https://raw.githubusercontent.com/kupietz/cpm/main/cpm > /bin/cpm && chmod a+x /bin/cpm
WORKDIR /derekovecs
-RUN apt update && apt -y install cmake libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev libzstd-dev libomp-dev
-
RUN git config --global user.email "korap+docker@ids-mannheim.de" && \
git config --global user.name "Docker"
# Install RocksDB
-RUN curl -L https://github.com/facebook/rocksdb/archive/refs/tags/v5.11.3.tar.gz | tar zx && \
- cd rocksdb-5.11.3 && \
- export PROCS=$(nproc) && \
- make -j $PROCS static_lib DISABLE_WARNING_AS_ERROR=1 WARNING_FLAGS=-w && \
- make install-static DISABLE_WARNING_AS_ERROR=1 WARNING_FLAGS=-w && \
- make -j $PROCS shared_lib DISABLE_WARNING_AS_ERROR=1 WARNING_FLAGS=-w && \
- make install-shared DISABLE_WARNING_AS_ERROR=1 WARNING_FLAGS=-w && \
- ldconfig && \
- cd ..
+RUN export PROCS=$(nproc) && \
+ git clone https://github.com/kupietz/rocksdb.git -b 5.11.fb --single-branch && \
+ cd rocksdb && \
+ mkdir -p build && \
+ cd build && \
+ cmake .. -DWITH_SNAPPY=1 -DWITH_LZ4=1 -DWITH_ZLIB=1 -DWITH_GFLAGS=1 && \
+ make -j $PROCS && \
+ make install && \
+ ln -s /usr/lib/librocksdb.so.5.11.4 /usr/lib/librocksdb.so.5.11
-
-RUN rm -rf rocksdb-5.11.3
+RUN cd /derekovecs && \
+ rm -rf rocksdb
# Install collocatordb
RUN git clone "https://korap.ids-mannheim.de/gerrit/ids-kl/collocatordb" && \
@@ -31,23 +40,33 @@
cd build && \
cmake .. && \
make && \
- make install && \
- ldconfig && \
- cd ../..
+ make install
-RUN rm -rf collocatordb
+RUN cd /derekovecs && \
+ rm -rf collocatordb
+
+COPY . .
# Install dependencies
-RUN cpanm https://github.com/Akron/Mojolicious-Plugin-Localize.git && \
- cpanm --installdeps .
-
+RUN cpm install -g https://github.com/Akron/Mojolicious-Plugin-Localize.git && \
+ cpm install -g
# Build derekovecs
RUN perl Makefile.PL && \
make && \
make install
-RUN rm -rf example-models
+# RUN MOJO_CONFIG=/derekovecs/example.conf hypnotoad -t script/derekovecs-server # Just do the Inlined::C stuff
+# does not work with slimming
+
+RUN rm -rf example-models /root/.perl-cpm
+RUN rm /bin/cpm && \
+ apk del git \
+# g++ \
+ cmake \
+ curl && \
+ rm -rf /root/.cpanm \
+ /usr/local/share/man
ENV MOJO_CONFIG=/config/derekovecs.conf
diff --git a/README.md b/README.md
index 52f44c4..437a35c 100644
--- a/README.md
+++ b/README.md
@@ -130,7 +130,7 @@
### Optional: Slim down image using [Slim(toolkit)](https://github.com/slimtoolkit/slim)
```bash
-slim build --new-expose=3000 --http-probe-ports=3000 --include-path /usr/local --mount ./example-models:/example-models:z --env MOJO_CONFIG=/example-models/example-docker.conf idscorpuslinguistics/derekovecs
+slim build --include-path /usr/local/share/perl5 --mount ./example-models:/example-models:z --env MOJO_CONFIG=/example-models/example-docker.conf idscorpuslinguistics/derekovecs
```
Will build an image `ids-kl/derekovecs.slim` reduced to ~25% of the original size.
diff --git a/script/derekovecs-server b/script/derekovecs-server
index d6fc6c5..5cd0c8d 100755
--- a/script/derekovecs-server
+++ b/script/derekovecs-server
@@ -65,9 +65,7 @@
my $title="";
my $training_args="";
-getopts('d:D:Gil:p:m:n:M:C') or usage();
-
-sub usage() {
+sub usage {
print STDERR <<EOF;
non-server mode usage: MOJO_CONFIG=`pwd`/example.conf $0 [-h] [-d <file>]
-h : this (help) message
@@ -80,6 +78,8 @@
exit;
}
+getopts('d:D:Gil:p:m:n:M:Ch') or usage();
+
if($opt_M) {
open my $handle, '<:encoding(UTF-8)', $opt_M
or die "Can't open '$opt_M' for reading: $!";