-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split out metadata locations and allow dev and prod deploys
- Loading branch information
Showing
12 changed files
with
169 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,28 +16,47 @@ | |
|
||
# to run | ||
# | ||
# ./deploy prod | ||
# ./deploy.sh deploy prod | ||
# to deploy to production | ||
# | ||
# ./deploy delete | ||
# ./deploy.sh delete prod | ||
# to delete the prod instance (usually because you have changed | ||
# some instance boot value and want to recreate it from scratch) | ||
|
||
# exit on error | ||
set -e | ||
|
||
action=$1 | ||
env=$2 | ||
|
||
# CHANGE THESE VALUES TO MATCH YOUR PROJECT | ||
# String id of a google cloud project | ||
project="firehook-censoredplanet" | ||
dev_project="firehook-censoredplanet" | ||
# Int id of a cloud service account with the correct access permissions | ||
service_account_id="654632410498" | ||
dev_service_account_id="654632410498" | ||
|
||
# String id of a google cloud project | ||
prod_project="censoredplanet-analysisv1" | ||
# Int id of a cloud service account with the correct access permissions | ||
prod_service_account_id="669508427087" | ||
|
||
# GCP zone to deploy to | ||
zone="us-east1-b" | ||
|
||
if [[ "${env}" == "dev" ]]; then | ||
project="${dev_project}" | ||
service_account_id="${dev_service_account_id}" | ||
env_file="dev.env" | ||
elif [[ "${env}" == "prod" ]]; then | ||
project="${prod_project}" | ||
service_account_id="${prod_service_account_id}" | ||
env_file="prod.env" | ||
else | ||
echo "Unknown env ${env}" | ||
exit 1 | ||
fi | ||
|
||
if [[ "${action}" == "backfill" ]]; then | ||
docker build --tag ${project} . | ||
docker build . --tag ${project} | ||
|
||
# Get service credentials if they are missing | ||
if [[ ! -f ~/.config/gcloud/${service_account_id}_compute_credentials.json ]]; then | ||
|
@@ -47,15 +66,16 @@ if [[ "${action}" == "backfill" ]]; then | |
fi | ||
|
||
# --entrypoint 'python3 -m pipeline.run_beam_tables --env=dev --full' | ||
docker run -it \ | ||
docker run -it --env-file "${env_file}" \ | ||
-v $HOME/.config/gcloud:$HOME/.config/gcloud \ | ||
-e GOOGLE_APPLICATION_CREDENTIALS=$HOME/.config/gcloud/${service_account_id}_compute_credentials.json \ | ||
${project} | ||
${project} | ||
|
||
elif [[ "${action}" == "dev" ]]; then | ||
elif [[ "${action}" == "deploy" ]]; then | ||
# For builders outside the VPC security perimeter the build will succeed | ||
# but throw a logging error, so we ignore errors here | ||
gcloud builds submit . --tag gcr.io/${project}/pipeline --project ${project} || true | ||
gcloud builds submit . \ | ||
--tag gcr.io/${project}/pipeline --project ${project} || true | ||
|
||
# Instead check that the latest build succeeded | ||
if gcloud builds list --limit=1 --project ${project} | grep SUCCESS; then | ||
|
@@ -70,14 +90,16 @@ elif [[ "${action}" == "dev" ]]; then | |
if gcloud compute instances list --project ${project} | grep -q ${project}; then | ||
# update | ||
gcloud compute instances update-container ${project} --zone ${zone} \ | ||
--container-image gcr.io/${project}/pipeline:latest --project ${project} | ||
--container-image gcr.io/${project}/pipeline:latest --project ${project} \ | ||
--container-env-file="${env_file}" | ||
else | ||
# otherwise create a new instance | ||
gcloud compute instances create-with-container ${project} \ | ||
--container-image gcr.io/${project}/pipeline:latest \ | ||
--machine-type e2-highmem-4 --zone ${zone} --boot-disk-size 50GB \ | ||
--service-account ${service_account_id}[email protected] \ | ||
--scopes=bigquery,cloud-platform,default --project ${project} | ||
--scopes=bigquery,cloud-platform,default --project ${project} \ | ||
--container-env-file="${env_file}" | ||
fi | ||
|
||
elif [[ "${action}" == "delete" ]]; then | ||
|
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 @@ | ||
PIPELINE_ENV=dev |
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
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 @@ | ||
PIPELINE_ENV=prod |
Oops, something went wrong.