Learn

Learn about latest technology

Build

Unleash your talent and coding!

Share

Let more people use it to improve!
 
Mostrando entradas con la etiqueta cassandra. Mostrar todas las entradas
Mostrando entradas con la etiqueta cassandra. Mostrar todas las entradas

Making available an Unscanned Cassandra image from the official docker file

miércoles, 21 de noviembre de 2018

I want to make here a constructive criticism, make thing easy please to all companies that work in open source environment. We make to many thing for free but that not mean that it shouldn't be almost(not completely) perfect.

The problem to solve in this post is that when I want to create a Cassandra ver 3.7 Image from the Oficial Docker file, the process fail and when I take a look in internet too many people are facing the same problem. So the docker file is wrong in that version an in others.

I have tested Cassandra Docker Hub repository and its true that we can build our images from his sources docker files BUT quite well just only few of them (see image below).

If you want to pull Cassandra image and spin up containers it can be done with almost all Cassandra versions. You can take a look, there are Scanned and Unscanned images and if you try to build images from source and the tag that you want to build image from is an Unscanned images perhaps you will face too many troubles.

I gonna try with Cassandra 3.7 and the first thing that I am going to do is follow the instructions described in the Cassandra github repository about its docker file template and surprisingly we get an Error or even using the dockerfile Cassandra version  3.7 we face the same error, see image below.


So in a best case when I construct the image changing the Debian's suite  I have to refactor it because the image can be can be built it BUT  the cqlsh tool cannot be accessed, see image below.


You can dive into github post  that explain how other Unscanned  Cassandra versions are facing the same problem when you try to create image from docker file.

Any way is frustrating after to many hours trying, so finally we refactored the image for solve the problems with openjdk-8-jre-headless adding to the official image the following snapshot of code:

RUN { \
  echo 'Package: openjdk-* ca-certificates-java'; \
  echo 'Pin: release n=*-backports'; \
  echo 'Pin-Priority: 990'; \
 } > /etc/apt/preferences.d/java-backports

You can find the solution for several version of cassandra docker files images in case that you want to build images from source in Cassandra version (3.9 - 3.10) that's the code that I have indicated previously.

You can find all the source code of Cassandra's image ver 3.7 in my github repository. We have tested it but if you have any problems please send us a feedback.

For many reason we should need to build an Official image from its sources for example is we need to add a layer to the image for Liveness and Readiness Probes in case of we want orchestrate our container with Kubernetes, it is not an obligation it is just a good practice. You can face the same situation in Docker when you are defining your Docker Compose yaml file. In next posts I am going to explain how deal with it.





Relationship between docker-cqlsh-cassandra

martes, 17 de julio de 2018


We have the most simplest architecture, two docker images/containers.  One of them with a Cassandra db and the other one contain an application(in my case Scala-Akka apps) could be any apps in any language but with ONE important exception our apps are using in his processes the CQLsh tool and specifically CQLsh tool - COPY FROM/TO.
zzz
In the above structure when the problems arise? The Application hosted in Container - II have some scripts and functions that make use of CQLsh tool for IMPORT FROM CVS file to Cassandra db(Container - I).

The main aspects in our lab:

Cassandra versions tested for us(From Official Repository)(Container - I):
  • 3.11.1
  • 3.7
  • 3.1.1
  • 3.2
CQL version: 3.4.+(Container - I)(Container - II)

When CQL version is not compatible you can add the following parameter( it is not recommended ):
  • cqlversion=Change cqlversion and use the  Database's cqlversion you want connect to
containerId=Container Id where is hosted Cassandra Database

We need to know from where is listening Cassandra (listen_address)  ref. Cassandra configuration file:
  • container_ip_address_where_is_cassandra=sudo docker inspect containerId -f '{{.NetworkSettings.IPAddress}}'
You ought define container_ip_address_where_is_cassandra, Cassandra listen_address  property as a OS Environment variable.

cqlsh --cqlversion=cql_version_compatible  listen_address

You can use the default port(9042) or any other if you change the configuration in cassandra.yaml

And the proper Docker File for CQLsh installation in our Container - II ought be:

1
2
3
4
5
6
7
8
..........
# Installing python
RUN apt-get update; \
  apt-get install -y python curl
# Installing cqlsh
RUN bash -c "python <(curl https://bootstrap.pypa.io/get-pip.py)"; \
  pip install cqlsh
...........
code. 1

The above(code. 1) is an snapshot of the Docker file part that make the cqlsh installation.

What can be done with this installation:
- create keyspaces
- create tables
- select
 
But the above installation does not encompass TWO important commands:

- COPY TO
- COPY FROM

When database is in different servers you use to get this mistake:

<stdin>:2:'module' object has no attribute 'parse_options' failing with the parse_options

I have analyze both source code(CQLsh from Cassandra and CQLsh from Python pip installation[pip in code. 1] ) and are different as well as the way that each code tackle the parse_options. You can have a look in CqlSh pip installation source code and the Cassandra cqlsh tool in your Cassandra container in  /usr/bin/cqlsh.py.

That is why if we need to make a COPY FROM/TO with CQLsh tool above solution (code. 1) It is NOT allowed.

There are several solutions for the above problem one of them is to install the CQLsh that come with Cassandra Official Image. It will be necessary only if I need to use CQLsh - COPY FROM/TO in any other case cqlsh via pip installation (code. 1) in image/CONTAINER II is good enough.

So My CQLsh Tool installation is from Cassandra Installation(ref. Cassandra versions tested):

Where the libraries in the Cassandra installation ver 3.7 - 3.11 can be found:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# cassandra download and run cassandra image 
docker run --name cassandra_image_37 -d cassandra:3.7

# copy python libraries from cassandra container
sudo docker cp cassandra_image_37:/usr/lib/python2.7 .

# cassandra libraries from cassandra container
sudo docker cp cassandra_image_37:/usr/share/cassandra .

# cqlsh python src and phyton shell script
sudo docker cp cassandra_image_37:/usr/bin/cqlsh .
sudo docker cp cassandra_image_37:/usr/bin/cqlsh.py .

# python bash from cassandra container
sudo docker cp cassandra_image_37:/usr/bin/python2.7 .

# open ssl libraries from cassandra container
sudo docker cp cassandra_image_37:/usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 .

# cripto libraries from cassandra container
sudo docker cpcassandra_image_37:/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 .

Project for create the image with java base + scala and CQLsh tools for execute COPY FROM or COPY TO can be found in my github project.

These architecture is valid only for images that are living in the same Docker. In the same way we run containers  in the same Docker which is very easy to inspect. You can include Docker Machine and config the docker-compose.yml properly if you want to work with more replicas. Another different thing is when we are talking about orchestration (swarm, kubernetes, etc) and the communication between different machines/pods.