-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute_dbt.py
32 lines (27 loc) · 1.6 KB
/
execute_dbt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import subprocess
import os
import json
import sys
# Follow these instructions to successfully set up this Blueprint:
instructions = """
1) Add the contents of this file to the root directory of the Github repository where your dbt models live, with the file name of "execute_dbt.py".
2) Move your profiles.yml file to the root directory of the Github repository where your dbt models live.
3) Connect Shipyard to the Github repository where your dbt models live.
4) Connect this Blueprint to the Github repository and branch/tag where your dbt models live.
5) If you used the default setting of cloning your Github repository to a folder with the repo's name, update the "File to Run" field to include the name of your repo as a folder. e.g. "your_repo_name/execute_dbt.py" If you opted to clone into the current working directory, do nothing.
6) Click "Use this Blueprint" to get started.
"""
bigquery_credentials = os.environ.get('BIGQUERY_CREDS')
directory_of_file = os.path.dirname(os.path.realpath(__file__))
dbt_command = os.environ.get('DBT_COMMAND', 'dbt run')
if os.path.realpath(__file__) == '/home/shipyard/execute_dbt.py':
print('This dbt Blueprint is not set up properly. Edit this Blueprint and follow the instructions below:')
print(instructions)
sys.exit(1)
else:
os.chdir(directory_of_file)
if not bigquery_credentials or not bigquery_credentials == 'None':
bigquery_credentials = json.loads(bigquery_credentials)
with open('bigquery_creds.json', 'w') as outfile:
json.dump(bigquery_credentials, outfile)
subprocess.run(['sh', '-c', dbt_command], check=True)