Skip to content

Commit

Permalink
Merge pull request #419 from basedosdados/feat/dbt-lint
Browse files Browse the repository at this point in the history
feat: add dbt linter
  • Loading branch information
laura-l-amaral authored Feb 14, 2024
2 parents 46f2fb9 + 47a8874 commit 6c44ef4
Show file tree
Hide file tree
Showing 449 changed files with 34,224 additions and 28,614 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*.sql linguist-detectable=true
*.sql linguist-detectable=true
14 changes: 2 additions & 12 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
---
name: CD

on:
push:
branches:
- main

branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: basedosdados/queries-basedosdados-dev/dbt-rpc

jobs:
build-container:
name: Build, publish and register
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Import Secrets
id: import_secrets
uses: hashicorp/[email protected]
Expand All @@ -28,41 +24,35 @@ jobs:
secret/data/gcp_credentials/basedosdados-dev GCP_PROJECT_ID | GCP_PROJECT_ID ;
secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_NAME | GKE_CLUSTER_NAME ;
secret/data/gcp_credentials/basedosdados-dev GKE_CLUSTER_ZONE | GKE_CLUSTER_ZONE ;
- name: Setup Google Cloud CLI
uses: google-github-actions/[email protected]
with:
service_account_key: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }}
project_id: ${{ steps.import_secrets.outputs.GKE_PROJECT_ID }}
export_default_credentials: true

- name: Get GKE credentials
uses: google-github-actions/[email protected]
with:
cluster_name: ${{ steps.import_secrets.outputs.GKE_CLUSTER_NAME }}
location: ${{ steps.import_secrets.outputs.GKE_CLUSTER_ZONE }}
credentials: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }}

- name: Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY}}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}

- name: Set up Kustomize
run: |-
curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ./kustomize
- name: Deploy
run: |-
./kustomize edit set image gcr.io/PROJECT_ID/IMAGE_DBT:TAG=$REGISTRY/$IMAGE_NAME:$GITHUB_SHA
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/ci-dbt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: CI dbt
on:
pull_request:
paths: ['**.sql', '**.yaml']
jobs:
lint:
name: Lint dbt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v4
with:
cache: pip
python-version: '3.10'
- name: Install requirements
run: pip install -r requirements-dev.txt
- name: Lint sql
run: sqlfmt --diff .
- name: Lint yaml
run: yamlfix --exclude ".kubernetes/**/*" .
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: Lint Dockerfile

---
name: CI Docker
on:
pull_request:

paths: [Dockerfile]
jobs:
docker_lint:
name: Lint Dockerfile
lint:
name: Lint dockerfile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4
- name: Run hadolint
uses: reviewdog/action-hadolint@v1
with:
Expand Down
18 changes: 4 additions & 14 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
---
name: Deploy docs

on:
push:
branches:
- main

branches: [main]
jobs:
docs:
name: Deploy docs
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Import Secrets
id: import_secrets
uses: hashicorp/[email protected]
Expand All @@ -21,33 +18,26 @@ jobs:
token: ${{ secrets.VAULT_TOKEN}}
secrets: |
secret/data/queries_credentials/<GCP_PROJECT_NAME> GCP_SA_KEY | GCP_SA_KEY;
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9.x"

python-version: 3.9.x
- name: Upgrade pip
run: |
pip install -U pip
- name: Install dependencies
run: |
pip3 install -r requirements-actions.txt -r requirements.txt
pip3 install -r requirements-dev.txt -r requirements.txt
- name: Setup credentials
run: |
echo ${{ steps.import_secrets.outputs.GCP_SA_KEY }} > dbt-sa.json
python3 .github/workflows/scripts/modify_profiles.py
- name: Generate docs
run: |
dbt docs generate --profiles-dir .
- name: Delete credentials
run: |
rm dbt-sa.json
- name: Deploy docs
uses: JamesIves/[email protected]
with:
Expand Down
18 changes: 5 additions & 13 deletions .github/workflows/metadata_automation.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
---
name: Metadata Automation

on:
push:
branches:
- '*'

branches: ['*']
jobs:
update-metadata:
name: Update metadata from Google Sheets
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Import Secrets
id: import_secrets
uses: hashicorp/[email protected]
Expand All @@ -21,28 +18,23 @@ jobs:
token: ${{ secrets.VAULT_TOKEN}}
secrets: |
secret/data/queries_credentials/basedosdados-dev GCP_SA_KEY_BASE64 | GCP_SA_KEY_BASE64;
- name: Setup Python version
uses: actions/setup-python@v2
with:
python-version: "3.9"

python-version: '3.9'
- name: Install Python dependencies for actions
run: |-
pip install -r requirements-actions.txt
pip install -r requirements-dev.txt
- name: Checkout to the head ref
run: |-
git fetch --depth=1
git checkout ${{ github.head_ref }}
- name: Update metadata
env:
GCP_SA_KEY_BASE64: ${{ steps.import_secrets.outputs.GCP_SA_KEY_BASE64 }}
run: |-
python3 .github/workflows/scripts/metadata_automation.py
- name: Commit changed files
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'Update metadata'
commit_message: Update metadata
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ venv-dbt/
.user.yml
dbt_packages
profiles.yml
gists/test.py
gists/test.py
15 changes: 6 additions & 9 deletions .kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ spec:
- name: credentials-prod
mountPath: /credentials-prod/
readOnly: true
command:
- "/bin/sh"
- "-c"
command: [/bin/sh, -c]
args:
- >
dbt deps;
dbt-rpc serve --profiles-dir . --profile default --target dev --host 0.0.0.0 --port 8580
dbt-rpc serve --profiles-dir . --profile default --target dev --host
0.0.0.0 --port 8580
volumes:
- name: credentials-dev
secret:
Expand All @@ -45,7 +44,6 @@ spec:
secret:
secretName: credentials-prod
restartPolicy: Always

---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -78,13 +76,12 @@ spec:
- name: credentials-prod
mountPath: /credentials-prod/
readOnly: true
command:
- "/bin/sh"
- "-c"
command: [/bin/sh, -c]
args:
- >
dbt deps;
dbt-rpc serve --profiles-dir . --profile default --target prod --host 0.0.0.0 --port 8580
dbt-rpc serve --profiles-dir . --profile default --target prod --host
0.0.0.0 --port 8580
volumes:
- name: credentials-dev
secret:
Expand Down
5 changes: 2 additions & 3 deletions .kubernetes/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ metadata:
name: dbt-rpc-dev
spec:
ports:
- name: "8580"
- name: '8580'
port: 8580
targetPort: 8580
selector:
app: dbt-rpc-dev

---
apiVersion: v1
kind: Service
Expand All @@ -22,7 +21,7 @@ metadata:
name: dbt-rpc-prod
spec:
ports:
- name: "8580"
- name: '8580'
port: 8580
targetPort: 8580
selector:
Expand Down
26 changes: 26 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: no-commit-to-branch
args: [-b, main]
- id: trailing-whitespace
- repo: https://github.com/tconbeer/sqlfmt
rev: v0.20.0
hooks:
- id: sqlfmt
language_version: python
additional_dependencies: ['.[jinjafmt]']
- repo: local
hooks:
- id: yamlfix
name: yamlfix
types: [yaml]
language: system
entry: yamlfix --exclude ".kubernetes/**/*" .
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ logs:
.PHONY: status
status:
docker-compose ps

.PHONY: lint
lint:
pre-commit run --all-files
Loading

0 comments on commit 6c44ef4

Please sign in to comment.