deploying with project id as env var for functions
This commit is contained in:
parent
6a17775f07
commit
d54b8317c9
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
@ -211,22 +211,22 @@ jobs:
|
|||||||
|
|
||||||
# DEPLOY update_tag function
|
# DEPLOY update_tag function
|
||||||
- name: Deploy update_tag Function
|
- name: Deploy update_tag Function
|
||||||
run: python admin.py tag
|
run: python admin.py tag ${{ vars.GCP_PROJECT }}
|
||||||
|
|
||||||
# DEPLOY run_user_playlist function
|
# DEPLOY run_user_playlist function
|
||||||
- name: Deploy run_user_playlist Function
|
- name: Deploy run_user_playlist Function
|
||||||
run: python admin.py playlist
|
run: python admin.py playlist ${{ vars.GCP_PROJECT }}
|
||||||
|
|
||||||
### CRON FUNCTIONS
|
### CRON FUNCTIONS
|
||||||
|
|
||||||
# DEPLOY run_all_playlists function
|
# DEPLOY run_all_playlists function
|
||||||
- name: Deploy run_all_playlists Function
|
- name: Deploy run_all_playlists Function
|
||||||
run: python admin.py playlist_cron
|
run: python admin.py playlist_cron ${{ vars.GCP_PROJECT }}
|
||||||
|
|
||||||
# DEPLOY run_all_playlist_stats function
|
# DEPLOY run_all_playlist_stats function
|
||||||
- name: Deploy run_all_playlist_stats Function
|
- name: Deploy run_all_playlist_stats Function
|
||||||
run: python admin.py playlist_stats_cron
|
run: python admin.py playlist_stats_cron ${{ vars.GCP_PROJECT }}
|
||||||
|
|
||||||
# DEPLOY run_all_tags function
|
# DEPLOY run_all_tags function
|
||||||
- name: Deploy run_all_tags Function
|
- name: Deploy run_all_tags Function
|
||||||
run: python admin.py tags_cron
|
run: python admin.py tags_cron ${{ vars.GCP_PROJECT }}
|
||||||
|
23
admin.py
23
admin.py
@ -83,7 +83,7 @@ class Admin(Cmd):
|
|||||||
def do_project(self, args):
|
def do_project(self, args):
|
||||||
print(f"\"{self.gcloud_project}\"")
|
print(f"\"{self.gcloud_project}\"")
|
||||||
|
|
||||||
def deploy_function(self, name, timeout: int = 60, region='europe-west2'):
|
def deploy_function(self, name, project_id, timeout: int = 60, region='europe-west2'):
|
||||||
"""
|
"""
|
||||||
Deploy function with required environment variables
|
Deploy function with required environment variables
|
||||||
"""
|
"""
|
||||||
@ -93,7 +93,7 @@ class Admin(Cmd):
|
|||||||
f'--gen2 '
|
f'--gen2 '
|
||||||
'--runtime=python311 '
|
'--runtime=python311 '
|
||||||
f'--trigger-topic {name} '
|
f'--trigger-topic {name} '
|
||||||
'--set-env-vars DEPLOY_DESTINATION=PROD '
|
f'--set-env-vars DEPLOY_DESTINATION=PROD,GOOGLE_CLOUD_PROJECT={project_id} '
|
||||||
f'--service-account {name.replace("_", "-")}-func@{self.gcloud_project}.iam.gserviceaccount.com '
|
f'--service-account {name.replace("_", "-")}-func@{self.gcloud_project}.iam.gserviceaccount.com '
|
||||||
f'--timeout={timeout}s', shell=True
|
f'--timeout={timeout}s', shell=True
|
||||||
)
|
)
|
||||||
@ -153,29 +153,34 @@ class Admin(Cmd):
|
|||||||
print('>> deploying app engine service')
|
print('>> deploying app engine service')
|
||||||
subprocess.check_call('gcloud app deploy', shell=True)
|
subprocess.check_call('gcloud app deploy', shell=True)
|
||||||
|
|
||||||
def function_deploy(self, main, function_id):
|
def function_deploy(self, main, function_id, project_id):
|
||||||
"""Deploy Cloud Function, copy main file and initiate gcloud command
|
"""Deploy Cloud Function, copy main file and initiate gcloud command
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
main (str): main path
|
main (str): main path
|
||||||
function_id (str): function id to deploy to
|
function_id (str): function id to deploy to
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if len(project_id) == 0:
|
||||||
|
print("no project id provided")
|
||||||
|
exit()
|
||||||
|
|
||||||
self.copy_main_file(main)
|
self.copy_main_file(main)
|
||||||
|
|
||||||
print(f'>> deploying {function_id}')
|
print(f'>> deploying {function_id}')
|
||||||
self.deploy_function(function_id)
|
self.deploy_function(function_id, project_id)
|
||||||
|
|
||||||
def do_tag(self, args):
|
def do_tag(self, args):
|
||||||
"""
|
"""
|
||||||
Deploy update_tag function
|
Deploy update_tag function
|
||||||
"""
|
"""
|
||||||
self.function_deploy('update_tag', 'update_tag')
|
self.function_deploy('update_tag', 'update_tag', args.strip())
|
||||||
|
|
||||||
def do_playlist(self, args):
|
def do_playlist(self, args):
|
||||||
"""
|
"""
|
||||||
Deploy run_user_playlist function
|
Deploy run_user_playlist function
|
||||||
"""
|
"""
|
||||||
self.function_deploy('run_playlist', 'run_user_playlist')
|
self.function_deploy('run_playlist', 'run_user_playlist', args.strip())
|
||||||
|
|
||||||
|
|
||||||
# all playlists cron job
|
# all playlists cron job
|
||||||
@ -183,21 +188,21 @@ class Admin(Cmd):
|
|||||||
"""
|
"""
|
||||||
Deploy run_all_playlists function
|
Deploy run_all_playlists function
|
||||||
"""
|
"""
|
||||||
self.function_deploy('cron', 'run_all_playlists')
|
self.function_deploy('cron', 'run_all_playlists', args.strip())
|
||||||
|
|
||||||
# all stats refresh cron job
|
# all stats refresh cron job
|
||||||
def do_playlist_stats_cron(self, args):
|
def do_playlist_stats_cron(self, args):
|
||||||
"""
|
"""
|
||||||
Deploy run_all_playlist_stats function
|
Deploy run_all_playlist_stats function
|
||||||
"""
|
"""
|
||||||
self.function_deploy('cron', 'run_all_playlist_stats')
|
self.function_deploy('cron', 'run_all_playlist_stats', args.strip())
|
||||||
|
|
||||||
# all tags cron job
|
# all tags cron job
|
||||||
def do_tags_cron(self, args):
|
def do_tags_cron(self, args):
|
||||||
"""
|
"""
|
||||||
Deploy run_all_tags function
|
Deploy run_all_tags function
|
||||||
"""
|
"""
|
||||||
self.function_deploy('cron', 'run_all_tags')
|
self.function_deploy('cron', 'run_all_tags', args.strip())
|
||||||
|
|
||||||
# redeploy all cron job functions
|
# redeploy all cron job functions
|
||||||
def do_cron_functions(self, args):
|
def do_cron_functions(self, args):
|
||||||
|
Loading…
Reference in New Issue
Block a user