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>2020-08-03 12:24:58 +0300
committerAchilleas Pipinellis <axil@gitlab.com>2021-03-19 11:55:00 +0300
commit1a6df8b0d0ca2cf0e4bad8f756c4df259271b630 (patch)
treec103a857e9ead247136af38336f7c7e2050e96b8
parent8dfa86cd7e025579d4767c7f78577a8264a81bc4 (diff)
Use a GCS bucket to deploy the review appsgcs-bucket-for-review-apps
Update the jobs for the review apps to use a deploy script (taken from https://gitlab.com/gitlab-com/www-gitlab-com/-/blob/master/scripts/deploy). The following env variables are used and set at the project settings: - GCP_BUCKET_REVIEW_APPS - GCP_PROJECT_REVIEW_APPS - GCP_SERVICE_ACCOUNT_KEY_REVIEW_APPS The jobs also use the https://hub.docker.com/r/google/cloud-sdk Docker image, which includes the necessary tools for Google Cloud.
-rw-r--r--.gitlab-ci.yml29
-rwxr-xr-xscripts/deploy49
-rwxr-xr-xscripts/review-replace-urls4
3 files changed, 69 insertions, 13 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 98c8d55f..769ff5c6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -360,28 +360,31 @@ test_unlinked_files:
###############################################
#
-# Deploy the Review App on a dev server
+# Deploy the Review App on a GCS bucket. Use the Google Cloud SDK image
+# https://hub.docker.com/r/google/cloud-sdk and run the script in scripts/deploy.
#
review:
+ image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
stage: deploy
extends:
- .retry
variables:
- GIT_STRATEGY: none
+ DEPLOY_TYPE: review
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
+ - apk add bash --update-cache
+ - ./scripts/deploy
+ # We sometimes have absolute URLs, this replaces them with correct ones for the review app
+ # Disable for now. Alpine's find is not compatible with the script.
+ #- ./scripts/review-replace-urls
environment:
name: review/$CI_COMMIT_REF_SLUG$REVIEW_SLUG
url: http://$CI_COMMIT_REF_SLUG$REVIEW_SLUG.$APPS_DOMAIN
on_stop: review_stop
+ auto_stop_in: 15 days
rules:
- if: '$CI_PROJECT_PATH != "gitlab-org/gitlab-docs"'
when: never
@@ -393,20 +396,23 @@ review:
- review-apps
#
-# Stop the Review App
+# Stop the Review App. Use the Google Cloud SDK image
+# https://hub.docker.com/r/google/cloud-sdk and run the script in scripts/deploy.
#
review_stop:
+ image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
stage: deploy
extends:
- .retry
variables:
- GIT_STRATEGY: none
+ DEPLOY_DELETE_APP: 'true'
needs: []
artifacts: {}
before_script: []
cache: {}
script:
- - rm -rf public /srv/nginx/pages/$CI_COMMIT_REF_SLUG$REVIEW_SLUG
+ - apk add bash --update-cache
+ - ./scripts/deploy
environment:
name: review/$CI_COMMIT_REF_SLUG$REVIEW_SLUG
action: stop
@@ -420,9 +426,6 @@ review_stop:
- if: '$CI_COMMIT_BRANCH =~ /docs-preview/'
allow_failure: true
when: manual
- tags:
- - nginx
- - review-apps
###############################################
# GitLab Pages (production) #
diff --git a/scripts/deploy b/scripts/deploy
new file mode 100755
index 00000000..bcf97406
--- /dev/null
+++ b/scripts/deploy
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+echo "Starting deploy for ${DEPLOY_TYPE} app."
+
+src='public/'
+
+if [ "$DEPLOY_TYPE" = 'review' ]; then
+ 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'
+ dest="gs://$gcp_bucket/$CI_COMMIT_REF_SLUG"
+elif [ "$DEPLOY_TYPE" = 'staging' ]; then
+ gcp_project=$GCP_PROJECT_STAGING
+ gcp_bucket=$GCP_BUCKET_STAGING
+ gcp_service_account_key=$GCP_SERVICE_ACCOUNT_KEY_STAGING
+ cache_control_max_age='600'
+ dest="gs://$gcp_bucket"
+elif [ "$DEPLOY_TYPE" = 'production' ]; then
+ gcp_project=$GCP_PROJECT_PRODUCTION
+ gcp_bucket=$GCP_BUCKET_PRODUCTION
+ gcp_service_account_key=$GCP_SERVICE_ACCOUNT_KEY_PRODUCTION
+ cache_control_max_age='600'
+ dest="gs://$gcp_bucket"
+else
+ echo "Invalid DEPLOY_TYPE: '$DEPLOY_TYPE'. Must be 'review', 'staging', or 'production'"
+ exit 1
+fi
+
+if [ "$DEPLOY_CLEANUP_OLD_DELETED_FILES" = 'true' ]; then
+ echo "'DEPLOY_CLEANUP_OLD_DELETED_FILES' flag is 'true', files which no longer exist will be deleted from ${dest}"
+ delete_flag='-d'
+else
+ delete_flag=''
+fi
+
+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 ${DEPLOY_TYPE} app from ${dest}..."
+ echo "gsutil -m rm -r \"$dest\""
+ gsutil -m rm -r "$dest"
+else
+ echo "Deploying ${DEPLOY_TYPE} app to ${dest}..."
+ echo "gsutil -h \"Cache-Control:public, max-age=$cache_control_max_age\" -m rsync $delete_flag -c -r \"$src\" \"$dest\""
+ gsutil -h "Cache-Control:public, max-age=$cache_control_max_age" -m rsync $delete_flag -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" "{}" +;