README.md 3.14 KB
Newer Older
Mark Pundsack's avatar
Mark Pundsack committed
1
# This is an example project that shows how to use Review Apps
Kamil Trzciński's avatar
Kamil Trzciński committed
2

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
3
4
5
This is a very basic project that has one static page, but it shows how to use
the environments feature of GitLab and the recently introduced dynamic
environments which can be used for Review Apps.
Kamil Trzciński's avatar
Kamil Trzciński committed
6

Mark Pundsack's avatar
Mark Pundsack committed
7
8
9
10
Review Apps allow you to create a new environment for each of your branches.
This review app is then visible as a link when you visit the merge request
for the branch. That way you are able to see all changes
introduced by the merge request changes, running live.
Kamil Trzciński's avatar
Kamil Trzciński committed
11
12

The example here uses a set of 3 environments:
Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
13

Mark Pundsack's avatar
Mark Pundsack committed
14
1. `production`: you trigger deploys to production manually, by clicking the **Production**
Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
15
   action under the **Pipelines** tab of your project.
Mark Pundsack's avatar
Mark Pundsack committed
16
1. `staging`: staging is deployed automatically when changes to `master` get
Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
17
   merged.
Mark Pundsack's avatar
Mark Pundsack committed
18
1. `review/*`: the review app is created for any other branch that is pushed to GitLab.
Kamil Trzciński's avatar
Kamil Trzciński committed
19

20
21
## Access the example

Mark Pundsack's avatar
Mark Pundsack committed
22
This project can be accessed under these addresses:
Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
23

24
25
1. `production`: http://production.138.68.69.232.xip.io/
1. `staging`: http://staging.138.68.69.232.xip.io/
Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
26
1. `review` for merge request [!1](https://gitlab.com/gitlab-examples/review-apps-nginx/merge_requests/1): http://update-hello-world.138.68.69.232.xip.io/
27

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
28
The review app can be seen in [Merge Request !1](https://gitlab.com/gitlab-examples/review-apps-nginx/merge_requests/1)
29
which is open:
30

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
31
<img src="images/merge_request.png" width="600">
32

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
33
34
---

Kamil Trzciński's avatar
Kamil Trzciński committed
35
Or in [Merge Request !2](https://gitlab.com/gitlab-examples/review-apps-nginx/merge_requests/2)
Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
36
which is merged:
37

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
38
<img src="images/merge_merged.png" width="600">
39

Kamil Trzciński's avatar
Kamil Trzciński committed
40
41
## Use it for your projects

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
42
43
This is a very simple example, but you can adapt it for your needs and have a
page that is deployed dynamically.
Kamil Trzciński's avatar
Kamil Trzciński committed
44
45
46

To do that you have to follow these few simple steps.

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
47
1. [Install GitLab Runner](https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/install/linux-repository.md)
Kamil Trzciński's avatar
Kamil Trzciński committed
48

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
49
    Use `shell` executor and assign a few tags: `nginx`, `review-apps`, `deploy`.
Kamil Trzciński's avatar
Kamil Trzciński committed
50

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
51
1. Configure your server
Kamil Trzciński's avatar
Kamil Trzciński committed
52

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
53
    The script was tested on Ubuntu 16.04:
Kamil Trzciński's avatar
Kamil Trzciński committed
54

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
55
56
57
58
59
    ```
    sudo apt-get update
    sudo apt-get install -y nginx
    sudo mkdir -p /srv/nginx/pages
    sudo chown -R gitlab-runner /srv/nginx/pages
Kamil Trzciński's avatar
Kamil Trzciński committed
60

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
61
62
63
64
65
    cat <<"EOF" | sudo tee /etc/nginx/sites-available/dynamic-pages
    server {
        listen 80;
        server_name ~^(www\.)?(?<sname>.+?).my.domain.com$;
        root /srv/nginx/pages/$sname/public;
Kamil Trzciński's avatar
Kamil Trzciński committed
66

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
67
        index index.html index.htm index.php;
Kamil Trzciński's avatar
Kamil Trzciński committed
68

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
69
        charset utf-8;
Kamil Trzciński's avatar
Kamil Trzciński committed
70

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
71
72
73
        location / {
            try_files $uri $uri/ /index.html;
        }
Kamil Trzciński's avatar
Kamil Trzciński committed
74

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
75
76
        access_log /var/log/nginx/$sname-access.log;
        error_log  /var/log/nginx/pages-error.log debug;
Kamil Trzciński's avatar
Kamil Trzciński committed
77
    }
Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
78
79
80
81
    EOF
    sudo ln -s /etc/nginx/sites-{available,enabled}/dynamic-pages
    sudo service nginx restart
    ```
Kamil Trzciński's avatar
Kamil Trzciński committed
82

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
83
    **Replace my.domain.com with your wildcard DNS record**
Kamil Trzciński's avatar
Kamil Trzciński committed
84

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
85
1. Add a Secure Variable with your Domain
Kamil Trzciński's avatar
Kamil Trzciński committed
86

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
87
    Add a `APPS_DOMAIN` to Secure Variables with your domain, ex.: `my.domain.com`
Kamil Trzciński's avatar
Kamil Trzciński committed
88

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
89
1. Modify `.gitlab-ci.yml`
Kamil Trzciński's avatar
Kamil Trzciński committed
90

Achilleas Pipinellis's avatar
Achilleas Pipinellis committed
91
92
    Check out other examples of static page generators: https://gitlab.com/groups/pages
    and incorporate them into `.gitlab-ci.yml`
Kamil Trzciński's avatar
Kamil Trzciński committed
93
94

You can now start pushing your changes and see them live!