Skip to content

Commit

Permalink
API URL correctly passed into Front-end code prior to deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebharris committed Jul 2, 2022
1 parent 88a5ba9 commit c3c54d8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@ def terraform(context, account_number="", contact="", distribution_bucket="terra
local(command)

if mode == 'apply' and frontend == 'yes':
with do_in_directory('terraform'):
result = local('terraform output')
search = re.search("(https.*)", result.stdout)
api_url = search.group(0)[:len(search.group(0))-1]
build_and_deploy_frontend()

with do_in_directory('frontend'):
build_frontend(api_url)

deploy_frontend()
def build_and_deploy_frontend():
api_url = get_api_url()
with do_in_directory('frontend'):
build_frontend(api_url)
deploy_frontend()


def get_api_url():
with do_in_directory('terraform'):
result = local('terraform output')
search = re.search("(https.*)", result.stdout)
api_url = search.group(0)[:len(search.group(0)) - 1]
return api_url


def build_lambdas():
Expand All @@ -85,7 +92,8 @@ def remove_local_terraform_state_files_to_prevent_deploying_in_wrong_environment

def build_frontend(api_url: str):
print("Building frontend using API url {api_url}...".format(api_url=api_url))
local('API_GATEWAY_URL={api_url} npm run build'.format(api_url=api_url))
local('echo API_GATEWAY_URL={api_url}>.env'.format(api_url=api_url))
local('npm run build')


def deploy_frontend():
Expand Down
1 change: 0 additions & 1 deletion frontend/.env

This file was deleted.

1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/public/build/

.DS_Store
.env

0 comments on commit c3c54d8

Please sign in to comment.