-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cloudbuild deployment script (#7)
* Remove cap drop * Add cloudbuild.yml and deploy.sh * Rename cloudbuild.yml * Add --zone flag * Add probability flag, move some parameters to env vars * Add \n * Address PR comments * Only remove keys that were created >10m ago
- Loading branch information
1 parent
7e9a831
commit 22d7bc6
Showing
3 changed files
with
82 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
steps: | ||
# Run the deployment script. NOTE: the IATA depends on the region where the | ||
# VM is deployed. Our testing VM is always in us-central1, which is CBF. | ||
- name: gcr.io/$PROJECT_ID/gcloud-jsonnet-cbif | ||
dir: '/workspace/' | ||
args: [ | ||
'/workspace/deploy.sh $PROJECT_ID mlab ${_API_KEY}' | ||
] |
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,69 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
USAGE="$0 <project> <organization> <iata> <api-key>" | ||
PROJECT=${1:?Please provide the GCP project (e.g., mlab-sandbox): ${USAGE}} | ||
ORG=${2:?Please provide the organization (e.g., mlab): ${USAGE}} | ||
API_KEY=${3:?Please provide the API key: ${USAGE}} | ||
|
||
IATA="cbf" | ||
VM_ZONE="us-central1-a" | ||
VM_NAME="autonode" | ||
DOCKER_COMPOSE_FILE_PATH="examples/ndt-fullstack.yml" | ||
LOCATE_URL="locate-dot-${PROJECT}.appspot.com" | ||
PROBABILITY="1.0" | ||
INTERFACE_NAME="ens4" | ||
INTERFACE_MAXRATE="150000000" | ||
SA_ACCOUNT="autonode@${PROJECT}.iam.gserviceaccount.com" | ||
|
||
# NOTE: We don't use the VM's default credentials because we want to simulate | ||
# how a non-GCP user would set up an autonode. Instead, we generate a temporary | ||
# key for the autonode service account that will only exist until the next | ||
# deployment. | ||
|
||
# Delete any existing keys for the autonode SA. Ignore failures due to | ||
# system-managed keys that cannot be deleted. | ||
for key in $(gcloud iam service-accounts keys list \ | ||
--iam-account=${SA_ACCOUNT} \ | ||
--created-before=$(date --iso-8601=seconds -d "10 mins ago") | \ | ||
cut -f1 -d " " | tail -n +2) | ||
do | ||
gcloud iam service-accounts keys delete --iam-account=${SA_ACCOUNT} ${key} -q || true | ||
done | ||
|
||
# Create a new key. | ||
gcloud iam service-accounts keys create key.json \ | ||
--iam-account=${SA_ACCOUNT} | ||
SA_KEY=$(<key.json) | ||
|
||
# Copy the docker compose file to the VM. | ||
gcloud --project ${PROJECT} compute scp --zone ${VM_ZONE} ${DOCKER_COMPOSE_FILE_PATH} ${VM_NAME}:~/docker-compose.yml --tunnel-through-iap | ||
|
||
# Setup script. This stops docker compose, creates the required folders, writes | ||
# the SA key, re-creates the .env file and restarts docker compose. | ||
gcloud --project ${PROJECT} compute ssh --zone ${VM_ZONE} ${VM_NAME} --tunnel-through-iap <<EOF | ||
set -euxo pipefail | ||
# Create volume folders if not present. | ||
mkdir -p autocert autonode certs html schemas resultsdir | ||
# Stop the docker compose if it's running. | ||
docker compose -f docker-compose.yml down | ||
# Create .env file | ||
rm .env || true | ||
echo "API_KEY=${API_KEY}" >> .env | ||
echo "ORGANIZATION=${ORG}" >> .env | ||
echo "PROJECT=${PROJECT}" >> .env | ||
echo "IATA=${IATA}" >> .env | ||
echo "LOCATE_URL=${LOCATE_URL}" >> .env | ||
echo "PROBABILITY=${PROBABILITY}" >> .env | ||
echo "INTERFACE_NAME=${INTERFACE_NAME}" >> .env | ||
echo "INTERFACE_MAXRATE=${INTERFACE_MAXRATE}" >> .env | ||
# Write service account key to the expected file. | ||
echo "${SA_KEY}" > certs/service-account-autojoin.json | ||
# Start the docker compose again. | ||
docker compose -f docker-compose.yml up -d | ||
EOF | ||
|
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