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

build-and-deploy.gitlab-ci.yml « ci « .gitlab - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5e179eef6f989db16a7526e0d3a925c089234e92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
###############################################
#        Build and deploy the website         #
###############################################

.build_base:
  stage: build
  extends:
    - .retry
    - .bundle_and_pnpm
  artifacts:
    paths:
      - 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.2-node-18
  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
  rules:
    - if: '$CI_PROJECT_PATH == "gitlab-renovate-forks/gitlab-docs"'
      when: manual
    - if: '$CI_PROJECT_PATH !~ /^gitlab-org/'
      when: never
    - if: '$CI_MERGE_REQUEST_EVENT_TYPE == "merge_train"'
      when: never
    - if: '$DOCS_PROJECT_PIPELINE_TYPE =~ /^MR pipeline.*/'
    - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Upstream review app pipeline"'

#
# The script lines for compiling and minifying the site
#
.compile-and-minify-scripts:
  script:
    - bundle exec rake default
    - bundle exec nanoc compile -VV
    - pnpm compile:css
    - pnpm compile:js
    # Create _redirects for Pages redirects
    - bundle exec rake redirects
    # Build the Lunr.js search index if needed
    - if [[ "$SEARCH_BACKEND" == "lunr" ]]; then make build-lunr-index; fi
    # Minify the assets of the resulting site
    - mkdir dest/
    - scripts/minify-assets.sh dest/ public/
    - rm -rf public/
    - mv dest/public public/

#
# The script lines for gzipping the site (not used in upstream review apps, to speed up pipelines)
#
.gzip-scripts:
  script:
    # Use gzip to compress static content for faster web serving. Keep uncompressed files for browsers that don't support
    # compressed files: https://docs.gitlab.com/ee/user/project/pages/introduction.html#serving-compressed-assets
    - find public/ -type f \( -iname "*.html" -o -iname "*.js"  -o -iname "*.css"  -o -iname "*.svg" -o -iname "*.json" \) -exec gzip --keep  --best --force --verbose {} \;
    - SIZE_AFTER_GZIP=$(du -sh public/ | awk '{print $1}')
    # Print size results
    - echo -e "Size after adding gzipped versions ..... $SIZE_AFTER_GZIP"

#
# Compile "prod" only on the default and stable branches
#
compile_prod:
  extends:
    - .rules_prod
    - .build_base
  variables:
    SEARCH_BACKEND: 'google'
    NANOC_ENV: 'production'
  script:
    - !reference [".compile-and-minify-scripts", "script"]
    - !reference [".gzip-scripts", "script"]

#
# Compile "dev" for all MRs in `gitlab-docs`
#
compile_dev:
  extends:
    - .rules_dev
    - .build_base
  script:
    - !reference [".compile-and-minify-scripts", "script"]
    - !reference [".gzip-scripts", "script"]

#
# Compile but skip gzip step for review apps from upstream projects
#
compile_upstream_review_app:
  extends:
    - .rules_upstream_review_app
    - .build_base
  script:
    - !reference [".compile-and-minify-scripts", "script"]

###############################################
#               Review Apps                   #
###############################################

#
# Deploy the Review App on a GCS bucket.
#
review:
  stage: deploy
  extends:
    - .retry
    - .review-environment
  before_script: []
  needs:
    - job: compile_dev
      optional: true
    - job: compile_upstream_review_app
      optional: true
  cache: {}
  script:
    - scripts/review-replace-urls.sh
    - scripts/deploy-review-app.sh

#
# Stop the Review App
#
review_stop:
  stage: deploy
  extends:
    - .retry
    - .review-environment
  variables:
    DEPLOY_DELETE_APP: 'true'
  environment:
    action: stop
  needs: []
  artifacts: {}
  before_script: []
  cache: {}
  script:
    - scripts/deploy-review-app.sh
  allow_failure: true
  when: manual

#
# Clean up stopped review app environments. Done once a month in a scheduled pipeline,
# only deletes stopped environments that are over 30 days old.
#
delete_stopped_environments:
  image: alpine:latest
  needs: []
  before_script: []
  dependencies: []
  rules:
    - if: '$DOCS_PROJECT_PIPELINE_TYPE == "Monthly stopped environments cleanup pipeline"'
  stage: test
  script:
    - apk --update add curl jq
    - curl --request DELETE "https://gitlab.com/api/v4/projects/1794617/environments/review_apps?limit=1000&dry_run=false&private_token=$DELETE_ENVIRONMENTS_TOKEN" | jq

###############################################
#          GitLab Pages (production)          #
###############################################

#
# Deploy to production with GitLab Pages
#
pages:
  resource_group: pages
  extends:
    - .rules_pages
    - .retry
  image: registry.gitlab.com/gitlab-org/gitlab-docs:latest
  stage: deploy
  variables:
    GIT_STRATEGY: none
  before_script: []
  cache: {}
  environment:
    name: production
    url: https://docs.gitlab.com
  # We are using dependencies, because we do not want to
  # re-deploy if the previous stages failed.
  dependencies:
    - compile_prod    # Contains the public directory
  script:
    #
    # We want to use the artifacts of the compile_prod job as
    # the latest docs deployment, and the other versions are
    # taken from /usr/share/nginx/html which are included in
    # the image we pull from.
    #
    - mv /usr/share/nginx/html/1* public/
  artifacts:
    paths:
      - public
    expire_in: 1d