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:
authorMarcel Amirault <mamirault@gitlab.com>2022-10-20 13:54:42 +0300
committerAchilleas Pipinellis <axil@gitlab.com>2022-10-20 13:54:42 +0300
commitd0e1680c0d836616f94fd999dd09b9ec27323713 (patch)
tree47ae9a979cf4cd19ef7b950751d576c5a2edc056
parent170797ff300767509f858513d9a44b4183a01dac (diff)
Re-implement Review Apps 2.0 (with correct environments)
-rw-r--r--.gitlab/ci/build-and-deploy.gitlab-ci.yml63
-rw-r--r--content/assets/stylesheets/stylesheet.scss2
-rw-r--r--content/frontend/default/environment.js2
-rwxr-xr-xscripts/deploy-review-app68
-rwxr-xr-xscripts/review-replace-urls4
5 files changed, 92 insertions, 47 deletions
diff --git a/.gitlab/ci/build-and-deploy.gitlab-ci.yml b/.gitlab/ci/build-and-deploy.gitlab-ci.yml
index 327aa6f3..ed110722 100644
--- a/.gitlab/ci/build-and-deploy.gitlab-ci.yml
+++ b/.gitlab/ci/build-and-deploy.gitlab-ci.yml
@@ -34,6 +34,15 @@
- public
expire_in: 1d
+# Common setup for review apps
+.review-environment:
+ image: registry.gitlab.com/gitlab-org/gitlab-build-images:www-gitlab-com-debian-bullseye-ruby-3.0-node-16
+ environment:
+ name: review/$CI_COMMIT_REF_SLUG$REVIEW_SLUG
+ url: https://$CI_COMMIT_REF_SLUG$REVIEW_SLUG.docs.gitlab-review.app
+ on_stop: review_stop
+ auto_stop_in: 30 days
+
#
# Compile only on the default and stable branches
#
@@ -60,28 +69,20 @@ compile_dev:
###############################################
#
-# Deploy the Review App on a dev server
+# Deploy the Review App on a GCS bucket.
#
review:
stage: deploy
extends:
- .retry
- variables:
- GIT_STRATEGY: none
+ - .review-environment
needs:
- compile_dev
before_script: []
cache: {}
script:
- # Rsync to the Pages dir
- - rsync -av --delete public /srv/nginx/pages/$CI_COMMIT_REF_SLUG$REVIEW_SLUG
- # Remove public directory so that the next review app can run in a
- # clean environment (limitation of the shell executor).
- - rm -rf public
- environment:
- name: review/$CI_COMMIT_REF_SLUG$REVIEW_SLUG
- url: http://$CI_COMMIT_REF_SLUG$REVIEW_SLUG.$APPS_DOMAIN
- on_stop: review_stop
+ - scripts/review-replace-urls
+ - scripts/deploy-review-app
rules:
- if: '$CI_PROJECT_PATH == "gitlab-renovate-forks/gitlab-docs"'
when: manual
@@ -90,9 +91,6 @@ review:
- if: '$CI_MERGE_REQUEST_ID'
- if: '$CI_PIPELINE_SOURCE == "pipeline" || $CI_PIPELINE_SOURCE == "trigger"'
- if: '$CI_COMMIT_BRANCH =~ /docs-preview/' # TODO: Remove once no projects create such branch
- tags:
- - nginx
- - review-apps
#
# Stop the Review App
@@ -101,17 +99,17 @@ review_stop:
stage: deploy
extends:
- .retry
+ - .review-environment
variables:
- GIT_STRATEGY: none
+ DEPLOY_DELETE_APP: 'true'
+ environment:
+ action: stop
needs: []
artifacts: {}
before_script: []
cache: {}
script:
- - rm -rf public /srv/nginx/pages/$CI_COMMIT_REF_SLUG$REVIEW_SLUG
- environment:
- name: review/$CI_COMMIT_REF_SLUG$REVIEW_SLUG
- action: stop
+ - scripts/deploy-review-app
rules:
- if: '$CI_PROJECT_PATH == "gitlab-renovate-forks/gitlab-docs"'
allow_failure: true
@@ -125,31 +123,6 @@ review_stop:
- if: '$CI_COMMIT_BRANCH =~ /docs-preview/'
allow_failure: true
when: manual
- tags:
- - nginx
- - review-apps
-
-#
-# Clean up review apps and free disk space
-#
-clean-pages:
- stage: deploy
- variables:
- GIT_STRATEGY: none
- needs: []
- artifacts: {}
- before_script: []
- cache: {}
- script:
- - /home/gitlab-runner/clean-pages ${CLEAN_REVIEW_APPS_DAYS}
- - df -h
- rules:
- - if: '$CI_PIPELINE_SOURCE == "schedule" && $CLEAN_REVIEW_APPS_DAYS'
- when: manual
- allow_failure: true
- tags:
- - nginx
- - review-apps
#
# Clean up stopped review app environments. Done once a month in a scheduled pipeline,
diff --git a/content/assets/stylesheets/stylesheet.scss b/content/assets/stylesheets/stylesheet.scss
index f3ea836f..d6fa587f 100644
--- a/content/assets/stylesheets/stylesheet.scss
+++ b/content/assets/stylesheets/stylesheet.scss
@@ -509,7 +509,7 @@ h6[id]::before {
// external link and footer social links
[href^='http://'],
[href^='https://'] {
- &:not([href*='gitlab.com']):not([href*='nip.io']):not(.gitlab-social):not(.no-attachment-icon) {
+ &:not([href*='gitlab.com']):not([href*='docs.gitlab-review.app']):not(.gitlab-social):not(.no-attachment-icon) {
&::after {
content: '\f08e';
font-family: FontAwesome, sans-serif;
diff --git a/content/frontend/default/environment.js b/content/frontend/default/environment.js
index 05e8ced5..2ee35219 100644
--- a/content/frontend/default/environment.js
+++ b/content/frontend/default/environment.js
@@ -9,7 +9,7 @@ export const GlHosts = [
},
{
environment: 'review',
- host: '35.193.151.162.nip.io',
+ host: 'docs.gitlab-review.app',
},
{
environment: 'local',
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" "{}" +;