-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
register blocks using seperate python files
- Loading branch information
Showing
6 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Programmatically create GCP Bigquery Block for Prefect""" | ||
|
||
from prefect_gcp import BigQueryWarehouse, GcpCredentials | ||
|
||
from src.utils import load_env_variables | ||
|
||
env_variables = load_env_variables() | ||
|
||
ENV = env_variables["ENV"] # dev, test or prod | ||
PREFECT_BLOCK_NAME_GCP_CREDENTIALS = f"{env_variables['GCP_PROJECT_ID']}-{env_variables['GCP_DEPLOYMENT_SERVICE_ACCOUNT']}" | ||
GOOGLE_BIGQUERY_BLOCK_NAME = f"{env_variables['GCP_PROJECT_ID']}-bigquery-{ENV}" | ||
|
||
bigquery_block = BigQueryWarehouse( | ||
gcp_credentials=GcpCredentials.load(PREFECT_BLOCK_NAME_GCP_CREDENTIALS) | ||
).save(name=GOOGLE_BIGQUERY_BLOCK_NAME, overwrite=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"""Programmatically create GCP Credential Block for Prefect""" | ||
|
||
from prefect_gcp import GcpCredentials | ||
|
||
from src.utils import load_env_variables | ||
|
||
env_variables = load_env_variables() | ||
|
||
PREFECT_BLOCK_NAME_GCP_CREDENTIALS_BLOCK_NAME = f"{env_variables['GCP_PROJECT_ID']}-{env_variables['GCP_DEPLOYMENT_SERVICE_ACCOUNT']}" | ||
|
||
with open(f".secrets/deployment_sa_account.json", "r") as f: | ||
service_account = f.read() | ||
|
||
gcp_credentials_block = GcpCredentials(service_account_info=service_account).save( | ||
name=PREFECT_BLOCK_NAME_GCP_CREDENTIALS_BLOCK_NAME, overwrite=True | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Programmatically create Github Block for Prefect""" | ||
|
||
from prefect.filesystems import GitHub | ||
from src.utils import load_env_variables | ||
|
||
env_vars = load_env_variables() | ||
ENV = env_vars["ENV"] # dev, test or prod | ||
|
||
branches_mapping = {"dev": "develop", "test": "test", "prod": "master"} | ||
GITHUB_BLOCK_NAME = f"{env_vars['GCP_PROJECT_ID']}-github-{ENV}" | ||
|
||
github_block = GitHub( | ||
repository=f"{env_vars['GITHUB_REPO']}", reference=branches_mapping[ENV] | ||
).save(name=GITHUB_BLOCK_NAME, overwrite=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Programmatically create Google Cloud Run Block for Prefect""" | ||
|
||
from prefect_gcp import CloudRunJob, GcpCredentials | ||
|
||
from src.utils import load_env_variables | ||
|
||
env_vars = load_env_variables() | ||
ENV = env_vars["ENV"] # dev, test or prod | ||
|
||
GCP_CREDENTIALS_PREFECT_BLOCK_NAME = ( | ||
f"{env_vars['GCP_PROJECT_ID']}-{env_vars['GCP_DEPLOYMENT_SERVICE_ACCOUNT']}" | ||
) | ||
GOOGLE_CLOUD_RUN_BLOCK_NAME = f"{env_vars['GCP_PROJECT_ID']}-google-cloud-run-{ENV}" | ||
|
||
gcp_credentials = GcpCredentials.load(GCP_CREDENTIALS_PREFECT_BLOCK_NAME) | ||
project_id = gcp_credentials.project | ||
registry_adress = ( | ||
f"{env_vars['GCP_DEFAULT_REGION']}-docker.pkg.dev/{project_id}/prefect-{ENV}" | ||
) | ||
|
||
cloud_run_job_block = CloudRunJob( | ||
credentials=gcp_credentials, | ||
project_id=project_id, | ||
image=f"{registry_adress}/prefect:{env_vars['PREFECT_VERSION']}-python{env_vars['PYTHON_VERSION']}", | ||
region=env_vars["GCP_DEFAULT_REGION"], | ||
).save(name=GOOGLE_CLOUD_RUN_BLOCK_NAME, overwrite=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Programmatically create Unsplash Access Key Secret Block for Prefect""" | ||
|
||
from prefect.blocks.system import Secret | ||
from src.utils import load_env_variables | ||
|
||
env_vars = load_env_variables() | ||
|
||
UNSPLASH_ACCESS_KEY_BLOCK_NAME = f"{env_vars['GCP_PROJECT_ID']}-unsplash-access-key" | ||
|
||
unsplash_access_key_block = Secret(value=env_vars["UNSPLASH_ACCESS_KEY"]).save( | ||
name=UNSPLASH_ACCESS_KEY_BLOCK_NAME, overwrite=True | ||
) |