-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into marcin/use-official-c…
…apz-image
- Loading branch information
Showing
38 changed files
with
771 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
## Connecting to AWS Secrets Backend | ||
|
||
Airflow allows you the opportunity to connect to various services as a Secrets Backend as an alternative to using the | ||
Airflow UI to manage connections. One of these services is [AWS Secrets Manager](https://airflow.apache.org/docs/apache-airflow-providers-amazon/stable/secrets-backends/aws-secrets-manager.html). | ||
Once you add below configurations, Airflow will be able to retrieve Secrets from AWS Secrets Manager (provided that they | ||
have the same prefixes specified in the `KWARGS` config). | ||
|
||
In this scenario, the prefixes are `airflow/connections` & `airflow/variables`, so any values stored under the | ||
`airflow/connections` prefix would be treated the same as an object stored in the `Admin >> Connections` menu of the | ||
Airflow UI. Any values stored under the `airflow/variables` prefix would be treated the same as an object stored in the | ||
`Admin >> Variables` menu of the Airflow UI. | ||
|
||
### edit values.yaml | ||
|
||
You'll then want to edit `airflow/helm/airflow/values.yaml` in your installation repo with something like: | ||
|
||
```yaml | ||
airflow: | ||
airflow: | ||
airflow: | ||
config: | ||
AIRFLOW__SECRETS__BACKEND: airflow.providers.amazon.aws.secrets.secrets_manager.SecretsManagerBackend | ||
AIRFLOW__SECRETS__BACKEND_KWARGS: '{"connections_prefix": "airflow/connections","variables_prefix": | ||
"airflow/variables"}' | ||
``` | ||
Alternatively, you should be able to do this in the configuration section for airflow in your plural console as well. | ||
### add policy to AWS role | ||
When installing the Airflow Application, Plural added a default role for Airflow. The role will be called | ||
`<your-cluster-name>-airflow`. You will need to add a policy to that role to allow it to access AWS Secrets Manager. You | ||
can use this policy as a starting point: | ||
|
||
```json | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "VisualEditor0", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"secretsmanager:GetRandomPassword", | ||
"secretsmanager:ListSecrets" | ||
], | ||
"Resource": "*" | ||
}, | ||
{ | ||
"Sid": "VisualEditor1", | ||
"Effect": "Allow", | ||
"Action": "secretsmanager:*", | ||
"Resource": "arn:aws:secretsmanager:<insert-aws-region>:<insert-aws-account-number>:secret:airflow/*" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### redeploy | ||
|
||
From there, you should be able to run `plural build --only airflow && plural deploy --commit "use aws secrets manager | ||
backend"` to use the secrets backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
## Running dbt core in Airflow via Cosmos | ||
|
||
[Cosmos](https://github.com/astronomer/astronomer-cosmos) is an open source project that allows you to run dbt core | ||
projects in Airflow natively. To date, it is probably one of the best ways to run dbt core in Airflow. | ||
|
||
### custom dockerfile | ||
|
||
In order to run dbt core effectively, we recommend you bake a new docker image against ours and then wiring it into your | ||
installation. Please follow the [pip-packages](./pip-packages.md) guide for instructions on baking your own image. | ||
|
||
Airflow and dbt both share common dependencies (i.e. Jinja). This can cause dependency clashes between Airflow and your | ||
dbt adapter when you upgrade them. To solve for this, we can put our dbt adapter in its own python virtual environment. | ||
This is possible by adding the following step to your custom `Dockerfile`: | ||
|
||
```dockerfile | ||
FROM docker.io/apache/airflow:2.6.3-python3.10 | ||
|
||
USER root | ||
RUN apt-get -yq update \ | ||
&& apt-get -yq install --no-install-recommends \ | ||
git \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
USER airflow | ||
|
||
COPY requirements.txt requirements.txt | ||
RUN pip freeze | grep -i apache-airflow > protected-packages.txt \ | ||
&& pip install --constraint ./protected-packages.txt --no-cache-dir -r ./requirements.txt \ | ||
&& rm -rf ./protected-packages.txt ./requirements.txt | ||
|
||
## create virtual environments for dbt | ||
RUN export PIP_USER=false && python -m venv dbt_venv && source dbt_venv/bin/activate && \ | ||
pip install --no-cache-dir dbt-redshift==1.6.1 && deactivate && export PIP_USER=true | ||
|
||
``` | ||
|
||
In this example, we've installed the `dbt-redshift` adapter into the python virtual environment. However, you can swap | ||
the adapter for the one that suites your needs (i.e. `dbt-bigquery`, `dbt-snowflake`, etc.) | ||
|
||
### add dbt project to your dags directory | ||
|
||
In your dags directory, add a folder called `dbt`. Within that folder, copy your dbt project. For example, if you were | ||
going to add Fishtown Analytic's classic [Jaffle Shop project](https://github.com/dbt-labs/jaffle_shop), your project | ||
directory would look something like this: | ||
|
||
```yaml | ||
plural-airflow-repo | ||
└── dags | ||
└── dbt | ||
└── jaffle_shop | ||
├── LICENSE | ||
├── README.md | ||
├── dbt_project.yml | ||
├── etc | ||
│ ├── dbdiagram_definition.txt | ||
│ └── jaffle_shop_erd.png | ||
├── models | ||
│ ├── customers.sql | ||
│ ├── docs.md | ||
│ ├── orders.sql | ||
│ ├── overview.md | ||
│ ├── schema.yml | ||
│ └── staging | ||
│ ├── schema.yml | ||
│ ├── stg_customers.sql | ||
│ ├── stg_orders.sql | ||
│ └── stg_payments.sql | ||
└── seeds | ||
├── raw_customers.csv | ||
├── raw_orders.csv | ||
└── raw_payments.csv | ||
``` | ||
|
||
### point Cosmos class to the nested dbt project directory | ||
|
||
In your dags directory, add a `jaffle_shop.py` file to create a DAG, and add the following contents to it: | ||
|
||
```python | ||
""" | ||
## Jaffle Shop | ||
Example of using cosmos to run the jaffle shop dbt project | ||
""" | ||
import os | ||
from datetime import datetime | ||
|
||
from airflow import DAG | ||
from cosmos import DbtTaskGroup, ExecutionConfig, ProfileConfig, ProjectConfig | ||
from cosmos.profiles.redshift.user_pass import RedshiftUserPasswordProfileMapping | ||
|
||
'''these next lines help to resolve the path to your dbt project in the plural airflow instance vs. local development''' | ||
|
||
# Dynamically retrieves the Airflow Home directory | ||
airflow_home = os.getenv("AIRFLOW_HOME", "/usr/local/airflow") | ||
|
||
# I've set a local env variable ENVIRONMENT=DEV to determine if dag is running in plural airflow or local airflow | ||
if os.getenv("ENVIRONMENT", "PROD") == "DEV": | ||
# the project path when running Airflow locally | ||
dbt_project_path = f"{airflow_home}/dags/dbt/jaffle_shop" | ||
else: | ||
# the project path in plural cluster | ||
dbt_project_path = f"{airflow_home}/dags/repo/dags/dbt/jaffle_shop" | ||
|
||
# the path to the dbt executable that's within the venv created in Dockerfile | ||
dbt_executable_path = f"{airflow_home}/dbt_venv/bin/dbt" | ||
|
||
# Profile mapping to connect dbt to a target | ||
profile_mapping = RedshiftUserPasswordProfileMapping( | ||
# airflow connection id to use for the dbt target | ||
conn_id="redshift_default", | ||
profile_args={ | ||
# my redshift database name | ||
"dbname": "dev", | ||
# default schema to write to if one isn't specified in .yml or .sql dbt files | ||
"schema": "a_default_schema_name" | ||
} | ||
) | ||
|
||
with DAG( | ||
dag_id="jaffle_shop", | ||
start_date=datetime(2023, 10, 6), | ||
schedule=None, | ||
doc_md=__doc__, | ||
tags=["dbt", "redshift"], | ||
): | ||
DbtTaskGroup( | ||
project_config=ProjectConfig( | ||
dbt_project_path=dbt_project_path | ||
), | ||
execution_config=ExecutionConfig( | ||
dbt_executable_path=dbt_executable_path | ||
), | ||
profile_config=ProfileConfig( | ||
profile_name="jaffle_shop", # the default profile - recommended to be your dbt project name | ||
target_name="cosmos_target", # the default target - recommended to just leave as cosmos_target | ||
profile_mapping=profile_mapping, | ||
) | ||
) | ||
``` | ||
|
||
This example uses a Redshift Data Warehouse as a target, but you can also configure profiles for other targets (i.e. | ||
Snowflake, BigQuery, etc.). For more information, please review Cosmos Docs [here](https://astronomer.github.io/astronomer-cosmos/profiles/index.html). | ||
After making these changes, you should see the DAG parse like so: | ||
|
||
![jaffle_shop_dag.png](https://github.com/astronomer/astronomer-cosmos/blob/main/docs/_static/jaffle_shop_task_group.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ maintainers: | |
email: [email protected] | ||
- name: David van der Spek | ||
email: [email protected] | ||
version: 0.8.75 | ||
version: 0.8.77 | ||
dependencies: | ||
- name: external-dns | ||
version: 6.14.1 | ||
|
@@ -30,7 +30,7 @@ dependencies: | |
repository: https://kubernetes.github.io/autoscaler | ||
- name: aws-load-balancer-controller | ||
condition: aws-load-balancer-controller.enabled | ||
version: 1.4.8 | ||
version: 1.6.1 | ||
repository: https://aws.github.io/eks-charts | ||
- name: aws-ebs-csi-driver | ||
condition: aws-ebs-csi-driver.enabled | ||
|
Binary file removed
BIN
-17.6 KB
bootstrap/helm/bootstrap/charts/aws-load-balancer-controller-1.4.8.tgz
Binary file not shown.
Binary file added
BIN
+18.9 KB
bootstrap/helm/bootstrap/charts/aws-load-balancer-controller-1.6.1.tgz
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ homepage: https://www.mage.ai/ | |
gitUrl: https://github.com/mage-ai/mage-ai | ||
contributors: | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
dependencies: | ||
- name: kuberay-operator | ||
repository: https://kevin85421.github.io/kuberay | ||
version: 0.3.0 | ||
digest: sha256:abb43e05246ec58ef6137df26d2d1692f59066058695b84d17986e5622d82690 | ||
generated: "2022-09-21T15:06:07.583379+02:00" | ||
repository: https://ray-project.github.io/kuberay-helm/ | ||
version: 0.6.0 | ||
digest: sha256:68767f4de687430221785f64d5b752285141d2192cae4c91a55b13d40106d063 | ||
generated: "2023-10-05T14:25:03.985572273-07:00" |
Oops, something went wrong.