Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #30

Closed
wants to merge 3 commits into from
Closed

Test #30

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/check_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
DBT_PROFILES_DIR: ./
BIGQUERY_PROJECT_ID: ${{ vars.DBT_BIGQUERY_PROJECT_ID }}
BIGQUERY_DATASET_ID: ${{ vars.DBT_BIGQUERY_DATASET_ID }}
BIGQUERY_SERVICE_FILE: ./dbt-service-account.jso
BIGQUERY_SERVICE_FILE: ./dbt-service-account.json
KEYFILE_CONTENTS: ${{secrets.KEYFILE_CONTENTS}}

SNOWFLAKE_ACCOUNT: ${{ vars.SNOWFLAKE_ACCOUNT }}
Expand All @@ -25,7 +25,10 @@ jobs:
name: install and build dbt
runs-on: ubuntu-latest

steps:
steps:
- name: Print current branch
run: echo "Deploying to production server on branch $GITHUB_BASE_REF"

- name: Install Python 3.9
uses: actions/setup-python@v2
with:
Expand All @@ -35,7 +38,7 @@ jobs:
uses: actions/checkout@v2

- name: Set up Snowflake environment
if: github.ref != 'refs/heads/main'
if: ${{ github.base_ref != 'refs/heads/main' }}
run: |
pip install dbt-snowflake pandas
dbt --version
Expand All @@ -45,10 +48,10 @@ jobs:
working-directory: ${{ env.working-directory }}

- name: Set up BigQuery environment
if: github.ref == 'refs/heads/main'
if: ${{ github.base_ref == 'refs/heads/main' }}
run: |
echo "$KEYFILE_CONTENTS" > ${{ env.BIGQUERY_SERVICE_FILE }}
pip install dbt-snowflake pandas
pip install dbt-bigquery pandas
dbt --version
dbt deps
env:
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Dev build image & push

on:
push:
branches: [ main ]

env:
working-directory: silverwork_dbt

jobs:
build:
name: Dockerize dbt
runs-on: ubuntu-latest

steps:
# actions/checkout MUST come before auth
- name: Checkout
uses: actions/checkout@v2

- id: auth
name: Authenticate with Google Cloud
uses: "google-github-actions/auth@v1"
with:
token_format: access_token
project_id: ${{ vars.DBT_BIGQUERY_PROJECT_ID }}
credentials_json: ${{ secrets.KEYFILE_CONTENTS }}
access_token_lifetime: 300s

- name: Login to Artifact Registry
uses: docker/login-action@v1
with:
registry: us-central1-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}

- name: Get tag
id: get-tag
run: echo ::set-output name=short_ref::${GITHUB_REF#refs/*/}

- name: Build & Push Image
uses: docker/build-push-action@v2
with:
context: ${{ github.workspace }}
push: true
tags: |
${{ secrets.DBT_REGISTRY_ENDPOINT }}:${{ steps.get-tag.outputs.short_ref }}
${{ secrets.DBT_REGISTRY_ENDPOINT }}:latest

# - name: Trigger Airflow init dag
# env:
# AIRFLOW_WEBSERVER_ENDPOINT: ${{ secrets.AIRFLOW_WEBSERVER_ENDPOINT }}
# AIRFLOW_WEBSERVER_ID: ${{ secrets.AIRFLOW_WEBSERVER_ID }}
# AIRFLOW_WEBSERVER_PASSWORD: ${{ secrets.AIRFLOW_WEBSERVER_PASSWORD }}
# AIRFLOW_DBT_INIT_DAG_ID: ${{ secrets.AIRFLOW_DBT_INIT_DAG_ID }}
# shell: bash
# run: |
# curl "$AIRFLOW_WEBSERVER_ENDPOINT/api/v1/dags/$AIRFLOW_DBT_INIT_DAG_ID/dagRuns" --user "$AIRFLOW_WEBSERVER_ID:$AIRFLOW_WEBSERVER_PASSWORD" -H 'Content-Type: application/json' -d '{}'
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 베이스 이미지 선택
FROM python:3.9-slim-buster

# 작업 디렉토리 설정
WORKDIR /app

# 필요한 파일 복사
COPY silverwork_dbt/ /app/silverwork_dbt/

# 의존성 설치
RUN pip install dbt-snowflake pandas
14 changes: 14 additions & 0 deletions silverwork_dbt/macros/get_custom_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% macro generate_schema_name(custom_schema_name, node) -%}

{%- set default_schema = target.schema -%}
{%- if custom_schema_name is none -%}

{{ default_schema }}

{%- else -%}

{{ custom_schema_name | trim }}

{%- endif -%}

{%- endmacro %}