summaryrefslogtreecommitdiff
path: root/.gitlab/ci/review-apps/main.gitlab-ci.yml
blob: b72afedc3b09b94c7196e0cc1b0cbc6791ee7c70 (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
196
default:
  interruptible: true

stages:
  - prepare
  - deploy
  - qa
  - post-qa
  - dast

include:
  - local: .gitlab/ci/global.gitlab-ci.yml
  - local: .gitlab/ci/rules.gitlab-ci.yml
  - local: .gitlab/ci/review-apps/rules.gitlab-ci.yml
  - local: .gitlab/ci/review-apps/qa.gitlab-ci.yml
  - local: .gitlab/ci/review-apps/dast.gitlab-ci.yml
  - local: .gitlab/ci/review-apps/dast-api.gitlab-ci.yml

.base-before_script: &base-before_script
  - source ./scripts/utils.sh
  - source ./scripts/review_apps/review-apps.sh
  - apt-get update && apt-get install -y jq

dont-interrupt-me:
  extends: .rules:dont-interrupt
  stage: prepare
  interruptible: false
  script:
    - echo "This jobs makes sure this pipeline won't be interrupted! See https://docs.gitlab.com/ee/ci/yaml/#interruptible."

review-build-cng-env:
  extends:
    - .default-retry
    - .review:rules:review-build-cng
  image: ${REGISTRY_HOST}/${REGISTRY_GROUP}/gitlab-build-images/debian-${DEBIAN_VERSION}-ruby-${RUBY_VERSION}:bundler-2.3
  stage: prepare
  needs:
    # We need this job because we need its `cached-assets-hash.txt` artifact, so that we can pass the assets image tag to the downstream CNG pipeline.
    - pipeline: $PARENT_PIPELINE_ID
      job: build-assets-image
  variables:
    BUILD_ENV: build.env
  before_script:
    - source ./scripts/utils.sh
    - install_gitlab_gem
  script:
    - 'ruby -r./scripts/trigger-build.rb -e "puts Trigger.variables_for_env_file(Trigger::CNG.new.variables)" > $BUILD_ENV'
    - echo "GITLAB_ASSETS_TAG=$(assets_image_tag)" >> $BUILD_ENV
    - ruby -e 'puts "FULL_RUBY_VERSION=#{RUBY_VERSION}"' >> build.env
    - cat $BUILD_ENV
  artifacts:
    reports:
      dotenv: $BUILD_ENV
    paths:
      - $BUILD_ENV
    expire_in: 7 days
    when: always

review-build-cng:
  extends: .review:rules:review-build-cng
  stage: prepare
  needs: ["review-build-cng-env"]
  inherit:
    variables: false
  variables:
    TOP_UPSTREAM_SOURCE_PROJECT: "${TOP_UPSTREAM_SOURCE_PROJECT}"
    TOP_UPSTREAM_SOURCE_REF: "${TOP_UPSTREAM_SOURCE_REF}"
    TOP_UPSTREAM_SOURCE_JOB: "${TOP_UPSTREAM_SOURCE_JOB}"
    TOP_UPSTREAM_SOURCE_SHA: "${TOP_UPSTREAM_SOURCE_SHA}"
    TOP_UPSTREAM_MERGE_REQUEST_PROJECT_ID: "${TOP_UPSTREAM_MERGE_REQUEST_PROJECT_ID}"
    TOP_UPSTREAM_MERGE_REQUEST_IID: "${TOP_UPSTREAM_MERGE_REQUEST_IID}"
    GITLAB_REF_SLUG: "${GITLAB_REF_SLUG}"
    # CNG pipeline specific variables
    GITLAB_VERSION: "${GITLAB_VERSION}"
    GITLAB_TAG: "${GITLAB_TAG}"
    GITLAB_ASSETS_TAG: "${GITLAB_ASSETS_TAG}"
    FORCE_RAILS_IMAGE_BUILDS: "${FORCE_RAILS_IMAGE_BUILDS}"
    CE_PIPELINE: "${CE_PIPELINE}"  # Based on https://docs.gitlab.com/ee/ci/jobs/job_control.html#check-if-a-variable-exists, `if: '$CE_PIPELINE'` will evaluate to `false` when this variable is empty
    EE_PIPELINE: "${EE_PIPELINE}"  # Based on https://docs.gitlab.com/ee/ci/jobs/job_control.html#check-if-a-variable-exists, `if: '$EE_PIPELINE'` will evaluate to `false` when this variable is empty
    GITLAB_ELASTICSEARCH_INDEXER_VERSION: "${GITLAB_ELASTICSEARCH_INDEXER_VERSION}"
    GITLAB_KAS_VERSION: "${GITLAB_KAS_VERSION}"
    GITLAB_METRICS_EXPORTER_VERSION: "${GITLAB_METRICS_EXPORTER_VERSION}"
    GITLAB_PAGES_VERSION: "${GITLAB_PAGES_VERSION}"
    GITLAB_SHELL_VERSION: "${GITLAB_SHELL_VERSION}"
    GITLAB_WORKHORSE_VERSION: "${GITLAB_WORKHORSE_VERSION}"
    GITALY_SERVER_VERSION: "${GITALY_SERVER_VERSION}"
    RUBY_VERSION: "${FULL_RUBY_VERSION}"
  trigger:
    project: gitlab-org/build/CNG-mirror
    branch: $TRIGGER_BRANCH
    strategy: depend

.review-workflow-base:
  extends:
    - .default-retry
  image: ${REVIEW_APPS_IMAGE}
  variables:
    HOST_SUFFIX: "${CI_ENVIRONMENT_SLUG}"
    DOMAIN: "-${CI_ENVIRONMENT_SLUG}.${REVIEW_APPS_DOMAIN}"
    GITLAB_HELM_CHART_REF: "ed813953079c1d81aa69d4cb8171c69aa9741f01"  # 6.5.4: https://gitlab.com/gitlab-org/charts/gitlab/-/commit/ed813953079c1d81aa69d4cb8171c69aa9741f01
  environment:
    name: review/${CI_COMMIT_REF_SLUG}${SCHEDULE_TYPE}  # No separator for SCHEDULE_TYPE so it's compatible as before and looks nice without it
    url: https://gitlab-${CI_ENVIRONMENT_SLUG}.${REVIEW_APPS_DOMAIN}
    on_stop: review-stop
    auto_stop_in: 6 hours

review-deploy:
  extends:
    - .review-workflow-base
    - .review:rules:review-deploy
  stage: deploy
  needs: ["review-build-cng"]
  cache:
    key: "review-deploy-dependencies-charts-${GITLAB_HELM_CHART_REF}-v1"
    paths:
      - "gitlab-${GITLAB_HELM_CHART_REF}"
  environment:
    action: start
  before_script:
    - export GITLAB_SHELL_VERSION=$(<GITLAB_SHELL_VERSION)
    - export GITALY_VERSION=$(<GITALY_SERVER_VERSION)
    - export GITLAB_WORKHORSE_VERSION=$(<GITLAB_WORKHORSE_VERSION)
    - echo "${CI_ENVIRONMENT_URL}" > environment_url.txt
    - echo "QA_GITLAB_URL=${CI_ENVIRONMENT_URL}" > environment.env
    - *base-before_script
    - !reference [".use-kube-context", before_script]
  script:
    - run_timed_command "check_kube_domain"
    - run_timed_command "download_chart"
    - run_timed_command "deploy" || (display_deployment_debug && exit 1)
    - run_timed_command "verify_deploy" || (display_deployment_debug && exit 1)
    - run_timed_command "disable_sign_ups" || (display_deployment_debug && exit 1)
  after_script:
    # Run seed-dast-test-data.sh only when DAST_RUN is set to true. This is to pupulate review app with data for DAST scan.
    # Set DAST_RUN to true when jobs are manually scheduled.
    - if [ "$DAST_RUN" == "true" ]; then source scripts/review_apps/seed-dast-test-data.sh; TRACE=1 trigger_proj_user_creation; fi
  artifacts:
    paths:
      - environment_url.txt
      - curl-logs/
    reports:
      dotenv: environment.env
    expire_in: 7 days
    when: always

review-deploy-sample-projects:
  extends:
    - .review-workflow-base
    - .review:rules:review-deploy
  stage: deploy
  needs: ["review-deploy"]
  environment:
    action: prepare
  before_script:
    - export GITLAB_SHELL_VERSION=$(<GITLAB_SHELL_VERSION)
    - export GITALY_VERSION=$(<GITALY_SERVER_VERSION)
    - export GITLAB_WORKHORSE_VERSION=$(<GITLAB_WORKHORSE_VERSION)
    - echo "${CI_ENVIRONMENT_URL}" > environment_url.txt
    - *base-before_script
    - !reference [".use-kube-context", before_script]
  script:
    - date
    - create_sample_projects

.review-stop-base:
  extends: .review-workflow-base
  environment:
    action: stop
  dependencies: []
  variables:
    # We're cloning the repo instead of downloading the script for now
    # because some repos are private and CI_JOB_TOKEN cannot access files.
    # See https://gitlab.com/gitlab-org/gitlab/issues/191273
    GIT_DEPTH: 1
  before_script:
    - source ./scripts/utils.sh
    - source ./scripts/review_apps/review-apps.sh
    - !reference [".use-kube-context", before_script]

review-delete-deployment:
  extends:
    - .review-stop-base
    - .review:rules:review-delete-deployment
  stage: prepare
  script:
    - delete_helm_release

review-stop:
  extends:
    - .review-stop-base
    - .review:rules:review-stop
  resource_group: review/${CI_COMMIT_REF_SLUG}${SCHEDULE_TYPE} # CI_ENVIRONMENT_SLUG is not available here and we want this to be the same as the environment
  stage: deploy
  needs: []
  script:
    - delete_helm_release