-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import executor migration to cloud run
- Loading branch information
Showing
9 changed files
with
229 additions
and
71 deletions.
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
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
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,30 @@ | ||
# Builds the docker image of import executor, pushes it to artificat registry, | ||
# and creates a cloud run job using this images. | ||
# | ||
# Run it using: | ||
# gcloud builds submit --region=us-west1 --config=cloudbuild.yaml --substitutions=_ARTIFACT_REGISTRY_REPO="dc-images",_IMAGE_NAME="dc-import",_REGION="us-west1",_JOB_NAME="dc-import" . | ||
|
||
steps: | ||
# Install dependencies | ||
- name: python | ||
entrypoint: pip | ||
args: ["install", "-r", "requirements.txt", "--user"] | ||
|
||
# Docker Build | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: ['build', '-t', | ||
'${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_ARTIFACT_REGISTRY_REPO}/${_IMAGE_NAME}:latest', '.'] | ||
|
||
# Docker push to Google Artifact Registry | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: ['push', '${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_ARTIFACT_REGISTRY_REPO}/${_IMAGE_NAME}:latest'] | ||
|
||
# Deploy to Cloud Run | ||
- name: google/cloud-sdk | ||
args: ['gcloud', 'run', 'jobs', 'deploy', '${_JOB_NAME}', | ||
'--image=${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_ARTIFACT_REGISTRY_REPO}/${_IMAGE_NAME}:latest', | ||
'--region', '${_REGION}'] | ||
|
||
# Store images in Google Artifact Registry | ||
images: | ||
- ${_REGION}-docker.pkg.dev/${PROJECT_ID}/${_ARTIFACT_REGISTRY_REPO}/${_IMAGE_NAME}:latest |
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,43 @@ | ||
from app import configs | ||
from app.executor import import_executor | ||
from app.service import file_uploader | ||
from app.service import github_api | ||
from app.service import email_notifier | ||
|
||
from absl import flags | ||
from absl import app | ||
import logging | ||
import json | ||
|
||
FLAGS = flags.FLAGS | ||
flags.DEFINE_string('import_name', '', 'Absoluate import name.') | ||
flags.DEFINE_string('import_config', '', 'Import executor configuration.') | ||
|
||
|
||
def scheduled_updates(absolute_import_name: str, import_config: str): | ||
logging.info(absolute_import_name) | ||
cfg = json.loads(import_config) | ||
config = configs.ExecutorConfig(**cfg) | ||
logging.info(config) | ||
executor = import_executor.ImportExecutor( | ||
uploader=file_uploader.GCSFileUploader( | ||
project_id=config.gcs_project_id, | ||
bucket_name=config.storage_prod_bucket_name), | ||
github=github_api.GitHubRepoAPI( | ||
repo_owner_username=config.github_repo_owner_username, | ||
repo_name=config.github_repo_name, | ||
auth_username=config.github_auth_username, | ||
auth_access_token=config.github_auth_access_token), | ||
config=config, | ||
notifier=email_notifier.EmailNotifier(config.email_account, | ||
config.email_token)) | ||
result = executor.execute_imports_on_update(absolute_import_name) | ||
logging.info(result) | ||
|
||
|
||
def main(_): | ||
scheduled_updates(FLAGS.import_name, FLAGS.import_config) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(main) |
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
Oops, something went wrong.