|
1 |
| -# Using CML on GitLab |
| 1 | +# Get Started with CML on GitLab |
2 | 2 |
|
3 |
| -Here, we'll walk through a tutorial to start using CML on GitLab. |
| 3 | +Here, we'll walk through a tutorial to start using CML. For simplicity, we'll |
| 4 | +show the demo in GitLab CI/CD, but instructions are pretty similar for all the |
| 5 | +supported CI systems. |
4 | 6 |
|
5 | 7 | 1. Fork our
|
6 | 8 | [example project repository](https://gitlab.com/iterative.ai/example_cml).
|
7 |
| - Click on Fork and select the namespace where you would like to keep the |
8 |
| - project. |
9 | 9 |
|
10 | 10 | 
|
11 | 11 |
|
12 |
| -2. ⚠️ In GitLab, to use CML, you must create a variable called a `REPO_TOKEN` |
13 |
| - whose value is a Personal Access Token. To do this: |
| 12 | +2. ⚠️ Follow |
| 13 | + [these instructions](https://cml.dev/doc/self-hosted-runners?tab=GitLab#personal-access-token) |
| 14 | + to configure a GitLab access token for CML. |
14 | 15 |
|
15 |
| - a. Click on your Avatar in the upper right side and click on "Edit Profile." |
| 16 | +<admon type="tip"> |
16 | 17 |
|
17 |
| - b. Along the left side of the screen go to Access Tokens. |
| 18 | +The following steps can all be done in the GitLab browser interface. However, to |
| 19 | +follow along the commands, we recommend cloning your fork to your local |
| 20 | +workstation: |
18 | 21 |
|
19 |
| - c. In the "Name" field, type `REPO_TOKEN` and check boxes to select `api`, |
20 |
| - `read_repository` and `write_repository`. |
| 22 | +```cli |
| 23 | +$ git clone https://gitlab.com/<your-username>/example_cml |
| 24 | +$ cd example_cml |
| 25 | +``` |
21 | 26 |
|
22 |
| - d. Click on the "Create personal access token" button and copy the generated |
23 |
| - access token. |
| 27 | + |
24 | 28 |
|
25 |
| -  |
| 29 | +</admon> |
26 | 30 |
|
27 |
| - e. Head back to your fork by clicking the Projects tab next to the GitLab |
28 |
| - logo and select it. |
29 |
| - |
30 |
| - f. On the left hand side Navigate to **Settings** ➡ **CI/CD** ➡ |
31 |
| - **Variables**. |
32 |
| - |
33 |
| -  |
34 |
| - |
35 |
| - f. Scroll to Variables and expand the field. Click "Add Variable". In the Key |
36 |
| - field, type `REPO_TOKEN`. In the Value field, paste your Personal Access |
37 |
| - Token. Check the "Mask variable" box, uncheck "Protect variable", and then |
38 |
| - save the variable by clicking "Add variable" at the bottom of the dialog box. |
39 |
| - |
40 |
| -> 💡 The following steps can all be done in the GitLab website. However, to |
41 |
| -> follow along the steps, we recommend cloning your fork to your local |
42 |
| -> workstation. |
43 |
| -
|
44 |
| -3. Go back to your forked `example_cml` project. Copy the Clone with HTTPS as |
45 |
| - shown in the image below, and then in your terminal, type the following |
46 |
| - command, replacing `<user_name>` with your own from GitLab. |
47 |
| - |
48 |
| -  |
49 |
| - |
50 |
| - ```cli |
51 |
| - $ git clone https://gitlab.com/<user_name>/example_cml.git |
52 |
| - ``` |
53 |
| - |
54 |
| -4. Change directory to `example_cml`. |
55 |
| - |
56 |
| - ```cli |
57 |
| - $ cd example_cml |
58 |
| - ``` |
59 |
| - |
60 |
| -5. To create a CML workflow, use your editor of choice to copy the following |
61 |
| - into a new file `.gitlab-ci.yml` and save. |
| 31 | +3. To create a CML workflow, copy the following into a new file named |
| 32 | + `.gitlab-ci.yml`: |
62 | 33 |
|
63 | 34 | ```yaml
|
64 | 35 | train-and-report:
|
65 | 36 | image: iterativeai/cml:0-dvc2-base1
|
66 | 37 | script:
|
67 | 38 | - pip install -r requirements.txt
|
68 | 39 | - python train.py
|
| 40 | + |
69 | 41 | - cat metrics.txt >> report.md
|
70 | 42 | - cml publish plot.png --md >> report.md
|
71 | 43 | - cml send-comment report.md
|
72 | 44 | ```
|
73 | 45 |
|
74 |
| -6. In your text editor, open `train.py` and edit line 16 to `depth = 5`. |
| 46 | +4. In your text editor, open `train.py` and modify line 15 to `depth = 5`. |
75 | 47 |
|
76 |
| -7. Commit and push the changes using: |
| 48 | +5. Commit and push the changes: |
77 | 49 |
|
78 | 50 | ```cli
|
79 | 51 | $ git checkout -b experiment
|
80 | 52 | $ git add . && git commit -m "modify forest depth"
|
81 | 53 | $ git push origin experiment
|
82 | 54 | ```
|
83 | 55 |
|
84 |
| -8. Go back to GitLab in a Browser window and create a merge request. |
| 56 | +6. In GitLab, create a Merge Request to compare the `experiment` branch to |
| 57 | + `master`. |
85 | 58 |
|
86 | 59 | 
|
87 | 60 |
|
88 |
| -9. If you arrive at a New Merge Request screen that says it's merging into |
89 |
| - anything _other_ than your local repository, click on `Change branches` seen |
90 |
| - here. |
| 61 | + The "New Merge Request" page will let you **Change branches**: |
91 | 62 |
|
92 | 63 | 
|
93 | 64 |
|
94 |
| -10. ⚠️ Change target branch to your local branch with your username. |
| 65 | + <admon type="warn"> |
| 66 | + |
| 67 | + Ensure the target is your fork (under your username): |
| 68 | + |
| 69 | +  |
| 70 | + |
| 71 | + </admon> |
| 72 | + |
| 73 | + Continue and submit the Merge Request. Shortly, you should see a comment |
| 74 | + appear in the Merge Request with your CML report. This is a result of the |
| 75 | + `cml send-comment` command in your workflow. |
95 | 76 |
|
96 |
| -  |
| 77 | +  |
97 | 78 |
|
98 |
| -11. Click on the "Compare branches and continue" button. Enter any additional |
99 |
| - comments you would like to put in the description and click the "Submit |
100 |
| - merge request" button. Shortly, you should see a comment from GitLab CI |
101 |
| - appear in the Pull Request with your CML report. This is a result of the |
102 |
| - `cml send-comment` command in your workflow. |
| 79 | +This is the gist of the CML workflow: when you push changes to your GitLab |
| 80 | +repository, the workflow in your `.gitlab-ci.yml` file gets run and a report |
| 81 | +generated. |
103 | 82 |
|
104 |
| -  |
| 83 | +CML commands let you display relevant results from the workflow, like model |
| 84 | +performance metrics and vizualizations, in GitLab comments. What kind of |
| 85 | +workflow you want to run, and want to put in your CML report, is up to you. |
105 | 86 |
|
106 | 87 | ## Final Solution
|
107 | 88 |
|
|
0 commit comments