Skip to content

Commit 95bb4e2

Browse files
authored
ci(airflow): Add dbt image workflow (#343)
add dbt image workflow
1 parent 5481ebf commit 95bb4e2

File tree

9 files changed

+119
-0
lines changed

9 files changed

+119
-0
lines changed

.github/workflows/dev_dbt.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Build and publish dbt-demo
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- main
9+
# TODO (@NickLarsenNZ): Also build on release branches, but with a stackable0.0.0-dev or stackableXX.X.X tag.
10+
# - release-*
11+
paths:
12+
- demos/airflow-scheduled-job/dbt/Dockerfile
13+
- demos/airflow-scheduled-job/dbt/requirements.txt
14+
- .github/workflows/dev_dbt.yaml
15+
16+
jobs:
17+
build_image:
18+
name: Reusable Workflow
19+
uses: ./.github/workflows/reusable_build_image.yaml
20+
secrets:
21+
harbor-robot-secret: ${{ secrets.HARBOR_ROBOT_DEMOS_GITHUB_ACTION_BUILD_SECRET }}
22+
slack-token: ${{ secrets.SLACK_CONTAINER_IMAGE_TOKEN }}
23+
with:
24+
image-name: dbt-demo
25+
# TODO (@NickLarsenNZ): Use a versioned image with stackable0.0.0-dev or stackableXX.X.X so that
26+
# the demo is reproducable for the release and it will be automatically replaced for the release branch.
27+
image-version: 0.0.1
28+
containerfile-path: demos/airflow-scheduled-job/dbt/Dockerfile
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM python:3.12-slim-bullseye AS builder
2+
3+
# Install build dependencies
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
gcc \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Create virtual environment
10+
RUN python -m venv /opt/venv
11+
ENV PATH="/opt/venv/bin:$PATH"
12+
13+
# Install Python packages
14+
COPY requirements.txt .
15+
RUN pip install --no-cache-dir --upgrade pip && \
16+
pip install --no-cache-dir -r requirements.txt
17+
18+
# Final stage
19+
FROM python:3.12-slim-bullseye
20+
21+
RUN apt-get update && apt-get install -y \
22+
git \
23+
curl \
24+
vim \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
# Copy virtual environment from builder
28+
COPY --from=builder /opt/venv /opt/venv
29+
ENV PATH="/opt/venv/bin:$PATH"
30+
31+
WORKDIR /dbt
32+
33+
COPY dbt_test ./dbt_test
34+
35+
# Security: non-root user
36+
RUN useradd -m -u 1000 dbt && chown -R dbt:dbt /dbt
37+
USER dbt
38+
39+
ENV DBT_PROFILES_DIR=/dbt
40+
41+
CMD ["dbt", "run"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: 'dbt_demo'
3+
version: '1.0.0'
4+
config-version: 2
5+
profile: 'trino_demo'
6+
model-paths: ['models']
7+
macro-paths: ['macros']
8+
target-path: "target"
9+
clean-targets: ['target']
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% test id_in_range(model, column_name) %}
2+
select *
3+
from {{ model }}
4+
where {{ column_name }} < 1 or {{ column_name }} > 5
5+
{% endtest %}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{ config(materialized='table') }}
2+
select * from (values (1),(2),(3),(4),(5)) as t(id)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
version: 2
3+
4+
models:
5+
- name: my_table
6+
description: "A simple demo table with integer IDs"
7+
columns:
8+
- name: id
9+
description: "ID value"
10+
tests:
11+
- not_null # built-in dbt test
12+
- unique # optional: ensure no duplicates
13+
- id_in_range
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
packages: []
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
trino_demo:
3+
outputs:
4+
iceberg:
5+
type: trino
6+
method: ldap
7+
user: "{{ env_var('TRINO_USER') }}"
8+
password: "{{ env_var('TRINO_PASSWORD') }}"
9+
catalog: iceberg
10+
host: "{{ env_var('TRINO_HOST') }}"
11+
port: "{{ env_var('TRINO_PORT') | int }}"
12+
schema: dbt_schema
13+
threads: 1
14+
cert: "{{ env_var('CERT_PATH') }}"
15+
verify: true
16+
17+
target: iceberg
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dbt-core==1.10.13
2+
dbt-trino==1.9.3

0 commit comments

Comments
 (0)