Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2022-10-20 03:16:33 +0300
committerMarcel Amirault <mamirault@gitlab.com>2022-10-20 03:16:33 +0300
commit379fd2d87f957d9a7a097d82b8d9ad51a138438e (patch)
treee8bb05c6cc0ebd8fd3bb32b954a56c2383f6223a /scripts
parent62cb99259c160163ae75011189546c8647ec633b (diff)
Review apps 2.0
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/deploy-review-app68
-rwxr-xr-xscripts/review-replace-urls4
2 files changed, 72 insertions, 0 deletions
diff --git a/scripts/deploy-review-app b/scripts/deploy-review-app
new file mode 100755
index 00000000..c6c09c85
--- /dev/null
+++ b/scripts/deploy-review-app
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+
+#
+# Copied and adapted from https://gitlab.com/gitlab-com/www-gitlab-com/-/blob/10b95368133ea0a23326d293b7a80fc71317d011/scripts/deploy
+#
+
+# Exponential backoff, found from StackOverflow at https://stackoverflow.com/questions/8350942/how-to-re-run-the-curl-command-automatically-when-the-error-occurs/8351489#8351489
+# Retries a command a with backoff.
+#
+# The retry count is given by ATTEMPTS (default 5), the
+# initial backoff timeout is given by TIMEOUT in seconds
+# (default 1.)
+#
+# Successive backoffs double the timeout.
+#
+# Beware of set -e killing your whole script!
+function with_backoff {
+ local max_attempts=${ATTEMPTS-5}
+ local timeout=${TIMEOUT-1}
+ local attempt=0
+ local exitCode=0
+
+ while [[ $attempt < $max_attempts ]]
+ do
+ "$@"
+ exitCode=$?
+
+ if [[ $exitCode == 0 ]]
+ then
+ break
+ fi
+
+ echo "Failure! Retrying in $timeout.." 1>&2
+ sleep $timeout
+ attempt=$(( attempt + 1 ))
+ timeout=$(( timeout * 2 ))
+ done
+
+ if [[ $exitCode != 0 ]]
+ then
+ echo "You've failed me for the last time! ($@)" 1>&2
+ fi
+
+ return $exitCode
+}
+
+echo "Starting deploy for review app."
+
+gcp_project=$GCP_PROJECT_REVIEW_APPS
+gcp_bucket=$GCP_BUCKET_REVIEW_APPS
+gcp_service_account_key=$GCP_SERVICE_ACCOUNT_KEY_REVIEW_APPS
+cache_control_max_age='60'
+src='public/'
+dest="gs://$gcp_bucket/$CI_COMMIT_REF_SLUG"
+
+echo "$gcp_service_account_key" > key.json
+gcloud auth activate-service-account --key-file key.json
+gcloud config set project "$gcp_project"
+
+if [ "$DEPLOY_DELETE_APP" = 'true' ]; then
+ echo "Deleting review app from ${dest}..."
+ echo "gsutil -m rm -r \"$dest\""
+ gsutil -m rm -r "$dest"
+else
+ echo "Deploying review app to ${dest}..."
+ echo "gsutil -h \"Cache-Control:public, max-age=$cache_control_max_age\" -m cp -z css,html,js,txt -c -r \"$src\" \"$dest\""
+ with_backoff gsutil -h "Cache-Control:public, max-age=$cache_control_max_age" -m cp -z css,html,js,txt -c -r "$src" "$dest"
+fi
diff --git a/scripts/review-replace-urls b/scripts/review-replace-urls
new file mode 100755
index 00000000..f78e8324
--- /dev/null
+++ b/scripts/review-replace-urls
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+# Note this uses linux-specific (GNU) find syntax, it does not work with MacOS (BSD) find syntax because of the usage of the 'regextype' flag (and possibly other reasons)
+find public/ -type f -regextype egrep -iregex ".*\.(html|js|css|json|xml|txt)" -exec sed --in-place "s#https\?://docs.gitlab.com#https://$CI_COMMIT_REF_SLUG.docs.gitlab-review.app#g" "{}" +;