|
| 1 | + |
| 2 | +* [Data engineering project template](#data-engineering-project-template) |
| 3 | + * [Run Data Pipeline](#run-data-pipeline) |
| 4 | + * [Run on codespaces](#run-on-codespaces) |
| 5 | + * [Run locally](#run-locally) |
| 6 | + * [Architecture and services in this template](#architecture-and-services-in-this-template) |
| 7 | + * [Using template](#using-template) |
| 8 | + * [Writing pipelines](#writing-pipelines) |
| 9 | + * [(Optional) Advanced cloud setup](#optional-advanced-cloud-setup) |
| 10 | + * [Prerequisites:](#prerequisites) |
| 11 | + * [Tear down infra](#tear-down-infra) |
| 12 | + |
| 13 | + |
| 14 | +# Data engineering project template |
| 15 | + |
| 16 | +Detailed explanation can be found **[`in this post`](https://www.startdataengineering.com/post/data-engineering-projects-with-free-template/)** |
| 17 | + |
| 18 | +## Run Data Pipeline |
| 19 | + |
| 20 | +Code available at **[data_engineering_project_template](https://github.com/josephmachado/data_engineering_project_template/tree/main?tab=readme-ov-file#data-engineering-project-template)** repository. |
| 21 | + |
| 22 | +### Run on codespaces |
| 23 | + |
| 24 | +You can run this data pipeline using GitHub codespaces. Follow the instructions below. |
| 25 | + |
| 26 | +1. Create codespaces by going to the **[data_engineering_project_template](https://github.com/josephmachado/data_engineering_project_template/tree/main?tab=readme-ov-file#data-engineering-project-template)** repository, cloning it(or click `Use this template` button) and then clicking on `Create codespaces on main` button. |
| 27 | +2. Wait for codespaces to start, then in the terminal type `make up`. |
| 28 | +3. Wait for `make up` to complete, and then wait for 30s (for Airflow to start). |
| 29 | +4. After 30s go to the `ports` tab and click on the link exposing port `8080` to access Airflow UI (username and password is `airflow`). |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +### Run locally |
| 36 | + |
| 37 | +To run locally, you need: |
| 38 | + |
| 39 | +1. [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) |
| 40 | +2. [Github account](https://github.com/) |
| 41 | +3. [Docker](https://docs.docker.com/engine/install/) with at least 4GB of RAM and [Docker Compose](https://docs.docker.com/compose/install/) v1.27.0 or later |
| 42 | + |
| 43 | +Clone the repo and run the following commands to start the data pipeline: |
| 44 | + |
| 45 | +```bash |
| 46 | +git clone https://github.com/josephmachado/data_engineering_project_template.git |
| 47 | +cd data_engineering_project_template |
| 48 | +make up |
| 49 | +sleep 30 # wait for Airflow to start |
| 50 | +make ci # run checks and tests |
| 51 | +``` |
| 52 | +Go to [http:localhost:8080](http:localhost:8080) to see the Airflow UI. Username and password are both `airflow`. |
| 53 | + |
| 54 | +## Architecture and services in this template |
| 55 | + |
| 56 | +This data engineering project template, includes the following: |
| 57 | + |
| 58 | +1. **`Airflow`**: To schedule and orchestrate DAGs. |
| 59 | +2. **`Postgres`**: To store Airflow's details (which you can see via Airflow UI) and also has a schema to represent upstream databases. |
| 60 | +3. **`DuckDB`**: To act as our warehouse |
| 61 | +4. **`Quarto with Plotly`**: To convert code in `markdown` format to html files that can be embedded in your app or servered as is. |
| 62 | +5. **`cuallee`**: To run data quality checks on the data we extracted from CoinCap API. |
| 63 | +6. **`minio`**: To provide an S3 compatible open source storage system. |
| 64 | + |
| 65 | +For simplicity services 1-5 of the above are installed and run in one container defined [here](./containers/airflow/Dockerfile). |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +The `coincap_elt` DAG in the [Airflow UI](http://localhost:8080) will look like the below image: |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +You can see the rendered html at [./visualizations/dashboard.html](https://github.com/josephmachado/data_engineering_project_template/blob/main/visualization/dashboard.html). |
| 74 | + |
| 75 | +The file structure of our repo is as shown below: |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +## Using template |
| 80 | + |
| 81 | +You can use this repo as a template and create your own, click on the `Use this template` button. |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +## Writing pipelines |
| 86 | + |
| 87 | +We have a sample pipeline at [coincap_elt.py](./dags/coincap_elt.py) that you can use as a starter to create your own DAGs. The tests are available at [./tests](./tests) folder. |
| 88 | + |
| 89 | +Once the `coincap_elt` DAG runs, we can see the dashboard html at [./visualization/dashboard.html](./visualization/dashboard.html) and will look like . |
| 90 | + |
| 91 | +## (Optional) Advanced cloud setup |
| 92 | + |
| 93 | +If you want to run your code on an EC2 instance, with terraform, follow the steps below. |
| 94 | + |
| 95 | +### Prerequisites: |
| 96 | + |
| 97 | +1. [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli) |
| 98 | +2. [AWS account](https://aws.amazon.com/) |
| 99 | +3. [AWS CLI installed](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) and [configured](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) |
| 100 | + |
| 101 | +You can create your GitHub repository based on this template by clicking on the `Use this template button in the **[data_engineering_project_template](https://github.com/josephmachado/data_engineering_project_template)** repository. Clone your repository and replace content in the following files |
| 102 | + |
| 103 | +1. **[CODEOWNERS](https://github.com/josephmachado/data_engineering_project_template/blob/main/.github/CODEOWNERS)**: In this file change the user id from `@josephmachado` to your Github user id. |
| 104 | +2. **[cd.yml](https://github.com/josephmachado/data_engineering_project_template/blob/main/.github/workflows/cd.yml)**: In this file change the `data_engineering_project_template` part of the `TARGET` parameter to your repository name. |
| 105 | +3. **[variable.tf](https://github.com/josephmachado/data_engineering_project_template/blob/main/terraform/variable.tf)**: In this file change the default values for `alert_email_id` and `repo_url` variables with your email and [github repository url](https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/GitHub-URL-find-use-example) respectively. |
| 106 | + |
| 107 | +Run the following commands in your project directory. |
| 108 | + |
| 109 | +```shell |
| 110 | +# Create AWS services with Terraform |
| 111 | +make tf-init # Only needed on your first terraform run (or if you add new providers) |
| 112 | +make infra-up # type in yes after verifying the changes TF will make |
| 113 | + |
| 114 | +# Wait until the EC2 instance is initialized, you can check this via your AWS UI |
| 115 | +# See "Status Check" on the EC2 console, it should be "2/2 checks passed" before proceeding |
| 116 | +# Wait another 5 mins, Airflow takes a while to start up |
| 117 | + |
| 118 | +make cloud-airflow # this command will forward Airflow port from EC2 to your machine and opens it in the browser |
| 119 | +# the user name and password are both airflow |
| 120 | + |
| 121 | +make cloud-metabase # this command will forward Metabase port from EC2 to your machine and opens it in the browser |
| 122 | +# use https://github.com/josephmachado/data_engineering_project_template/blob/main/env file to connect to the warehouse from metabase |
| 123 | +``` |
| 124 | + |
| 125 | +For the [continuous delivery](https://github.com/josephmachado/data_engineering_project_template/blob/main/.github/workflows/cd.yml) to work, set up the infrastructure with terraform, & defined the following repository secrets. You can set up the repository secrets by going to `Settings > Secrets > Actions > New repository secret`. |
| 126 | + |
| 127 | +1. **`SERVER_SSH_KEY`**: We can get this by running `terraform -chdir=./terraform output -raw private_key` in the project directory and paste the entire content in a new Action secret called SERVER_SSH_KEY. |
| 128 | +2. **`REMOTE_HOST`**: Get this by running `terraform -chdir=./terraform output -raw ec2_public_dns` in the project directory. |
| 129 | +3. **`REMOTE_USER`**: The value for this is **ubuntu**. |
| 130 | + |
| 131 | +### Tear down infra |
| 132 | + |
| 133 | +After you are done, make sure to destroy your cloud infrastructure. |
| 134 | + |
| 135 | +```shell |
| 136 | +make down # Stop docker containers on your computer |
| 137 | +make infra-down # type in yes after verifying the changes TF will make |
| 138 | +``` |
| 139 | + |
0 commit comments