Ajeet Raina I am a Docker Captain, ARM Innovator & Docker Bangalore Community Leader. I am a maintainer of Collabnix blogging site. I work for Docker as a full-time employee. I run Collabnix Community Slack with over 6500+ audience . We have built a popular projects like Docker Labs, KubeLabs, KubeTools and DockerTools. You can follow me on Twitter(@ajeetsraina) & GitHub(@ajeetraina)

Visualize Docker Compose codebase using Pycograph

1 min read

Pycograph is an open source tool that creates a Graph model of your Python code. The tool lets you to explore your Python codebase with graph queries. With Pycograph, you can query the python code with Cypher. The project is hosted over https://pycograph.com/ and package is available in PyPI repository. It was introduced for the first time by Reka Horvath. I was lucky to be one of the contributor for this project.

Let us see how to explore Python code using Pycograph and RedisGraph below:

Step 1. Install Docker

 curl -sSL https://get.docker.com/ | sh
 

Step 2. Install Pycograph from PyPI

 pip install pycograph
 

Step 3. Start RedisGraph Module

The redislabs/redismod Docker image provides you all the essential Redis modules.

 docker run -d -p 6379:6379 redislabs/redismod
 

Step 4. Run RedisInsight

 docker run -d -v redisinsight:/db -p 8001:8001 redislabs/redisinsight:latest
 

Step 5. Load a sample Python code

We will be using a popular Docker compose project for our sample python code. Clone the Docker Compose project repository

  git clone https://github.com/docker/compose
 

Step 6. Load Python Code

Load your project’s code with the pycograph load command:

 pycograph load --project-dir compose
 

Results:

 Graph successfully updated.
{'graph name': 'compose', 'nodes added': 2428, 'edges added': 11239}
 

Step 7. Visualize the project

Open RedisInsight, select RedisGraph on the left menu and run the below query:

Query #1: Return every node

 MATCH (n) RETURN n
 

You will see the below output:

My Image

Query #2: Return every non-test object

My Image

Query #3. Displaying the function behind the docker-compose up command

A query returning exactly one node using the unique full_name property. Double-click on the node to display all its relationships.

My Image

Query #4. Displaying the ‘docker-compose up’ and its calls relationships

My Image

Query #5. Displaying the ‘docker-compose up’ vs ‘docker-compose run’

Functions called by the Docker Compose top level commands up and run

My Image

References:

 

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina I am a Docker Captain, ARM Innovator & Docker Bangalore Community Leader. I am a maintainer of Collabnix blogging site. I work for Docker as a full-time employee. I run Collabnix Community Slack with over 6500+ audience . We have built a popular projects like Docker Labs, KubeLabs, KubeTools and DockerTools. You can follow me on Twitter(@ajeetsraina) & GitHub(@ajeetraina)

Get Started with Kubernetes

Kubernetes (a.k.a K8s) is an open-source container-orchestration system which manages the containerised applications and takes care of the automated deployment, storage, scaling, scheduling, load...
Ajeet Raina
2 min read

Leave a Reply