Skip to content

Commit

Permalink
Add missing functionality to deploy-production.sh (web-platform-tests…
Browse files Browse the repository at this point in the history
…#3544)

* Add a command-line flag to stop a running daemon

* Add the remaining steps for deployment to production

* Enforce numeric comparison

Co-authored-by: James C Scott III <[email protected]>

* Enforce numeric equality

Co-authored-by: James C Scott III <[email protected]>

---------

Co-authored-by: James C Scott III <[email protected]>
  • Loading branch information
past and jcscottiii authored Oct 23, 2023
1 parent cfa1075 commit 3cdefdd
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 19 deletions.
66 changes: 64 additions & 2 deletions util/deploy-production.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Helper script for deploying to production.
# Needs the following packages to be installed: google-cloud-cli, gh, jq

#set -x #echo on for debugging purposes
set -e

usage() {
Expand All @@ -11,6 +12,17 @@ usage() {
echo "${USAGE}"
}

# Deletes the service passed as a parameter.
delete_oldest_version() {
OLDEST_REV=$(gcloud app --project=wptdashboard versions list --sort-by=last_deployed_time --filter="service=$1" --limit=1 --format=json | jq -r '.[] | .id')
echo "Deleting $1 service version $OLDEST_REV"
if confirm "Delete $1 service version $OLDEST_REV?"; then
gcloud app versions delete --service=$SERVICE $OLDEST_REV
else
echo "Skipping $1 service version $OLDEST_REV"
fi
}

while getopts ':fh' flag; do
case "${flag}" in
f) FORCE_DEPLOY='true' ;;
Expand All @@ -20,6 +32,9 @@ done

GH_OWNER="web-platform-tests"
GH_REPO="wpt.fyi"
UTIL_DIR=$(dirname $0)
source "${UTIL_DIR}/logging.sh"
source "${UTIL_DIR}/commands.sh"

# Find changes to deploy.
LAST_DEPLOYED_SHA=$(gcloud app --project=wptdashboard versions list --hide-no-traffic --filter='service=default' --format=yaml | grep id | head -1 | cut -d' ' -f2 | sed 's/rev-//')
Expand Down Expand Up @@ -73,5 +88,52 @@ then
exit 2
fi

# TODO(past): automate the remaining steps
echo "Until the process if fully automated, continue with the manual deployment process starting at step 4."
# Confirm there are 3 versions for each service and delete the oldest version.
SERVICES="default processor searchcache"
for SERVICE in $SERVICES
do
VERSIONS=$(gcloud app --project=wptdashboard versions list --filter="service=$SERVICE" --format=list | wc -l)
if [[ "${VERSIONS}" -eq "3" ]];
then
echo "Found 3 versions for service $SERVICE, will delete the oldest"
delete_oldest_version $SERVICE
elif [[ "${VERSIONS}" -lt "3" ]];
then
echo -e "\n$VERSIONS versions found for service $SERVICE"
else
echo -e "\n$VERSIONS versions found for service $SERVICE!"
exit 3
fi
done

# Start a docker instance.
${UTIL_DIR}/docker-dev/run.sh -d
# Login to gcloud if not already logged in.
wptd_exec_it gcloud auth login
# Deploy the services.
wptd_exec_it make deploy_production PROJECT=wptdashboard APP_PATH=webapp/web
wptd_exec_it make deploy_production PROJECT=wptdashboard APP_PATH=results-processor
wptd_exec_it make deploy_production PROJECT=wptdashboard APP_PATH=api/query/cache/service
cd webapp/web
gcloud app deploy --project=wptdashboard index.yaml queue.yaml dispatch.yaml
cd ../..

# Stop docker.
${UTIL_DIR}/docker-dev/run.sh -s

# Confirm that everything works as expected and redirect traffic.
VERSION_URL=$(gcloud app --project=wptdashboard versions list --sort-by=~last_deployed_time --filter='service=default' --limit=1 --format=json | jq -r '.[] | .version.versionUrl')
LATEST_VERSION=$(gcloud app --project=wptdashboard versions list --sort-by=~last_deployed_time --filter='service=default' --limit=1 --format=json | jq -r '.[] | .id')
MESSAGE="Visit $VERSION_URL to confirm that everything works (page load, search, test expansion, show history). Redirect traffic now?"
if confirm "$MESSAGE"; then
for SERVICE in $SERVICES
do
gcloud app services set-traffic $SERVICE --splits $LATEST_VERSION=1
done
else
echo "Don't forget to migrate traffic to the new version."
fi

# Update and close deployment bug.
LAST_DEPLOYMENT_ISSUE=$(gh issue list --state open --label "$PROD_LABEL" --label "$RELEASE_LABEL" --limit 1 --json number --jq '.[] | .number')
gh issue close "$LAST_DEPLOYMENT_ISSUE" -c "Deployment is now complete."
37 changes: 20 additions & 17 deletions util/docker-dev/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,27 @@ source "${DOCKER_DIR}/../commands.sh"
source "${DOCKER_DIR}/../logging.sh"

function usage() {
USAGE="USAGE: $(basename ${0}) [-q] [-a] [-d]
USAGE="USAGE: $(basename ${0}) [-q] [-d] [-s]
-d daemon mode: Run in the background rather than blocking then cleaning up
-q quiet mode: Assume default for all prompts"
-q quiet mode: Assume default for all prompts
-s stop daemon: Stop a running daemon"
>&2 echo "${USAGE}"
}

function stop() {
info "Stopping ${DOCKER_INSTANCE}..."
wptd_stop
info ""${DOCKER_INSTANCE}" stopped."
if [[ "${PR}" == "" ]]; then
confirm_preserve_remove "Docker instance ${DOCKER_INSTANCE} still exists"
fi
if [[ "${PR}" == "r" ]]; then
info "Removing ${DOCKER_INSTANCE}..."
wptd_rm
info "${DOCKER_INSTANCE} removed."
fi
}

PR=""
function confirm_preserve_remove() {
if confirm "${1}. Remove?"; then
Expand All @@ -25,10 +40,12 @@ function confirm_preserve_remove() {

DAEMON="false"
QUIET="false"
while getopts ':dhaq' FLAG; do
while getopts ':dhqs' FLAG; do
case "${FLAG}" in
d)
DAEMON="true" ;;
s)
stop && exit 0 ;;
q)
QUIET="true"
PR="r" ;;
Expand All @@ -42,20 +59,6 @@ INSPECT_STATUS="${?}"
docker inspect "${DOCKER_INSTANCE}" | grep '"Running": true' | read
RUNNING_STATUS="${?}"

function stop() {
info "Stopping ${DOCKER_INSTANCE}..."
wptd_stop
info ""${DOCKER_INSTANCE}" stopped."
if [[ "${PR}" == "" ]]; then
confirm_preserve_remove "Docker instance ${DOCKER_INSTANCE} still exists"
fi
if [[ "${PR}" == "r" ]]; then
info "Removing ${DOCKER_INSTANCE}..."
wptd_rm
info "${DOCKER_INSTANCE} removed."
fi
}

function quit() {
warn "run.sh: Recieved interrupt. Exiting..."
stop
Expand Down

0 comments on commit 3cdefdd

Please sign in to comment.