Skip to content

Commit ca70dda

Browse files
author
CNE Bot
committed
Initial commit: Template content from https://github.com/tikalk/cne-dbt-template
0 parents  commit ca70dda

157 files changed

Lines changed: 7841 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.commitlintrc.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"rules": {
3+
"header-max-length": [
4+
2,
5+
"always",
6+
72
7+
],
8+
"body-leading-blank": [
9+
2,
10+
"always"
11+
],
12+
"type-empty": [
13+
2,
14+
"never"
15+
],
16+
"type-enum": [
17+
2,
18+
"always",
19+
[
20+
"feat",
21+
"fix",
22+
"docs",
23+
"chore",
24+
"refactor",
25+
"test",
26+
"revert"
27+
]
28+
],
29+
"scope-empty": [
30+
2,
31+
"never"
32+
],
33+
"scope-enum": [
34+
2,
35+
"always",
36+
[
37+
"dbt",
38+
"deps",
39+
"tests",
40+
"infra",
41+
"common",
42+
"dagster",
43+
"snowflake",
44+
"bigquery"
45+
]
46+
]
47+
}
48+
}

.dbt-checkpoint.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version: 1
2+
disable-tracking: true

.devcontainer/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
2+
3+
# Install system dependencies
4+
RUN apt-get update && apt-get install -y \
5+
git \
6+
postgresql-client \
7+
curl \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
# install uv
11+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
12+
13+
# Install dbt
14+
RUN pip install --no-cache-dir \
15+
dbt-core \
16+
dbt-postgres \
17+
dbt-bigquery
18+
# Create non-root user
19+
RUN useradd -ms /bin/bash vscode
20+
USER vscode
21+
WORKDIR /home/vscode
22+
23+
# Configure dbt profiles directory
24+
RUN mkdir -p /home/vscode/.dbt
25+
26+
# Create a basic profiles.yml template
27+
RUN echo "default:\n\
28+
target: dev\n\
29+
outputs:\n\
30+
dev:\n\
31+
type: postgres\n\
32+
host: localhost\n\
33+
user: dbt_user\n\
34+
password: dbt_password\n\
35+
port: 5432\n\
36+
dbname: dbt\n\
37+
schema: dbt_schema\n\
38+
threads: 4" > /home/vscode/.dbt/profiles.yml
39+
40+
# Add dbt to PATH
41+
ENV PATH="/home/vscode/.local/bin:${PATH}"

.devcontainer/devcontainer.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "Dev Environment",
3+
"dockerFile": "Dockerfile",
4+
"runArgs": [
5+
"--env-file",
6+
".env"
7+
],
8+
"initializeCommand": "[[ -f .env ]] || touch .env",
9+
"containerEnv": {
10+
"DEV_CONTAINER": "true",
11+
"SSH_AUTH_SOCK": "/tmp/op_sock",
12+
"UV_LINK_MODE": "copy",
13+
"SNOWFLAKE_PRIVATE_KEY_PATH": "/workspace/rsa_key.p8 ",
14+
"DATABASE_HOST": "db",
15+
"HISTFILE": "${localWorkspaceFolder}/.history",
16+
},
17+
"extensions": [
18+
"ms-python.python",
19+
"ms-python.vscode-pylance",
20+
"innoverio.vscode-dbt-power-user",
21+
"bungcip.better-toml", // For handling dbt's `profiles.yml` and `.toml` files
22+
"redhat.vscode-yaml", // YAML support
23+
"EditorConfig.EditorConfig", // For consistent editor settings
24+
"ms-azuretools.vscode-docker",
25+
"mtxr.sqltools",
26+
"mtxr.sqltools-driver-pg"
27+
],
28+
"settings": {
29+
"python.defaultInterpreterPath": "/usr/local/bin/python",
30+
"python.linting.enabled": true,
31+
"python.linting.mypyEnabled": true,
32+
"python.linting.pylintEnabled": true,
33+
"python.formatting.provider": "black",
34+
"editor.formatOnSave": true,
35+
"terminal.integrated.shell.linux": "/usr/bin/zsh",
36+
"terminal.integrated.profiles.linux": {
37+
"zsh": {
38+
"path": "/usr/bin/zsh",
39+
"args": [
40+
"-c",
41+
"source .venv/bin/activate; zsh"
42+
]
43+
}
44+
},
45+
"terminal.integrated.defaultProfile.linux": "zsh",
46+
"files.associations": {
47+
"*.sql": "jinja-sql"
48+
},
49+
"docker.dockerode": "socket",
50+
"docker.exposeDockerCli": true
51+
},
52+
"forwardPorts": [
53+
5432
54+
],
55+
"mounts": [
56+
"source=${localEnv:HOME}/.gitconfig,target=/home/vscode/.gitconfig,type=bind,consistency=cached",
57+
"source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached",
58+
"source=${localEnv:HOME}/.config/op,target=/home/vscode/.config/op,type=bind"
59+
],
60+
"postCreateCommand": ".devcontainer/setup_devcontainer.sh"
61+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
echo "Seting up vscode"
2+
mkdir -p /home/$USERNAME/.vscode
3+
4+
echo "Seting up venv"
5+
uv venv
6+
uv sync
7+
pre-commit install
8+
pre-commit install --hook-type pre-commit --hook-type pre-push
9+
pre-commit install-hooks
10+
pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks

.github/CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This is a comment.
2+
# Each line is a file pattern followed by one or more owners.
3+
4+
# Default code owners
5+
# Order is important; the last matching pattern takes the most precedence.
6+
* @tikal/whs

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
- [ ] Commit history is tidy
2+
3+
### What this does
4+
5+
_Explain why this PR exists_
6+
7+
### Notes for the reviewer
8+
9+
_Instructions on how to run this locally, background context, what to review, questions…_
10+
11+
### Additional information
12+
13+
- GitLab ticket: https://gitlab.tikalk.dev/
14+
- Link to documentation: https://www.notion.so/
15+
16+
### Screenshots
17+
18+
_Visuals that may help the reviewer_

.github/workflows/ci.yml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: DBT Build
2+
3+
on:
4+
push:
5+
branches:
6+
- main #
7+
pull_request:
8+
types: [closed, opened, synchronize] # 👈 Add this trigger for PR closures
9+
10+
11+
jobs:
12+
run-dbt:
13+
name: Build DBT Models
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write # This gives permission to push tags
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.head_ref }}
22+
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: '3.12'
28+
29+
- name: Write BIGQUERY_KEYFILE_JSON to File
30+
env:
31+
BIGQUERY_KEYFILE_JSON_BASE64: ${{ secrets.BIGQUERY_KEYFILE_JSON_BASE64 }}
32+
run: |
33+
echo "$BIGQUERY_KEYFILE_JSON_BASE64" | base64 --decode > /tmp/bigquery-keyfile.json
34+
echo "BIGQUERY_KEYFILE_PATH=/tmp/bigquery-keyfile.json" >> $GITHUB_ENV
35+
36+
- name: Calc dataset name
37+
run: |
38+
echo "github_ref: ${{ github.ref }}"
39+
echo "event_name: ${{ github.event_name }}"
40+
echo "action: ${{ github.event.action }}"
41+
echo "number: ${{ github.event.number }}"
42+
43+
branch_name=${{ github.event.number }}
44+
45+
# If the branch is main, append the latest short commit hash
46+
if [ -z "$branch_name" ] || [ "$branch_name" == "main" ]; then
47+
short_commit_hash=$(git rev-parse --short HEAD)
48+
branch_name="${branch_name}_${short_commit_hash}"
49+
fi
50+
51+
dataset_name=$(echo "$branch_name" | sed 's/[^a-zA-Z0-9_]/_/g')
52+
echo "dataset_name: SAAS_pr__${dataset_name}"
53+
echo "DB_NAME=pr__${dataset_name}" >> $GITHUB_ENV
54+
55+
- name: Install the latest version of uv
56+
run: |
57+
curl -LsSf https://astral.sh/uv/install.sh | sh
58+
echo "$HOME/.local/bin" >> $GITHUB_PATH
59+
export PATH="$HOME/.local/bin:$PATH"
60+
uv venv
61+
uv pip install --upgrade setuptools
62+
uv sync
63+
uv pip install -e .
64+
65+
66+
- uses: robinraju/release-downloader@v1
67+
with:
68+
latest: true
69+
out-file-path: target/last_run
70+
fileName: '*.json'
71+
72+
73+
- name: Run File Validation
74+
env:
75+
DATASET_PREFIX: "CI_"
76+
DBT_PROFILE_PROJECT: ${{ vars.DBT_PROFILE_PROJECT }}
77+
BIGQUERY_DATABASE: ${{ vars.BIGQUERY_DATABASE }}
78+
79+
run: |
80+
source .venv/bin/activate
81+
dbt deps
82+
dbt parse
83+
pre-commit run --all-files
84+
85+
86+
- name: Run DBT
87+
if: (github.event_name == 'push') || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize'))
88+
env:
89+
DATASET_PREFIX: "CI_"
90+
DBT_SCHEMA: "CI_DWH"
91+
DBT_PROFILE_PROJECT : ${{ secrets.DBT_PROFILE_PROJECT }}
92+
BIGQUERY_DATABASE: ${{ vars.BIGQUERY_DATABASE }}
93+
run: |
94+
source .venv/bin/activate
95+
dbt deps
96+
dbt debug --debug
97+
# dbt run-operation create_database --args "{database_name: ${DBT_PROFILE_PROJECT}.${DBT_SCHEMA}}"
98+
# dbt run-operation create_database --args "{database_name: ${DBT_SCHEMA}_GOLD}"
99+
# dbt run-operation create_database --args "{database_name: ${DBT_SCHEMA}_SILVER}"
100+
dbt build
101+
if ${{ github.ref == 'refs/heads/main' }}; then
102+
dbt build
103+
else
104+
dbt build --select "+state:modified+" --state ./target/last_run
105+
fi
106+
107+
- name: Prepare Docs Site Artifact
108+
if: (github.event_name == 'push')
109+
env:
110+
DATASET_PREFIX: "CI_"
111+
DBT_SCHEMA: "CI_DWH"
112+
DBT_PROFILE_PROJECT : ${{ secrets.DBT_PROFILE_PROJECT }}
113+
BIGQUERY_DATABASE: ${{ vars.BIGQUERY_DATABASE }}
114+
115+
run: |
116+
source .venv/bin/activate
117+
dbt docs generate --static
118+
mkdir -p docs_site
119+
cp target/static_index.html target/index.html target/manifest.json target/catalog.json docs_site
120+
121+
- name: Extract release version
122+
if: (github.event_name == 'push')
123+
run: |
124+
# Get today's date in YYYY.MM format
125+
TODAY=$(date +"%Y.%m")
126+
127+
# Fetch existing tags
128+
git fetch --tags > /dev/null 2>&1
129+
EXISTING_TAGS=$(git tag | grep "^$TODAY" | sort -V)
130+
131+
# Determine the next increment
132+
if [[ -z "$EXISTING_TAGS" ]]; then
133+
NEW_TAG="${TODAY}.1"
134+
else
135+
LAST_TAG=$(echo "$EXISTING_TAGS" | tail -n 1)
136+
LAST_INCREMENT=${LAST_TAG##*.} # Extract the last number
137+
NEW_TAG="${TODAY}.$((LAST_INCREMENT + 1))"
138+
fi
139+
140+
# Print the new tag
141+
echo "$NEW_TAG"
142+
echo "RELEASE_VERSION=$NEW_TAG" >> $GITHUB_ENV
143+
144+
145+
- name: Create and push Git tag
146+
if: (github.event_name == 'push')
147+
run: |
148+
git tag $RELEASE_VERSION
149+
git push origin $RELEASE_VERSION
150+
151+
- name: Upload release asset
152+
if: (github.event_name == 'push')
153+
uses: softprops/action-gh-release@v2
154+
with:
155+
tag_name: ${{ env.RELEASE_VERSION }}
156+
files: |
157+
target/static_index.html
158+
target/index.html
159+
target/manifest.json
160+
target/catalog.json
161+
target/run_results.json
162+
env:
163+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+
165+
- name: Cleanup (e.g., delete resources tied to the branch)
166+
if: (github.event.action == 'closed' || github.ref == 'refs/heads/main')
167+
env:
168+
DATASET_PREFIX: "CI_"
169+
DBT_SCHEMA: "CI_DWH"
170+
DBT_PROFILE_PROJECT : ${{ secrets.DBT_PROFILE_PROJECT }}
171+
BIGQUERY_DATABASE: ${{ vars.BIGQUERY_DATABASE }}
172+
173+
run: |
174+
source .venv/bin/activate
175+
dbt deps
176+
dbt run-operation delete_database --args "{database_name: ${DBT_PROFILE_PROJECT}.${DBT_SCHEMA}}"

0 commit comments

Comments
 (0)