<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>PostgreSQL on Ghost in the data</title><link>https://ghostinthedata.info/tags/postgresql/</link><description>Ghost in the data</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Ghost in the data</copyright><lastBuildDate>Sat, 09 Mar 2024 00:00:00 +1100</lastBuildDate><atom:link href="https://ghostinthedata.info/tags/postgresql/index.xml" rel="self" type="application/rss+xml"/><item><title>Docker and Airflow: A Comprehensive Setup Guide</title><link>https://ghostinthedata.info/posts/2024/2024-03-10-setup-docker-and-airflow-data-engineering/</link><pubDate>Sat, 09 Mar 2024 00:00:00 +1100</pubDate><guid>https://ghostinthedata.info/posts/2024/2024-03-10-setup-docker-and-airflow-data-engineering/</guid><author>Chris Hillman</author><description>Dive into our comprehensive guide to setting up Docker and Airflow, essential tools for creating robust data engineering pipelines.</description><content:encoded>&lt;h3 id="introduction">Introduction&lt;/h3>
&lt;hr>
&lt;p>&lt;strong>Docker&lt;/strong> and &lt;strong>Airflow&lt;/strong> are like peanut butter and jelly for data engineers; they just work perfectly together. Docker simplifies deployment by wrapping your applications in containers, ensuring consistency across environments. It&amp;rsquo;s like having a genie that makes sure your software behaves the same, no matter where you deploy it. On the flip side, Airflow is the maestro of orchestrating complex workflows, making it a go-to tool for managing data pipelines in various organisations.&lt;/p>
&lt;/br>
&lt;/br>
&lt;h3 id="lets-get-docker-rolling">Let&amp;rsquo;s Get Docker Rolling&lt;/h3>
&lt;p>First things first, we&amp;rsquo;ll lay our foundation with Docker. Begin by grabbing Docker Desktop from &lt;a href="https://www.docker.com/products/docker-desktop/" target="_blank" rel="noopener">Docker&amp;rsquo;s official website&lt;/a>. Choose the version compatible with your operating system, and you&amp;rsquo;re off to the races.&lt;/p>
&lt;/br>
&lt;p>Here&amp;rsquo;s the gear we&amp;rsquo;ll need for our setup:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>docker-compose.yaml&lt;/strong> : Think of this as the blueprint for how your Docker containers will play nicely together.&lt;/li>
&lt;li>&lt;strong>dockerfile-airflow&lt;/strong> : This defines how we build one of the Docker containers, and we will use it as a blueprint for all the building of the systems in our ecosystem.&lt;/li>
&lt;li>&lt;strong>.dockerignore&lt;/strong> : It&amp;rsquo;s like telling Docker, &amp;ldquo;Please ignore these files.&amp;rdquo; This step keeps our build clean and conflict-free.&lt;/li>
&lt;li>&lt;strong>requirements.txt&lt;/strong>: A simple pip requirements file. While Airflow can run Python commands, we recommend keeping it lean. You can always use Kubernetes Operators to manage heavier workloads.&lt;/li>
&lt;/ul>
&lt;/br>
&lt;blockquote>
&lt;p>Note: Regarding the requirements.txt
While you can install Python packages directly onto Airflow workers, it&amp;rsquo;s not the best practice. Keep Airflow light and use Kubernetes Operators for the heavy lifting or to deploy specific Docker images as needed.&lt;/p>&lt;/blockquote>
&lt;/br>
&lt;p>Clone the &lt;a href="git@github.com:krshillman/tut_docker_setup.git">Repository&lt;/a> and in your terminal, navigate to the new directory.&lt;/p>
&lt;/br>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>Run docker-compose build
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/br>
&lt;img src="https://ghostinthedata.info/posts/2024/2024-03-10-setup-docker-and-airflow-data-engineering/images/docker-compose.PNG"
 
 alt="docker-compose"
 
 
 
 
 
 class="center"
 
>

&lt;/br>
&lt;p>Next up:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>Run docker-compose up --build
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/br>
&lt;img src="https://ghostinthedata.info/posts/2024/2024-03-10-setup-docker-and-airflow-data-engineering/images/docker-compose-up.PNG"
 
 alt="docker-compose-up"
 
 
 
 
 
 class="center"
 
>

&lt;/br>
&lt;p>This spins up your ecosystem and pulls the necessary images to get started.&lt;/p>
&lt;hr>
&lt;/br>
&lt;/br>
&lt;h3 id="airflow-setup">Airflow Setup&lt;/h3>
&lt;hr>
&lt;p>To access Airflow, hit up &lt;a href="http://localhost:8080/" target="_blank" rel="noopener">localhost:8080&lt;/a> on your web browser. You&amp;rsquo;ll be met with a login screen—both the username and password are &amp;lsquo;airflow&amp;rsquo;. Once in, you&amp;rsquo;ll see Airflow&amp;rsquo;s interface, ready for action.&lt;/p>
&lt;/br>
&lt;img src="https://ghostinthedata.info/posts/2024/2024-03-10-setup-docker-and-airflow-data-engineering/images/airflow-signin.PNG"
 
 alt="airflow-signin"
 
 
 
 
 
 class="center"
 
>

&lt;/br>
&lt;img src="https://ghostinthedata.info/posts/2024/2024-03-10-setup-docker-and-airflow-data-engineering/images/airflow-start.PNG"
 
 alt="airflow-start"
 
 
 
 
 
 class="center"
 
>

&lt;/br>
&lt;p>There&amp;rsquo;s a &amp;ldquo;Hello World&amp;rdquo; DAG pre-loaded for you to experiment with. This is just the beginning of your journey with Airflow.&lt;/p>
&lt;/br>
&lt;h4 id="running-the-hello-world-dag">Running the &amp;ldquo;Hello World&amp;rdquo; DAG&lt;/h4>
&lt;p>To get your hands dirty with Airflow, let&amp;rsquo;s run the &amp;ldquo;Hello World&amp;rdquo; DAG. This simple task is a great way to familiarize yourself with how Airflow orchestrates tasks.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Find the DAG&lt;/strong>: On the main dashboard. Locate the &amp;ldquo;Hello World&amp;rdquo; DAG. It should be there, smiling back at you, ready for action.&lt;/li>
&lt;li>&lt;strong>Trigger the DAG&lt;/strong>: Hover over the &amp;ldquo;Hello World&amp;rdquo; DAG row, and you&amp;rsquo;ll see a &lt;strong>play&lt;/strong> button appear on the right side. Click this button to trigger the DAG manually. Alternatively, if the DAG is scheduled to run automatically, you can wait for its next run.&lt;/li>
&lt;li>&lt;strong>Monitor the DAG&amp;rsquo;s Progress&lt;/strong>: After triggering the DAG, click on its name to open the DAG details page. Here, you can see the DAG&amp;rsquo;s tasks, their status (such as running, success, or failed), and other useful information.&lt;/li>
&lt;/ul>
&lt;/br>
&lt;h4 id="checking-the-logs-for-the-hello-world-output">Checking the Logs for the &amp;ldquo;Hello World&amp;rdquo; Output&lt;/h4>
&lt;p>Seeing what your DAG is doing under the hood is crucial for debugging and understanding its behaviour. Here&amp;rsquo;s how to check the logs for the &amp;ldquo;Hello World&amp;rdquo; task:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Go to the DAG&amp;rsquo;s Graph View&lt;/strong>: From the DAG details page, navigate to the &lt;strong>&amp;ldquo;Graph View&amp;rdquo;&lt;/strong> tab. This view shows all the tasks in your DAG and their dependencies.&lt;/li>
&lt;li>&lt;strong>Find the Task Instance&lt;/strong>: Locate the &lt;strong>&amp;ldquo;Hello World&amp;rdquo;&lt;/strong> task in the graph. It should be a clickable node.&lt;/li>
&lt;li>&lt;strong>Access Task Logs&lt;/strong>: Click on the &lt;strong>&amp;ldquo;Hello World&amp;rdquo;&lt;/strong> task node, and a small window will pop up with several options. Click on the &lt;strong>&amp;ldquo;Log&amp;rdquo;&lt;/strong> button to open the task&amp;rsquo;s logs.&lt;/li>
&lt;li>&lt;strong>Review the Output&lt;/strong>: The log window will display the task&amp;rsquo;s output, including any &amp;ldquo;Hello World&amp;rdquo; messages it printed. Here, you can see everything the task did, any errors it encountered, and the famous &amp;ldquo;Hello World&amp;rdquo; output you&amp;rsquo;re looking for.&lt;/li>
&lt;/ul>
&lt;/br>
&lt;/br>
&lt;h3 id="postgresql-data-warehouse">PostgreSQL: Data Warehouse&lt;/h3>
&lt;hr>
&lt;p>With Airflow humming along, it&amp;rsquo;s time to peek at our data warehouse setup. You can connect to our databases using DBeaver or a similar tool.&lt;/p>
&lt;/br>
&lt;img src="https://ghostinthedata.info/posts/2024/2024-03-10-setup-docker-and-airflow-data-engineering/images/dbeaver.PNG"
 
 alt="dbeaver"
 
 
 
 
 
 class="center"
 
>

&lt;/br>
&lt;p>You&amp;rsquo;ll find databases set up for different stages of data processing:&lt;/p>
&lt;ul>
&lt;li>dwh_01_landing&lt;/li>
&lt;li>dwh_02_staging&lt;/li>
&lt;li>dwh_03_integration&lt;/li>
&lt;li>dwh_04_presentation&lt;/li>
&lt;/ul>
&lt;p>We&amp;rsquo;ll delve into how we can move and transform data within these databases using dbt and Airflow in future posts.&lt;/p>
&lt;/br>
&lt;/br>
&lt;h3 id="conclusion">Conclusion&lt;/h3>
&lt;hr>
&lt;p>That&amp;rsquo;s a wrap on our Docker and Airflow setup guide! We&amp;rsquo;ve laid the groundwork for you to start tinkering with data pipelines and transformation processes. Stay tuned for more on leveraging these powerful tools to streamline your data engineering projects.&lt;/p></content:encoded><category>Data Engineering</category><category>Apache Airflow</category><category>ETL</category><category>Data Engineering</category><category>PostgreSQL</category></item></channel></rss>