docker - 如何在 alpine docker 上安装有效的 Perl Cassandra 客户端
问题描述
哪个是在 Alpine docker 上运行的最佳 perl Cassandra 客户端以及如何安装和使用它?
请提供一个 docker 文件或至少 docker 命令和一个连接到 Cassandra 的 POC 脚本。
这是使用 DBD::Cassandra 库的最新尝试,docker 文件实际上已成功完成并已部署:
FROM alpine:3.10.3
## alpine curl and wget aren't fully compatible, so we install them
## here. gnupg is needed for Module::Signature.
RUN apk update && apk upgrade
RUN apk add --no-cache curl tar make gcc build-base wget gnupg ca-certificates g++ git gd-dev
RUN apk add --no-cache zlib zlib-dev
RUN apk add --no-cache perl perl-dev
RUN apk add --no-cache perl-app-cpanminus
RUN cpanm App::cpm
WORKDIR /usr
RUN cpm install Try::Tiny
RUN cpm install YAML
RUN cpm install JSON
RUN cpm install JSON::MaybeXS
RUN cpm install HTTP::Request
RUN cpm install HTTP::Response
RUN cpm install HTTP::Daemon
RUN cpm install GD::Simple
RUN cpm install GD::Graph
RUN cpm install Data::HexDump::Range
RUN cpm install Proc::Daemon
RUN cpm install Test::Block
RUN cpm install Text::Colorizer
RUN cpm install Gzip::Faster
ENV PERL5LIB=/usr/local/lib/perl5
ENV PATH=/usr/local/bin:$PATH
RUN apk add --no-cache musl-obstack-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
RUN cpm install Proc::ProcessTable
RUN cpm install Kafka::Connection
RUN apk add --update openssl && \
rm -rf /var/cache/apk/*
#RUN cpm install DBI
RUN cpm install DBD::Cassandra
COPY run.sh /run.sh
RUN chmod +x "/run.sh"
RUN mkdir -p /code_path
WORKDIR /code_path
CMD ["/run.sh"]
这是脚本:
use Data::Dumper;
use DBD::Cassandra;
use DBI;
say("Mama");
my $user = undef;
my $password = undef;
my $host = 'cassandra.cassandra.svc.cluster.local';
my $keyspace = 'grids';
my $table = 'electricity_grid';
my $dbh = DBI->connect("dbi:Cassandra:host=$host;keyspace=$keyspace", $user, $password, { RaiseError => 1 });
my $rows = $dbh->selectall_arrayref("SELECT * FROM $table");
for my $row (@$rows) {
# Do something with your row
say($row);
}
但代码示例不起作用,就好像没有安装库一样:
bash-5.0# ./demoCassandra.pl
Can't locate DBD/Cassandra.pm in @INC (you may need to install the
DBD::Cassandra module) (@INC contains: /usr/local/lib/perl5/5.28.2/x86_64-linux-thread-multi /usr/local/lib/perl5/5.28.2 /usr/local/lib/perl5/x86_64-linux-thread-multi /usr/local/lib/perl5 /usr/local/lib/perl5/site_perl /usr/local/share/perl5/site_perl /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/share/perl5/core_perl) at ./demoCassandra.pl line 7.
BEGIN failed--compilation aborted at ./demoCassandra.pl line 7.
这是一个古老的尝试:由于下面@valiano 的答案的相关性,我将它放在这里。
我发现的最新库是: DBD::Cassandra 所以我尝试在 alpine docker 上安装 perl DBD::Cassandra 这失败了:
cpm install DBD::Cassandra
阅读日志后我成功安装
cpm install IO::Socket::INET6
并且安装失败
cpm install OpenSSL
这是基本文件:
FROM alpine:3.10.3
## alpine curl and wget aren't fully compatible, so we install them
## here. gnupg is needed for Module::Signature.
RUN apk update && apk upgrade
RUN apk add --no-cache curl tar make gcc build-base wget gnupg ca-certificates g++ git gd-dev
RUN apk add --no-cache zlib zlib-dev
RUN apk add --no-cache perl perl-dev
RUN curl -L <this was cencored by stack overflow>cpanm > /bin/cpanm && chmod +x /bin/cpanm
RUN cpanm App::cpm
WORKDIR /usr
RUN cpm install Try::Tiny
RUN cpm install YAML
RUN cpm install JSON
RUN cpm install JSON::MaybeXS
RUN cpm install HTTP::Request
RUN cpm install HTTP::Response
RUN cpm install HTTP::Daemon
RUN cpm install GD::Simple
RUN cpm install GD::Graph
RUN cpm install Data::HexDump::Range
RUN cpm install Proc::Daemon
RUN cpm install Test::Block
RUN cpm install Text::Colorizer
RUN cpm install Gzip::Faster
ENV PERL5LIB=/usr/local/lib/perl5
ENV PATH=/usr/local/bin:$PATH
RUN apk add --no-cache musl-obstack-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing
RUN cpm install Proc::ProcessTable
RUN cpm install Kafka::Connection
COPY run.sh /run.sh
RUN chmod +x "/run.sh"
RUN mkdir -p /code_path
WORKDIR /code_path
CMD ["/run.sh"]
输出失败文件指示 IO::Socket::INET6 OpenSSL 丢失:
bash-5.0# tail /root/.cpanm/work/1582818617.3526/build.log
/usr/include/openssl/bn.h:332:1: note: declared here
DEPRECATEDIN_0_9_8(int
^~~~~~~~~~~~~~~~~~
OpenSSL.xs: In function 'boot_OpenSSL':
OpenSSL.xs:854:9: warning: implicit declaration of function 'SSL_load_error_strings'; did you mean 'ERR_lib_error_string'? [-Wimplicit- function-declaration]
SSL_load_error_strings();
^~~~~~~~~~~~~~~~~~~~~~
ERR_lib_error_string
make: *** [Makefile:353: OpenSSL.o] Error 1
-> FAIL Installing OpenSSL failed. See /root/.cpanm/work/1582818617.3526/build.log for details. Retry with --force to force install it.
解决方案
经过两天的摆弄,我到达了这个 dockerfile:
FROM alpine:3.10.3
MAINTAINER hamshif
## alpine curl and wget aren't fully compatible, so we install them
## here. gnupg is needed for Module::Signature.
RUN apk update && apk upgrade
RUN apk add --no-cache curl tar make gcc build-base wget gnupg ca-certificates g++ git gd-dev
RUN apk add --no-cache zlib zlib-dev
RUN apk add --no-cache perl perl-dev
RUN apk add --no-cache perl-app-cpanminus
RUN cpanm App::cpm
WORKDIR /usr
RUN cpm install Try::Tiny
RUN cpm install YAML
RUN cpm install JSON
RUN cpm install JSON::MaybeXS
RUN cpm install HTTP::Request
RUN cpm install HTTP::Response
RUN cpm install HTTP::Daemon
RUN cpm install GD::Simple
RUN cpm install GD::Graph
RUN cpm install Data::HexDump::Range
RUN cpm install Proc::Daemon
RUN cpm install Test::Block
RUN cpm install Text::Colorizer
RUN cpm install Gzip::Faster
ENV PERL5LIB=/usr/local/lib/perl5
ENV PATH=/usr/local/bin:$PATH
RUN apk add --no-cache musl-obstack-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
RUN cpm install Proc::ProcessTable
RUN cpm install Kafka::Connection
RUN apk add --update openssl
RUN apk add --update openssl-dev
RUN cpm install IO::Socket::INET6
RUN cpm install Net::SSLeay
#RUN cpm install Cassandra::Client
RUN cpm install https://cpan.metacpan.org/authors/id/T/TV/TVDW/Cassandra-Client-0.10.tar.gz
RUN cpm install DBI
RUN cpm install DBD::Cassandra && \
rm -rf /var/cache/apk/*
COPY run.sh /run.sh
RUN chmod +x "/run.sh"
RUN mkdir -p /code_path
WORKDIR /code_path
CMD ["/run.sh"]
该脚本在 docker 中工作(在 kubernetes 桌面上):
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use feature qw/say/;
use Data::Dumper;
use XSLoader;
use Cassandra::Client;
use DBD::Cassandra;
use DBI;
say("Mama");
my $user = undef;
my $password = undef;
my $host = 'cassandra.cassandra.svc.cluster.local';
my $keyspace = 'grids';
my $table = 'electricity_grid';
my $dbh = DBI->connect("dbi:Cassandra:host=$host;keyspace=$keyspace", $user, $password, { RaiseError => 1 });
my $rows = $dbh->selectall_arrayref("SELECT * FROM $table");
for my $row (@$rows) {
# Do something with your row
say($row);
}
推荐阅读
- php - 是否可以在引导模型中包含 CSV 文件?
- ruby-on-rails - 在 Rails 中,我如何计算一个项目的使用次数?
- spring - 如何在 Spring-integration xml 中创建具有 WS-A 属性的请求
- java - 具有相同映射的两个请求
- python - 字母按字母顺序排列的可能子字符串列表。递归
- python - 如何访问 mininet 拓扑中创建的节点?
- c - C unix 中的文件配置、创建和使用
- scala - Scala:从 Runnable 返回
- javascript - 带有 formdata 的 Ajax 请求返回错误“请求实体太大”
- javascript - 为什么 Angular 文档建议在模块和组件级别导入?