<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Koray Çağlar on Medium]]></title>
        <description><![CDATA[Stories by Koray Çağlar on Medium]]></description>
        <link>https://medium.com/@koraycaglar?source=rss-7da247518445------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Yg5BqRnicgpf5d22S8aA8Q.jpeg</url>
            <title>Stories by Koray Çağlar on Medium</title>
            <link>https://medium.com/@koraycaglar?source=rss-7da247518445------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 10:24:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@koraycaglar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting up SSH connection to GitHub with Git on Linux command-line]]></title>
            <link>https://medium.com/@koraycaglar/setting-up-ssh-connection-to-github-with-git-on-linux-command-line-556692a19fbe?source=rss-7da247518445------2</link>
            <guid isPermaLink="false">https://medium.com/p/556692a19fbe</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Koray Çağlar]]></dc:creator>
            <pubDate>Mon, 24 Apr 2023 12:10:08 GMT</pubDate>
            <atom:updated>2023-04-24T12:10:08.174Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Install Git on Linux</strong></h4><p>Open the terminal, enter the command:</p><pre>sudo apt install git</pre><p>Set your user.email(or user.name):</p><pre>git config --global user.email &quot;email@example.com&quot;</pre><h4>Create a SSH key</h4><p>Enter this command to create a ssh key:</p><pre>ssh-keygen -t rsa -b 4096 -C &quot;email@example.com&quot;</pre><p>To view the key:</p><pre>cat ~/.ssh/id_rsa.pub</pre><p>Copy the code from start to finish.</p><p>Go to settings from your GitHub profile, get to the page “SSH and GPG keys”, click “New SSH key”.</p><p>Enter any title, keep key type as “Authentication Key”, paste the ssh key you just copied to the key section.</p><p><strong>Now you are authorized to push to/pull from your GitHub repos.</strong></p><h4>Testing</h4><p>Clone the repo you want to work on</p><p>Go to the repo’s page, click “Code”, copy the remote URL in the SSH tab.</p><p>Enter the command with your URL to clone the repo to your system:</p><pre>git clone git@github.com:username/reponame.git</pre><p>Navigate into the folder and set the remote origin:</p><pre>git remote set-url origin git@github.com:username/reponame.git</pre><p>Change anything in the contents, I am modifying the README.md file.</p><p>After changing something, enter the commands to push the changes:</p><pre>git add .<br>git commit -m &quot;test commit&quot;<br>git push</pre><p>Check the repo in the GitHub page to see the changes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=556692a19fbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Airflow with Docker and orchestrating tasks on GCP.]]></title>
            <link>https://medium.com/@koraycaglar/installing-airflow-with-docker-and-orchestrating-tasks-on-gcp-b679275686dd?source=rss-7da247518445------2</link>
            <guid isPermaLink="false">https://medium.com/p/b679275686dd</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[airflow]]></category>
            <dc:creator><![CDATA[Koray Çağlar]]></dc:creator>
            <pubDate>Mon, 31 Oct 2022 20:46:46 GMT</pubDate>
            <atom:updated>2022-10-31T20:46:46.652Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MrgX6Ap9TunntqK8ILe2MA.jpeg" /></figure><blockquote><strong><em>Note</em></strong><em>: This tutorial is part of a larger tutorial. See the main article here:</em></blockquote><p><a href="https://medium.com/@koraycaglar/creating-end-to-end-ai-data-product-image-processing-app-with-mlops-by-using-docker-elk-airflow-15336ade44f9">Creating End-to-End AI Data Product(image processing) App with MLOps by using Docker, ELK, Airflow…</a></p><p>In this article we will setup Airflow with Docker on GCP. Then we will orchestrate Python tasks using it.</p><p>Airflow schedules, orchestrates and monitors tasks. It allows us to make tasks dependent on other tasks. Also, we can schedule tasks to run every minute using Airflow.</p><p>We will create a DAG (directed acyclic graph) that contains our tasks. This DAG will run every minute to maintain a real-time data process. Inside our DAG we will have 2 tasks: An image to Base64 encoder and a prediction script that contains our trained machine learning model. The prediction script will depend on the encoder script running before it, so that it doesn’t try to predict without a Base64 formatted data existing.</p><h4>Installing Airflow</h4><p>Assuming you have Docker installed already, you also need ‘docker-compose’. Airflow has multiple components like Scheduler, Worker, Triggerer, Webserver. We will use docker-compose to install our four components.</p><p>If you do not have docker-compose installed, here is the command:</p><pre>$ sudo apt install docker-compose</pre><p>Create dags, logs and plugins folders preferably in the home/username directory. We will later connect these folders with Airflow functions.</p><pre>$ mkdir logs<br>$ mkdir dags<br>$ mkdir plugins </pre><p>You need a ‘yaml’ file to setup Airflow using docker-compose. You can write/find it yourself or you can use mine. You can clone my GitHub repository if you haven’t:</p><pre>$ git clone <a href="https://github.com/koraycaglar/datapipeline.git">https://github.com/koraycaglar/datapipeline.git</a></pre><p>You will find the yaml file at ‘datapipeline/airflow/docker-compose.yaml’. Use a text editor to change &lt;username&gt; parts in the beginning. Change the volume locations of logs, dags, plugins folders if they are different in your filesystem. Also try changing the version number if you get errors during the next step.</p><p>While in the same directory with the yaml file, enter the command:</p><pre>$ docker-compose up airflow-init</pre><p>This initializes the setup, now do:</p><pre>$ docker-compose up -d</pre><p>This takes some time to run the container. You can check the running containers with ‘docker ps’ command. There should be 4 Airflow related containers running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*YYlDeF9x88oIwCb5A-eZ6w.jpeg" /></figure><p>Notice the webserver component running on port 8080. We can use the Airflow web interface using that port. If you are using Google Cloud Platform, I explained before how to interact with web interfaces when you are on a compute engine instance on my ElasticSearch article in this series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-1IiqCQDB0ul18ypNsI3_A.png" /><figcaption>Airflow Web UI</figcaption></figure><p>You can see example dags in this page. We will create our own dag now.</p><h4>Creating a DAG</h4><p>If you have cloned my GitHub repository, you can see our dag file (proje_dag) at the directory ‘datapipeline/airflow/dags/proje_dag.py’. You can copy it into the dags folder you have created before, or you can write your own dag file inside the dags folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88b433b5fd7c6cbb3eaa92920fe9746c/href">https://medium.com/media/88b433b5fd7c6cbb3eaa92920fe9746c/href</a></iframe><p>Let’s examine the DAG file. Variable ‘seven_days_ago’ allows us to keep relative start date time.</p><p>In the ‘dag’ definition, ‘schedule_interval’ is set to 1 minute, meaning it will run the tasks in this dag every minute. You can find more information about the scheduling syntax on the official Airflow page: <a href="https://airflow.apache.org/docs/apache-airflow/1.10.1/scheduler.html">Scheduling &amp; Triggers — Airflow Documentation (apache.org)</a></p><p>t1 and t2 are our tasks. In this case we use Bash Operators to run the bash commands that trigger our python scripts. t1&gt;&gt;t2 descripts that task ‘t1’ should run first before task ‘t2’ runs.</p><p>Now we need the Python scripts ‘encode.py’ and ‘predict.py’. I prefer to keep them inside the ‘dags’ folder which is connected to our Airflow using volumes. You can also find these scripts in the GitHub clone inside ‘dags’ directory. Copy those into your ‘dags’ folder.</p><p>My encode.py script appends new data to a certain base64.log file. It needs permissions to do that. To set permissions for the encode script:</p><pre>$ chmod 777 encode.py</pre><p>If you look at the Airflow Web UI, you can see our DAG appearing among the example DAGs. The DAG should display our tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JvyUMlQHwPQ9I7-TyOFc5g.jpeg" /></figure><p>You see, the encode task and the predict task are connected to each other. When our DAG runs, first the encode task, then the predict task will run.</p><h4>Requirements Before Running</h4><p>Before running the DAG, connect your Airflow Docker containers to other containers using the Docker network functionality if need be. In my case, ElasticSearch connection is needed for my scripts to function.</p><pre>$ docker network connect &lt;username&gt;_default elasticsearch</pre><p>You should also install the requirements of the Python scripts inside the Airflow Docker containers. I need to install Tensorflow, OpenCV and Pika libraries. Get into the worker container using the command:</p><pre>$ docker exec -it  &lt;username&gt;_airflow-worker_1 bash</pre><p>Install python libraries using pip:</p><pre>$ pip install opencv-python<br>$ pip install tensorflow<br>$ pip install pika</pre><p>Exit the container with command ‘exit’.</p><p>To prevent a certain error, I had to update and install extra packages. Get back into the container with root user:</p><pre>$ docker exec -u root -it  &lt;username&gt;_airflow-worker_1 bash</pre><p>Enter the commands:</p><pre>$ sudo apt-get update<br>$ sudo apt-get install ffmpeg libsm6 libxext6  -y</pre><p>Exit the container. Finally, everything is ready. Turn the DAG on at the Web UI and run it. It should run once every minute. This page displays the health of the system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hy-VJjQHHfsbYmYONIEy0g.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b679275686dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing and using RabbitMQ with Docker.]]></title>
            <link>https://medium.com/@koraycaglar/installing-and-using-rabbitmq-with-docker-b997d80b8d17?source=rss-7da247518445------2</link>
            <guid isPermaLink="false">https://medium.com/p/b997d80b8d17</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <dc:creator><![CDATA[Koray Çağlar]]></dc:creator>
            <pubDate>Thu, 27 Oct 2022 14:41:43 GMT</pubDate>
            <atom:updated>2022-10-27T14:41:43.991Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EtQoJAyusPtGEAek4tcs8g.jpeg" /></figure><p><strong><em>Note</em></strong><em>: This tutorial is part of a larger tutorial. See the main article here:</em></p><p><a href="https://medium.com/@koraycaglar/creating-end-to-end-ai-data-product-image-processing-app-with-mlops-by-using-docker-elk-airflow-15336ade44f9">Creating End-to-End AI Data Product(image processing) App with MLOps by using Docker, ELK, Airflow…</a></p><p>I will explain how to setup RabbitMQ with Docker. We will do a basic example using Python, then implement the part in my project where RabbitMQ is used.</p><p>RabbitMQ is a message broker, which means it is a middleman between other programs that help deliver messages, logs and sometimes data. In its most basic form, there should be a producer(sender) program and a consumer(receiver) program. The producer sends messages to a queue in RabbitMQ, the receiver pulls the messages in first-in-first-out(queue) order. RabbitMQ has many more concepts and architectures to learn about, but they are out of scope for this article.</p><h4><strong>Installing RabbitMQ</strong></h4><p>We will install it using Docker, so make sure you have Docker on your system before beginning.</p><p>RabbitMQ and other programs using it should be installed on the same Docker network. For tutorial purposes, let’s create a network named “rabbitnet”.</p><pre>$ docker network create rabbitnet</pre><p>Run this command to pull the latest RabbitMQ image and run a container with given arguments:</p><pre>$ docker run -d --rm --network rabbitnet -p 15672:15672 --hostname rabbit-1 --name rabbitmq rabbitmq:latest</pre><p>Our container runs on the rabbitnet network, is attached to port 15672 and named rabbitmq.</p><p>Now our RabbitMQ is installed. As you see it was very easy and straightforward. Now we will build a basic example system.</p><h4>Sending Message to RabbitMQ</h4><p>We will create a basic Python program that sends a message to a queue in RabbitMQ, then Dockerize it with a Dockerfile.</p><p>Make a folder named ‘sender’.</p><pre>$ mkdir sender</pre><p>Inside the sender directory, make a python file.</p><pre>$ sudo nano sender.py</pre><p>Copy the following code into the py file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a59d23164e7c2f84eb4b05b2d86e7fd1/href">https://medium.com/media/a59d23164e7c2f84eb4b05b2d86e7fd1/href</a></iframe><p>Save and exit the editor. Now we should build a Docker image using a Dockerfile.</p><p>Create a Dockerfile using any text editor:</p><pre>$ sudo nano Dockerfile</pre><p>Copy this code inside it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b9d34a364f23b8f59c5e41666ab1477/href">https://medium.com/media/3b9d34a364f23b8f59c5e41666ab1477/href</a></iframe><p>Save and exit.</p><p>Create a Docker image named ‘sender’:</p><pre>$ docker build -t sender .</pre><p>We have our producer program ready. When we run a container from this image, it will send a &#39;hello&#39; message to our &#39;test_queue&#39;, then shutdown the container. <br>Let&#39;s create the receiving end.</p><h4>Pulling a Message from RabbitMQ</h4><p>Make a ‘receiver’ folder.</p><pre>$ mkdir receiver</pre><p>Create a Python file named ‘receiver.py’</p><pre>$ sudo nano receiver.py</pre><p>Copy the following code into the script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6fd26e3a7c222d31d194272dfd60033/href">https://medium.com/media/f6fd26e3a7c222d31d194272dfd60033/href</a></iframe><p>Create a Dockerfile in the same directory.</p><pre>$ sudo nano Dockerfile</pre><p>Copy the following code into the Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a9805b3777ed66dedac8092d471519c/href">https://medium.com/media/2a9805b3777ed66dedac8092d471519c/href</a></iframe><p>Build a Docker image named ‘receiver’.</p><pre>$ docker build -t receiver .</pre><p>Our receiver(consumer) program is ready. Its container will always be up and listening the &#39;test_queue&#39; and print out the message when it receives one.</p><h4>Testing</h4><p>You can check our images using &#39;docker images&#39; command. We will run containers from the images and see if it is working.</p><p>Run this command to create the receiver container:</p><pre>$ docker run -u root -dit --network rabbitnet --name receiver receiver</pre><p>Our container is running on &#39;rabbitnet&#39; and named &#39;receiver&#39;. It is important that all our programs using the RabbitMQ should be in the same Docker network as the RabbitMQ itself.</p><p>When we run our sender container, it will publish a message and shutdown. Let&#39;s do it:</p><pre>$ docker run -u root --network rabbitnet --name sender --rm sender</pre><p>Now check if our receiver container received it:</p><pre>$ docker logs receiver</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*yv8an9wY3SuWaxqQDEc9QQ.jpeg" /></figure><p>It did! Now you can build more complex systems using this knowledge. Which I will do it now for my personal project.</p><h4>Concerning the Main Project</h4><p>I deleted all the containers, images and networks created above in this article and build them on my default &#39;elk_default&#39; docker network.</p><p>I am running a new RabbitMQ container with this command:</p><pre>docker run -d --rm --network elk_default -p 15672:15672 --hostname rabbit-1 --name rabbitmq rabbitmq:latest</pre><p>The producer will be a Python script running on Airflow which we didn&#39;t build yet. It will send a base64 code of a marble image and the prediction made by the machine learning model, meaning 2 messages should be delivered using 2 different queues.</p><p>The consumer will be a Python script that prints the base64 code of received image and the prediction received from the machine learning model.</p><p>The receiver script is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69f65d7c6337fd6cffee37c81e746a03/href">https://medium.com/media/69f65d7c6337fd6cffee37c81e746a03/href</a></iframe><p>The Dockerfile is same as in the example above:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a9805b3777ed66dedac8092d471519c/href">https://medium.com/media/2a9805b3777ed66dedac8092d471519c/href</a></iframe><p>Building the receiver image:</p><pre>$ docker build -t receiver .</pre><p>Running the receiver container:</p><pre>docker run -u root -dit --network elk_default --name receiver receiver</pre><p>The receiver script listens to 2 different queues: &#39;base64&#39; and &#39;prediction&#39;, then prints the received messages. The RabbitMQ system is ready to use. In the next article we will install Airflow and build a &#39;dag&#39; containing tasks that send messages to our RabbitMQ.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b997d80b8d17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing ElasticSearch, Kibana and Filebeat using Docker on Google Cloud Platform]]></title>
            <link>https://medium.com/@koraycaglar/installing-elasticsearch-kibana-and-filebeat-using-docker-on-google-cloud-platform-30cb93296194?source=rss-7da247518445------2</link>
            <guid isPermaLink="false">https://medium.com/p/30cb93296194</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kibana]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[filebeat]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Koray Çağlar]]></dc:creator>
            <pubDate>Tue, 04 Oct 2022 13:22:05 GMT</pubDate>
            <atom:updated>2022-10-13T13:33:36.787Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KUmoxtUrQNeMV5b1rvWIzg.jpeg" /></figure><blockquote><strong>Note</strong>: This tutorial is part of a larger tutorial. See the main article here:</blockquote><p><a href="https://medium.com/@koraycaglar/creating-end-to-end-ai-data-product-image-processing-app-with-mlops-by-using-docker-elk-airflow-15336ade44f9">Creating End-to-End AI Data Product(image processing) App with MLOps by using Docker, ELK, Airflow…</a></p><p>In this tutorial, we will build a system that detects when new data gets appended on a log file using Filebeat, saves it to our ElasticSearch database and lets us see the data inside the database using the Kibana user interface.</p><h4>Installing ElasticSearch and Kibana:</h4><p>We will install both in a simple way called “Docker Compose”. First, we need Docker Compose for that:</p><pre>$ sudo apt install docker-compose</pre><p>Now we need a docker compose yml file that tells Docker how to install and run these containers. You can write your own yml file or you can copy mine using git:</p><pre>$ git clone <a href="https://github.com/koraycaglar/datapipeline.git">https://github.com/koraycaglar/datapipeline.git</a></pre><p>Now after cloning the repository, you can find the yml file in this location: datapipeline/ELK/docker-compose.yml</p><p>Get to the location where the .yml file is. If you want to take a look at the .yml file write the following command:</p><pre>$ sudo nano docker-compose.yml</pre><p>Notice I am installing ES and Kibana versions 7.9.2. You can install more recent versions by changing the version numbers in the yml file.</p><p>Before running the ElasticSearch container you need to increase the size of vm.max_map_count as officially explained here:</p><p><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html">Virtual memory | Elasticsearch Guide [8.4] | Elastic</a></p><p>Run the mentioned command as root:</p><pre>$ sudo sysctl -w vm.max_map_count=262144</pre><p>To download and run the ES and Kibana containers using docker compose run the following command. Make sure you are at the same directory where the yml file is.</p><pre>$ docker-compose up -d</pre><p>It will pull the images and run the containers as instructed in the .yml file. It may take some time (few minutes).</p><p>After the wait, enter this command to see the running containers:</p><pre>$ docker ps</pre><p>You should see our ES and Kibana are running. Note the ports 9200 is assigned for ES and 5601 for Kibana.</p><p>Enter this command to see if ES is running:</p><pre>$ curl localhost:9200</pre><p>Let’s check if Kibana is also running. We will do that in a cool way. Maybe you know Kibana has a user interface. In Google Cloud Platform we can see program interfaces using web preview feature.</p><p>Get back to the Google Cloud page, click the Google Cloud Shell icon at the top right of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7zjvprvdhAXoqgbYnXVcvw.jpeg" /><figcaption>Google Cloud Shell icon at the top right</figcaption></figure><p>In the opened terminal, enter the following command <strong>with instance name and zone code changed to match yours.</strong> In my case:</p><p>$ gcloud compute ssh instance-1 --zone=us-west4-b -- -L 5601:localhost:5601</p><p>You can find your instance name and zone code in this same page where you SSH into the machine.</p><p>After entering the command, you should click the “web preview” button on the terminal window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sotkjnW7CBE5hXDEuoU54A.jpeg" /><figcaption>Web preview button shown with red arrow</figcaption></figure><p>Click change port, write 5601 (kibana’s port) and click change and preview. Kibana’s web interface opens in new window, means it is working.</p><h4><strong>Installing and configuring Filebeat:</strong></h4><p>Our Filebeat instance will listen to a log file all the time. Let’s create the log file first.</p><p>Get back to your default file path (/home/&lt;username&gt;). Create a .log file. I am naming it base64.log because I will put base64 image codes inside it.</p><pre>$ sudo nano base64.log</pre><p>In the text editor press Enter once to “write” an empty line so that we can save the file. Press Ctrl+X, Y and Enter to save.</p><p>Now that we have our log file ready, we should install and configure the Filebeat instance.</p><p>If you have cloned my Github repository before, you can find my yml file for Filebeat in this location:</p><p>datapipeline/filebeat/filebeat.docker.yml</p><p><strong>Change the &lt;username&gt; part with your username in the yml file!</strong></p><pre>$ sudo nano filebeat.docker.yml</pre><p>Run the following command to configure the Filebeat installation. Change the version number 7.9.2 to something recent if you want.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/331ca8534a9abfb8a152e438cae1ae58/href">https://medium.com/media/331ca8534a9abfb8a152e438cae1ae58/href</a></iframe><p>While in the same directory with the yml file, <strong>change the &lt;username&gt; part</strong> in the following command and run to create a Filebeat container. Change the version number again if you did in the previous step.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b9d6b28d512ad7c1c94e79a4b3345f8/href">https://medium.com/media/8b9d6b28d512ad7c1c94e79a4b3345f8/href</a></iframe><p>You can see the container if you run “docker ps” command.</p><p>We have built the whole system and it should work as intended now. Our Filebeat container is listening to any changes made in the base64.log file and saving them to our ES database.</p><h4>Testing</h4><p>We run a python script that encodes all image files inside our imageserver directory to base64, writes the code to our base64.log file, then moves the processes images into “done” folder in the imageserver folder.</p><p>Get inside the imageserver folder and create a “done” folder. This folder will hold images after we are done with encoding them. This way we can see which images are processed.</p><pre>$ mkdir done</pre><p>Get back to the main directory and create a python script:</p><pre>$ sudo nano encode.py</pre><p>Copy the following code into the script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0fb9864a8e75b2562b832b3f8458300/href">https://medium.com/media/a0fb9864a8e75b2562b832b3f8458300/href</a></iframe><p>Change the &lt;username&gt; parts with your username (there are 3 parts). Save the file.</p><p>For the script to be able to access and add to the log file, set permissions of the base64.log file:</p><pre>$ sudo chmod 777 base64.log</pre><p>Run our camera.py script to move images into the imageserver folder.</p><pre>$ python3 camera.py</pre><p>Wait a bit for the images to transfer. Remember that one image is transferred every 3 seconds. Ctrl+C to stop the script after waiting.</p><p>Run the encode.py script:</p><pre>$ python3 encode.py</pre><p>Encode script just wrote our base64 codes in the base64.log file. Filebeat detected it and saved the codes into the ES database. You can check inside the base64.log file to see the codes.</p><p>Let&#39;s use the Kibana interface to see our codes inside the database (I explained above how to do it).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4UH86oF3SS3liY8UxNWFtQ.jpeg" /><figcaption>Click the 3-line button at the top left. Then click Discover under the Kibana tab.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6u-y7MS2KxdXKQ2z2iEVTA.jpeg" /><figcaption>Viola! Our codes are here.</figcaption></figure><p>If you can’t see the codes in the Kibana interface, try changing the time interval at the top right. It shows codes recorded in the last hour by default.</p><p>Here ends our tutorial. It was quite long but installing the ELK stack and Filebeat can be confusing. I hope it was useful for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30cb93296194" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Downloading a dataset with Kaggle API and simulating a fictional camera]]></title>
            <link>https://medium.com/@koraycaglar/downloading-a-dataset-with-kaggle-api-and-simulating-a-fictional-camera-81955025a37?source=rss-7da247518445------2</link>
            <guid isPermaLink="false">https://medium.com/p/81955025a37</guid>
            <category><![CDATA[kaggle-api]]></category>
            <category><![CDATA[dataset]]></category>
            <dc:creator><![CDATA[Koray Çağlar]]></dc:creator>
            <pubDate>Sun, 18 Sep 2022 17:44:03 GMT</pubDate>
            <atom:updated>2022-09-18T17:44:03.154Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*GZrTyTz0OKMbxnO5Trhcew.png" /></figure><blockquote><strong>Note</strong>: This tutorial is part of a larger tutorial. See the main article here:</blockquote><p><a href="https://medium.com/@koraycaglar/creating-end-to-end-ai-data-product-image-processing-app-with-mlops-by-using-docker-elk-airflow-15336ade44f9">Creating End-to-End AI Data Product(image processing) App with MLOps by using Docker, ELK, Airflow…</a></p><p>In this tutorial I will explain how to download a dataset from Kaggle using Kaggle API.</p><p>After that, concerning the main project, we will write a python script to transfer files from the dataset to a folder to simulate a camera.</p><h4>Installing the Kaggle API:</h4><p>We should install pip first:</p><pre>$ sudo apt install python3-pip</pre><p>Install the Kaggle API:</p><pre>$ pip install kaggle</pre><p>Now if you enter command “kaggle” you will get a “kaggle: command not found” error. A symbolic link between /.local/bin and /usr/bin should be created. You do that by entering the following command:</p><pre>$ sudo ln -s ~/.local/bin/kaggle /usr/bin/kaggle</pre><p>You will also get an error “Could not find kaggle.json” error when you enter a kaggle command. That’s because you should have an API token to use Kaggle API. If you do not have a Kaggle account, go create one. If you have an account, go to the account page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*zQCNXZK5in6k-RDEUBMchw.jpeg" /><figcaption>Click your profile photo in the top-right. Then click Account.</figcaption></figure><p>In the API section, click “Create New API Token”. It should download your kaggle.json file.</p><p>Back to your VM, click “Upload File” button in the top-right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*PirUDn7pQVavZ3pURaWLCg.jpeg" /></figure><p>Upload the kaggle.json file you just downloaded. The VM can crash, just try again. After uploading, write “ls” to see the file in your system.</p><p>We should move the json file into the .kaggle folder. To do so:</p><pre>$ mv kaggle.json .kaggle</pre><p>You can enter Kaggle commands now.</p><h4>Download a dataset</h4><p>Go to a dataset’s page. Click the 3-points button next to the Download button. Click “Copy API command”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*NStDxwLb3oOhd3vlGbUcEw.jpeg" /></figure><p>In my case the dataset is “Marble surface anomaly detection”. Link to the dataset:</p><p><a href="https://www.kaggle.com/datasets/wardaddy24/marble-surface-anomaly-detection-2">Marble Surface Anomaly Detection — 2 | Kaggle</a></p><p>Enter the copied command to download the dataset zip file. My dataset’s command is as follows:</p><pre>$ kaggle datasets download -d wardaddy24/marble-surface-anomaly-detection-2</pre><p>Write “ls” to see the downloaded zip file. We need to extract our data from the zip file. Download the unzip package by entering the following command:</p><pre>$ sudo apt install unzip</pre><p>The command to unzip the zip file in my case (change the name if yours is different):</p><pre>$ unzip marble-surface-anomaly-detection-2.zip</pre><p>Write “ls” to see the dataset folder. Remove the zip file to have a tidy workspace:</p><pre>$ rm marble-surface-anomaly-detection-2.zip</pre><h4>Simulate a camera</h4><p>As we do not have an IRL camera, we should make it appear as like we do have a camera. We do that by writing a Python script. The script will copy an image from the dataset to our newly created “imageserver” folder. You can imagine it like an IRL camera is taking a new photo and sending it to the imageserver folder every 3 seconds.</p><p>Create a new folder named “imageserver”:</p><pre>$ mkdir imageserver</pre><p>Create a new python script named “camera.py”:</p><pre>$ sudo nano camera.py</pre><p>“nano” is a text editor. Inside the editor copy the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb89f9f88d18d041d52e9c150a0475ae/href">https://medium.com/media/eb89f9f88d18d041d52e9c150a0475ae/href</a></iframe><p>Change the “username” parts in the directories with your username.</p><p>Press Ctrl + X to exit from the editor. Press Y to save it and then Enter.</p><p>Run the script:</p><pre>$ python3 camera.py</pre><p>The script transfers an image file every 3 seconds. Wait a bit. Then press Ctrl + C to stop the script. Now go to the imageserver folder and list the contents. You should see some jpg files.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81955025a37" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating End-to-End AI Data Product(image processing) App with MLOps by using Docker, ELK, Airflow…]]></title>
            <link>https://medium.com/@koraycaglar/creating-end-to-end-ai-data-product-image-processing-app-with-mlops-by-using-docker-elk-airflow-15336ade44f9?source=rss-7da247518445------2</link>
            <guid isPermaLink="false">https://medium.com/p/15336ade44f9</guid>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[filebeat]]></category>
            <dc:creator><![CDATA[Koray Çağlar]]></dc:creator>
            <pubDate>Sun, 18 Sep 2022 13:35:53 GMT</pubDate>
            <atom:updated>2022-10-31T20:56:34.924Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating End-to-End AI Data Product(image processing) App with MLOps by using Docker, ELK, Airflow, RabbitMQ</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*dgzD0A-5sYVnHx56eyjQhw.png" /></figure><blockquote><strong>Note</strong>: This is the main article about building the system above. Details and instructions on how to implement parts of the system are written in other Medium articles which are linked below this article.</blockquote><p>In this tutorial I will try to explain how to create an End-to End data pipeline which we will build on the Google Cloud Platform. <strong>Be wary as I am not an expert on the subject</strong>, but a mere student and I am sure there are better ways to build such a system. My reason for building this project was to learn/practice. Also, English is not my first language.</p><p>The system’s function is to detect faulty marble products on a production line in real-time.</p><h4><strong>The system we will be building consists of:</strong></h4><ul><li>Getting image data form a source (our camera is fictional)</li><li>Processing the data</li><li>Storing data on a NoSQL database (ElasticSearch in our case)</li><li>Classifying with machine learning model</li><li>Publishing to a message broker (RabbitMQ)</li><li>Consuming from a message broker</li><li>Building a very basic interface to see the results.</li></ul><h4><strong>The tech/tools we will be using:</strong></h4><ul><li>Google Cloud Platform (Compute Engine)</li><li>Docker</li><li>Linux (Debian)</li><li>Python</li><li>Elastic Stack (ElasticSearch, Filebeat, Kibana)</li><li>Apache Airflow</li><li>RabbitMQ</li></ul><h4>Tech Details</h4><p><strong>Google Cloud Platform:</strong> GCP is the cloud service of Google. Thanks to this service, we can build our system on Google’s servers. This practice has many advantages compared to a local system. Some of these advantages are as follows:</p><ul><li>We save from hardware costs.</li><li>If things go wrong, we can just create a new machine on the cloud.</li><li>Our machine on the cloud stays up all the time.</li></ul><p><strong>Docker:</strong> Docker lets us containerize programs and run them wherever we want. Docker containers contain apps and their pre-requirements. This allows us to install our tools without installing their requirements first.</p><p>Docker is especially useful in Cloud platforms since we don’t need to relay on what is currently installed on the host thanks to it.</p><p><strong>Elastic Stack (ELK): </strong>By Elastic Stack, we mean ElasticSearch, Logstash and Kibana.<strong> </strong>I didn’t see any reason to use Logstash since we only have one data source in this project. Additionally to the ELK stack, we will install Filebeat to detect when data arrives at somewhere.</p><p>ElasticSearch is used as a NoSQL database. It searches text-based data with ease. Our images will be converted to a text-based format called Base64 before saving to the database, so it fits our case. Also ElasticSearch being compatible with Kibana and Filebeat is the most important reason we are using it.</p><p>Kibana lets us monitor what’s inside out ElasticSearch Database. We can see our data, indexes, documents and metadata thanks to Kibana.</p><p>Filebeat is a part of the ELK stack. It detects when new data arrives where it is looking for and sends it to our ElasticSearch database. We will use it to listen to the location where images from the camera arrives every few seconds.</p><p><strong>Apache Airflow: </strong>Airflow schedules, orchestrates and monitors tasks. It allows us to make tasks dependent on other tasks. Also, we can schedule tasks to run every minute using Airflow.</p><p>We will create a DAG (directed acyclic graph) that contains our tasks. This DAG will run every minute to maintain a real-time data process. Inside our DAG we will have 2 tasks: An image to Base64 encoder and a prediction script that contains our trained machine learning model. The prediction script will depend on the encoder script running before it, so that it doesn’t try to predict without a Base64 formatted data existing.</p><p><strong>RabbitMQ</strong>: This is a message broker. Thanks to RabbitMQ we can deliver data and messages between tools and applications.</p><p>In its most basic form, it has a producer, a queue and a consumer. Producer is any app that publishes messages to the RabbitMQ queue. Messages are kept in the queue until they are consumed by a consumer app. Messages from the queues are consumed as First-In-First-Out style, meaning first message that’s published to the queue is also consumed first, which makes it a “queue”.</p><h4><strong>Steps to follow for building the system:</strong></h4><p>I will explain every detail. So as not to turn this article to a messy salad, I will divide this tutorial into multiple articles.</p><p>Follow below articles in order to build the system from zero.</p><ul><li><a href="https://medium.com/@koraycaglar/installing-docker-on-a-compute-engine-d8c6411aa451">Installing Docker on a Compute Engine</a></li><li><a href="https://medium.com/@koraycaglar/downloading-a-dataset-with-kaggle-api-and-simulating-a-fictional-camera-81955025a37">Downloading a dataset with Kaggle API and simulating a fictional camera</a></li><li><a href="https://medium.com/@koraycaglar/installing-elasticsearch-kibana-and-filebeat-using-docker-on-google-cloud-platform-30cb93296194">Installing ElasticSearch, Kibana and Filebeat using Docker on Google Cloud Platform</a></li><li><a href="https://medium.com/@koraycaglar/installing-and-using-rabbitmq-with-docker-b997d80b8d17">Installing and using RabbitMQ with Docker.</a></li><li><a href="https://medium.com/@koraycaglar/installing-airflow-with-docker-and-orchestrating-tasks-on-gcp-b679275686dd">Installing Airflow with Docker and orchestrating tasks on GCP.</a></li></ul><p>You can see the end product in this video:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fs2RUkLEPRnE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Ds2RUkLEPRnE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fs2RUkLEPRnE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a01015ff832b0cf0c3019baf6c835de/href">https://medium.com/media/1a01015ff832b0cf0c3019baf6c835de/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15336ade44f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Docker on a Compute Engine]]></title>
            <link>https://medium.com/@koraycaglar/installing-docker-on-a-compute-engine-d8c6411aa451?source=rss-7da247518445------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8c6411aa451</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Koray Çağlar]]></dc:creator>
            <pubDate>Sun, 18 Sep 2022 13:14:37 GMT</pubDate>
            <atom:updated>2022-09-18T13:38:17.644Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*prvnwMAtnPhXAxRrRXJ3Lw.png" /></figure><blockquote><strong>Note</strong>: This tutorial is part of a larger tutorial. See the main article here:</blockquote><p><a href="https://medium.com/@koraycaglar/creating-end-to-end-ai-data-product-image-processing-app-with-mlops-by-using-docker-elk-airflow-15336ade44f9">Creating End-to-End AI Data Product(image processing) App with MLOps by using Docker, ELK, Airflow…</a></p><h4><strong>Creating a Compute Engine VM:</strong></h4><p>Create a Google Cloud account if you do not have one. Note that you can get $300 free credit for 90 days so that you can try the platform and tinker around as you like.</p><p>After setting up your account, go to the Compute Engine page and click <strong>Create Instance. </strong>Choose any Name, Region and Zone. Some regions’ prices differ from each other.</p><p>I chose e2-highmem-8 machine type from E2 series. You can get something different if you’d like.</p><p>Enable display device, allow full access to all Cloud APIs, allow HTTP and HTTPS traffic. Click <strong>Create</strong>.</p><h4><strong>Increasing the disk size:</strong></h4><p>If you do not increase the disk size, you can get memory errors after installing multiple tools. The error I encountered before increasing the disk size is “<strong>No space left on device” </strong>when I tried to install Tensorflow.</p><p>Click the name of the instance you just created, get to the <strong>Boot disk</strong> section and click the name of the instance again. Click the <strong>Edit </strong>button on top of the page. Change the size from 10 to 100 and click <strong>Save</strong>. Wait until it finishes updating the disk. “Updating the disk” message stayed longer than it should in my case. Just refresh the page.</p><h4><strong>Installing Docker:</strong></h4><p>In the VM instances page, click the SSH button on the instance to connect to your VM.</p><p>Updating stuff is always a good practice. Enter the commands:</p><pre>$ sudo apt update</pre><pre>$ sudo apt upgrade</pre><p>To install Docker:</p><pre>$ sudo apt install docker.io</pre><p>After installing run</p><pre>$ docker</pre><p>If bunch of stuff comes up it means you have installed it successfully. Now run:</p><pre>$ sudo docker run hello-world</pre><p>It will not find the hello-world image locally and pull it from the internet. Then it will create a container from the image and run it. You should see a message starting with “Hello from Docker!”.</p><h4><strong>Adding the user to docker group:</strong></h4><p>If you want to refrain from writing “sudo” before every docker command you should add your current user to a group named docker. Enter the commands:</p><pre>$ sudo groupadd docker</pre><pre>$ sudo usermod -aG docker $USER</pre><pre>$ newgrp docker</pre><p>Now you can run docker commands without writing “sudo”. Try it:</p><pre>$ docker run hello-world</pre><p>This concludes our tutorial. You can use Docker as you like from now on.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8c6411aa451" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>