如何在alpine docker上安装一个工作的perl cassandra客户机

wwtsj6pe  于 2021-06-10  发布在  Cassandra
关注(0)|答案(2)|浏览(754)

在alpine docker上运行的perl-cassandra客户端最好是哪一个&如何安装和使用它?
请提供docker文件或至少docker命令和连接到cassandra的poc脚本。
下面是使用dbd::cassandra库的最新尝试docker文件实际上成功完成并部署了get:

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.
7nbnzgx9

7nbnzgx91#

通过以下调整,我成功地构建了附加的dockerfile:
为了 /bin/cpanm ,使用alpine的本机包perl app cpanminus: RUN apk add --no-cache perl-app-cpanminus (而不是手动下载 cpanm 二进制-这是一个特殊的定制版本吗?)
musl obstack dev已从 edge/testingedge/main 存储库: RUN apk add --no-cache musl-obstack-dev --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main

of1yzvn4

of1yzvn42#

经过两天的摆弄,我来到了这个码头:

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);
}

相关问题