index.md 11,2 КБ
Newer Older
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
1
2
3
4
---
type: reference
---

Evan Read's avatar
Evan Read включено в состав коммита
5
# Review Apps
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
6

Evan Read's avatar
Evan Read включено в состав коммита
7
8
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/21971) in GitLab 8.12. Further additions were made in GitLab 8.13 and 8.14.
> - Inspired by [Heroku's Review Apps](https://devcenter.heroku.com/articles/github-integration-review-apps), which itself was inspired by [Fourchette](https://github.com/rainforestapp/fourchette).
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
9

Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
10
Review Apps is a collaboration tool that takes the hard work out of providing an environment to showcase product changes.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
11

Evan Read's avatar
Evan Read включено в состав коммита
12
13
## Introduction

Evan Read's avatar
Evan Read включено в состав коммита
14
15
16
Review Apps:

- Provide an automatic live preview of changes made in a feature branch by spinning up a dynamic environment for your merge requests.
Hrishi's avatar
Hrishi включено в состав коммита
17
- Allow designers and product managers to see your changes without needing to check out your branch and run your changes in a sandbox environment.
Marcel Amirault's avatar
Marcel Amirault включено в состав коммита
18
- Are fully integrated with the [GitLab DevOps LifeCycle](../../README.md#the-entire-devops-lifecycle).
Evan Read's avatar
Evan Read включено в состав коммита
19
20
21
22
- Allow you to deploy your changes wherever you want.

![Review Apps Workflow](img/continuous-delivery-review-apps.svg)

Evan Read's avatar
Evan Read включено в состав коммита
23
In the above example:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
24

Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
25
- A Review App is built every time a commit is pushed to `topic branch`.
Evan Read's avatar
Evan Read включено в состав коммита
26
27
28
- The reviewer fails two reviews before passing the third review.
- Once the review as passed, `topic branch` is merged into `master` where it's deploy to staging.
- After been approved in staging, the changes that were merged into `master` are deployed in to production.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
29

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
30
## How Review Apps work
Evan Read's avatar
Evan Read включено в состав коммита
31
32
33
34
35

A Review App is a mapping of a branch with an [environment](../environments.md).
Access to the Review App is made available as a link on the [merge request](../../user/project/merge_requests.md) relevant to the branch.

The following is an example of a merge request with an environment set dynamically.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
36
37
38

![Review App in merge request](img/review_apps_preview_in_mr.png)

Evan Read's avatar
Evan Read включено в состав коммита
39
In this example, a branch was:
Evan Read's avatar
Evan Read включено в состав коммита
40
41
42
43

- Successfully built.
- Deployed under a dynamic environment that can be reached by clicking on the **View app** button.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
44
45
46
47
48
49
After adding Review Apps to your workflow, you follow the branched Git flow. That is:

1. Push a branch and let the Runner deploy the Review App based on the `script` definition of the dynamic environment job.
1. Wait for the Runner to build and deploy your web application.
1. Click on the link provided in the merge request related to the branch to see the changes live.

Evan Read's avatar
Evan Read включено в состав коммита
50
## Configuring Review Apps
Evan Read's avatar
Evan Read включено в состав коммита
51

Evan Read's avatar
Evan Read включено в состав коммита
52
Review Apps are built on [dynamic environments](../environments.md#configuring-dynamic-environments), which allow you to dynamically create a new environment for each branch.
Evan Read's avatar
Evan Read включено в состав коммита
53

Evan Read's avatar
Evan Read включено в состав коммита
54
The process of configuring Review Apps is as follows:
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
55

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
56
1. Set up the infrastructure to host and deploy the Review Apps (check the [examples](#review-apps-examples) below).
Evan Read's avatar
Evan Read включено в состав коммита
57
1. [Install](https://docs.gitlab.com/runner/install/) and [configure](https://docs.gitlab.com/runner/commands/) a Runner to do deployment.
Eric Hendricks's avatar
Eric Hendricks включено в состав коммита
58
1. Set up a job in `.gitlab-ci.yml` that uses the [predefined CI environment variable](../variables/README.md) `${CI_COMMIT_REF_NAME}` to create dynamic environments and restrict it to run only on branches.
Evan Read's avatar
Evan Read включено в состав коммита
59
1. Optionally, set a job that [manually stops](../environments.md#stopping-an-environment) the Review Apps.
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
60

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
61
## Review Apps examples
Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
62

Evan Read's avatar
Evan Read включено в состав коммита
63
The following are example projects that demonstrate Review App configuration:
Evan Read's avatar
Evan Read включено в состав коммита
64
65
66
67

- [NGINX](https://gitlab.com/gitlab-examples/review-apps-nginx).
- [OpenShift](https://gitlab.com/gitlab-examples/review-apps-openshift).

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
68
<i class="fa fa-youtube-play youtube" aria-hidden="true"></i>
Evan Read's avatar
Evan Read включено в состав коммита
69
See also the video [Demo: Cloud Native Development with GitLab](https://www.youtube.com/watch?v=jfIyQEwrocw), which includes a Review Apps example.
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
70

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
71
## Route Maps
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
72

Evan Read's avatar
Evan Read включено в состав коммита
73
> Introduced in GitLab 8.17. In GitLab 11.5, the file links are available in the merge request widget.
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
74
75
76

Route Maps allows you to go directly from source files
to public pages on the [environment](../environments.md) defined for
Evan Read's avatar
Evan Read включено в состав коммита
77
78
79
Review Apps.

Once set up, the review app link in the merge request
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
80
81
82
widget can take you directly to the pages changed, making it easier
and faster to preview proposed modifications.

Evan Read's avatar
Evan Read включено в состав коммита
83
Configuring Route Maps involves telling GitLab how the paths of files
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
84
85
86
87
88
89
90
91
in your repository map to paths of pages on your website using a Route Map.
Once set, GitLab will display **View on ...** buttons, which will take you
to the pages changed directly from merge requests.

To set up a route map, add a a file inside the repository at `.gitlab/route-map.yml`,
which contains a YAML array that maps `source` paths (in the repository) to `public`
paths (on the website).

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
92
### Route Maps example
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
93

Evan Read's avatar
Evan Read включено в состав коммита
94
The following is an example of a route map for [Middleman](https://middlemanapp.com),
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
a static site generator (SSG) used to build [GitLab's website](https://about.gitlab.com),
deployed from its [project on GitLab.com](https://gitlab.com/gitlab-com/www-gitlab-com):

```yaml
# Team data
- source: 'data/team.yml' # data/team.yml
  public: 'team/' # team/

# Blogposts
- source: /source\/posts\/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.+?)\..*/ # source/posts/2017-01-30-around-the-world-in-6-releases.html.md.erb
  public: '\1/\2/\3/\4/' # 2017/01/30/around-the-world-in-6-releases/

# HTML files
- source: /source\/(.+?\.html).*/ # source/index.html.haml
  public: '\1' # index.html

# Other files
- source: /source\/(.*)/ # source/images/blogimages/around-the-world-in-6-releases-cover.png
  public: '\1' # images/blogimages/around-the-world-in-6-releases-cover.png
```

Evan Read's avatar
Evan Read включено в состав коммита
116
Mappings are defined as entries in the root YAML array, and are identified by a `-` prefix. Within an entry, there is a hash map with two keys:
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
117
118

- `source`
Evan Read's avatar
Evan Read включено в состав коммита
119
120
121
122
123
124
125
126
  - A string, starting and ending with `'`, for an exact match.
  - A regular expression, starting and ending with `/`, for a pattern match:
    - The regular expression needs to match the entire source path - `^` and `$` anchors are implied.
    - Can include capture groups denoted by `()` that can be referred to in the `public` path.
    - Slashes (`/`) can, but don't have to, be escaped as `\/`.
    - Literal periods (`.`) should be escaped as `\.`.
- `public`, a string starting and ending with `'`.
  - Can include `\N` expressions to refer to capture groups in the `source` regular expression in order of their occurrence, starting with `\1`.
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
127
128
129
130
131
132
133
134
135
136
137
138

The public path for a source path is determined by finding the first
`source` expression that matches it, and returning the corresponding
`public` path, replacing the `\N` expressions with the values of the
`()` capture groups if appropriate.

In the example above, the fact that mappings are evaluated in order
of their definition is used to ensure that `source/index.html.haml`
will match `/source\/(.+?\.html).*/` instead of `/source\/(.*)/`,
and will result in a public path of `index.html`, instead of
`index.html.haml`.

Evan Read's avatar
Evan Read включено в состав коммита
139
Once you have the route mapping set up, it will take effect in the following locations:
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
140

Evan Read's avatar
Evan Read включено в состав коммита
141
142
143
144
- In the merge request widget. The:
  - **View app** button will take you to the environment URL set in `.gitlab-ci.yml`.
  - Dropdown will list the first 5 matched items from the route map, but you can filter them if more
    than 5 are available.
Marcia Ramos's avatar
Marcia Ramos включено в состав коммита
145
146
147
148
149
150
151
152
153
154

    ![View app file list in merge request widget](img/view_on_mr_widget.png)

- In the diff for a merge request, comparison, or commit.

    !["View on env" button in merge request diff](img/view_on_env_mr.png)

- In the blob file view.

    !["View on env" button in file view](img/view_on_env_blob.png)
Evan Read's avatar
Evan Read включено в состав коммита
155

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
156
## Visual Reviews **(STARTER)**
sarahghp's avatar
sarahghp включено в состав коммита
157

Sarah Groff Hennigh-Palermo's avatar
Sarah Groff Hennigh-Palermo включено в состав коммита
158
159
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ee/issues/10761) in GitLab Starter 12.0.

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
160
161
162
With Visual Reviews, you can provide a feedback form to your Review Apps so
that reviewers can post comments directly from the app back to the merge request
that spawned the Review App.
Sarah Groff Hennigh-Palermo's avatar
Sarah Groff Hennigh-Palermo включено в состав коммита
163

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
164
### Configuring Visual Reviews
sarahghp's avatar
sarahghp включено в состав коммита
165

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
166
167
168
169
The feedback form is served through a script you add to pages in your Review App.
If you have [Developer permissions](../../user/permissions.md) to the project,
you can access it by clicking the **Review** button in the **Pipeline** section
of the merge request.
sarahghp's avatar
sarahghp включено в состав коммита
170

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
171
![review button](img/review_button.png)
sarahghp's avatar
sarahghp включено в состав коммита
172

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
173
174
175
176
177
178
179
180
181
182
183
184
185
186
The provided script should be added to the `<head>` of you application and
consists of some project and merge request specific values. Here's what it
looks like:

```html
<script
  data-project-id='11790219'
  data-merge-request-id='1'
  data-mr-url='https://gitlab.example.com'
  data-project-path='sarah/review-app-tester'
  id='review-app-toolbar-script'
  src='https://gitlab.example.com/assets/webpack/visual_review_toolbar.js'>
</script>
```
Sarah Groff Hennigh-Palermo's avatar
Sarah Groff Hennigh-Palermo включено в состав коммита
187

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
Ideally, you should use [environment variables](../variables/predefined_variables.md)
to replace those values at runtime when each review app is created:

- `data-project-id` is the project ID, which can be found by the `CI_PROJECT_ID`
  variable.
- `data-merge-request-id` is the merge request ID, which can be found by the
  `CI_MERGE_REQUEST_IID` variable. `CI_MERGE_REQUEST_IID` is available only if
  [`only: [merge_requests]`](../merge_request_pipelines/index.md)
  is used and the merge request is created.
- `data-mr-url` is the URL of the GitLab instance and will be the same for all
  review apps.
- `data-project-path` is the project's path, which can be found by `CI_PROJECT_PATH`.
- `id` is always `review-app-toolbar-script`, you don't need to change that.
- `src` is the source of the review toolbar script, which resides in the
  respective GitLab instance and will be the same for all review apps.

For example, in a Ruby application, you would need to have this script:

```html
<script
  data-project-id="ENV['CI_PROJECT_ID']"
  data-merge-request-id="ENV['CI_MERGE_REQUEST_IID']"
  data-mr-url='https://gitlab.example.com'
  data-project-path="ENV['CI_PROJECT_PATH']"
  id='review-app-toolbar-script'
  src='https://gitlab.example.com/assets/webpack/visual_review_toolbar.js'>
</script>
```
Sarah Groff Hennigh-Palermo's avatar
Sarah Groff Hennigh-Palermo включено в состав коммита
216

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
217
218
Then, when your app is deployed via GitLab CI/CD, those variables should get
replaced with their real values.
sarahghp's avatar
sarahghp включено в состав коммита
219

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
220
221
222
NOTE: **Note:**
Future enhancements [are planned](https://gitlab.com/gitlab-org/gitlab-ee/issues/11322)
to make this process even easier.
sarahghp's avatar
sarahghp включено в состав коммита
223

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
224
### Using Visual Reviews
sarahghp's avatar
sarahghp включено в состав коммита
225

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
226
227
228
After Visual Reviews has been [enabled](#configuring-visual-reviews) for the
Review App, the Visual Reviews feedback form is overlaid on the app's pages at
the bottom-right corner.
sarahghp's avatar
sarahghp включено в состав коммита
229

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
230
![Visual review feedback form](img/toolbar_feeback_form.png)
sarahghp's avatar
sarahghp включено в состав коммита
231

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
232
233
234
235
236
237
238
239
240
241
242
To use the feedback form:

1. Create a [personal access token](../../user/profile/personal_access_tokens.md)
   with the API scope selected.
1. Paste the token into the feedback box when prompted. If you select **Remember me**,
   your browser stores the token so that future visits to Review Apps at the same URL
   will not require you to re-enter the token. To clear the token, click **Log out**.
1. Make a comment on the visual review. You can make use of all the
   [Markdown annotations](../../user/markdown.md) that are also available in
   merge request comments.
1. Finally, click **Send feedback**.
sarahghp's avatar
sarahghp включено в состав коммита
243

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
244
245
After you make and submit a comment in the visual review box, it will appear
automatically in the respective merge request.
Sarah Groff Hennigh-Palermo's avatar
Sarah Groff Hennigh-Palermo включено в состав коммита
246

Achilleas Pipinellis's avatar
Achilleas Pipinellis включено в состав коммита
247
248
249
250
251
TIP: **Tip:**
Because tokens must be entered on a per-domain basis and they can only be accessed
once, different review apps will not remember your token. You can save the token
to your password manager specifically for the purpose of Visual Reviews. This way,
you will not need to create additional tokens for each merge request.
sarahghp's avatar
sarahghp включено в состав коммита
252

Evan Read's avatar
Evan Read включено в состав коммита
253
254
255
## Limitations

Review App limitations are the same as [environments limitations](../environments.md#limitations).