Skip to content

Commit da45e41

Browse files
authored
Merge pull request #19 from oer-particle-physics/gh-pages
module updates
2 parents ca01310 + e8223c0 commit da45e41

9 files changed

Lines changed: 121 additions & 106 deletions

File tree

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# FIXME Lesson title
2-
1+
# GitLab CI/CD in CMS(SW)
32
[![Create a Slack Account with us](https://img.shields.io/badge/Create_Slack_Account-The_Carpentries-071159.svg)](https://swc-slack-invite.herokuapp.com/)
43

54
This repository generates the corresponding lesson website from [The Carpentries](https://carpentries.org/) repertoire of lessons.
65

6+
> **Note**
7+
> Click [here](https://oer-particle-physics.github.io/gitlab-cms) for the training website!
8+
9+
The aim of this module is to learn how to run CMS software workflows (CMSSW) in a reproducible and secure way using the GitLab installation at CERN.
10+
711
## Contributing
812

913
We welcome all contributions to improve the lesson! Maintainers will do their best to help you if you have any
@@ -19,15 +23,11 @@ nicely explained in the chapter [Contributing to a Project](http://git-scm.com/b
1923
by Scott Chacon.
2024
Look for the tag ![good_first_issue](https://img.shields.io/badge/-good%20first%20issue-gold.svg). This indicates that the maintainers will welcome a pull request fixing this issue.
2125

22-
2326
## Maintainer(s)
2427

2528
Current maintainers of this lesson are
2629

27-
* FIXME
28-
* FIXME
29-
* FIXME
30-
30+
* [Clemens Lange](https://clange.ch/)
3131

3232
## Authors
3333

@@ -37,4 +37,9 @@ A list of contributors to the lesson can be found in [AUTHORS](AUTHORS)
3737

3838
To cite this lesson, please consult with [CITATION](CITATION)
3939

40+
## Open Educational Resources (OER) on Zenodo
41+
42+
This lesson is included in the ETH Domain Open Educational Resources for Research Data Management (RDM) community on Zenodo. These resources support researchers, students, and RDM staff in implementing best practices across the research data lifecycle. The materials developed here are published under open licenses (CC BY 4.0) and can be freely reused and adapted for teaching and training initiatives worldwide.
43+
44+
4045
[lesson-example]: https://carpentries.github.io/lesson-example

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
carpentry: "swc"
1111

1212
# Overall title for pages.
13-
title: "GitLab CI for CMS"
13+
title: "GitLab CI/CD in CMS(SW)"
1414

1515
# Life cycle stage of the lesson
1616
# possible values: "pre-alpha", "alpha", "beta", "stable"

_episodes/01-introduction.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: "Setting up an environment using CVMFS in GitLab CI (e.g. to run CMSSW)"
2+
title: "Setting up CMSSW in GitLab CI with CernVM File System (CVMFS)"
33
teaching: 10
44
exercises: 10
55
questions:
66
- "Which GitLab runners are needed?"
77
- "What's different w.r.t. LXPLUS?"
88
objectives:
9-
- "Know how to source the CMSSW environment"
10-
- "Understand the different commands that need to be used"
9+
- "Know how to source the CMSSW environment."
10+
- "Understand the different commands that need to be used."
1111
keypoints:
1212
- "Special GitLab CVMFS runners are required to run CI jobs that need CVMFS, e.g. to run CMSSW."
1313
- "If the setup script tries to access unset variables, then that can cause the CI to fail when using strict shell scripting checks."
@@ -18,19 +18,19 @@ CI/CD and also CERN-specific information:
1818
- [GitLab CI/CD documentation][gitlab-ci]
1919
- [CERN Knowledge Base Articles for the Git Service][snow-git]
2020

21-
These pages serve as a good entrypoint in case of problems and questions.
21+
These pages serve as a good entry point in case of problems and questions.
2222

2323
> ## Create a new GitLab project to follow along
2424
> Please [create a new GitLab project][gitlab-newproject] now to follow along.
2525
> To do so, select "Create blank project" and provide a project name.
26-
> You can for instance call it `awesome-gitlab-cms`.
26+
> You can, for instance, call it `awesome-gitlab-cms`.
2727
> You need to specify the project visibility level. Private, the default, is fine for this tutorial.
28-
> In the following, we will assume that all your work is in a directory called `awesome-workshop` in your
29-
> home directory and we will now clone the newly created project in a local repository therein:
28+
> In the following, we will assume that all your work is into a directory called `awesome-workshop` in your
29+
> home directory, and we will now clone the newly created project in a local repository therein:
3030
> `~/awesome-workshop/awesome-gitlab-cms`
3131
{: .callout}
3232

33-
The commands would look like this (replace `${USER}` by your CERN
33+
The commands would look like this (replace `${USER}` with your CERN
3434
username in case it isn't the same as on your laptop):
3535

3636
~~~
@@ -43,9 +43,9 @@ cd awesome-gitlab-cms
4343

4444
## Choosing the correct GitLab runner
4545

46-
We are now going to setup a GitLab CI. For that, we need to create a `.gitlab-ci.yml` file.
46+
We are now going to set up a GitLab CI. For that, we need to create a `.gitlab-ci.yml` file.
4747
Standard [GitLab CI runners at CERN](https://gitlab.docs.cern.ch/docs/Build%20your%20application/CI-CD/Runners/)
48-
do not mount CVMFS, which is required in many cases, for example for setting up CMSSW, to create a grid proxy, or to access LCG software stacks in `/cvmfs/sft.cern.ch/`.
48+
do not mount CVMFS, which is required in many cases, for example, for setting up CMSSW, to create a grid proxy, or to access LCG software stacks in `/cvmfs/sft.cern.ch/`.
4949
In order to get a runner that mounts CVMFS, you need
5050
to add a `tag` to your `gitlab-ci.yml` file:
5151

@@ -69,7 +69,7 @@ cmssw_setup:
6969
The `cmssw_setup` line defines the name of the job, and all the job does is
7070
list `/cvmfs/cms.cern.ch/`, which would fail if CVMFS isn't mounted.
7171

72-
To trigger the pipeline we need to commit the file and push it to GitLab:
72+
To trigger the pipeline, we need to commit the file and push it to GitLab:
7373

7474
~~~
7575
git add .gitlab-ci.yml
@@ -78,12 +78,12 @@ git push
7878
~~~
7979
{: .language-bash}
8080

81-
If you now navigate the GitLab UI with your browser you will see the CI running and eventually finishing.
81+
If you now navigate the GitLab UI with your browser, you will see the CI running and eventually finishing.
8282
You can check the output, and also the `cvmfs` label:
8383

8484
![A job with a GitLab CVMFS Runner showing the cvmfs label](../fig/cvmfs_tag.png)
8585

86-
In the following you'll will learn how to setup a GitLab CI job that runs CMSSW.
86+
In the following, you'll learn how to set up a GitLab CI job that runs CMSSW.
8787

8888
This should be regarded as an example for any CI job requiring access to CVMFS and accessing CMS-restricted files.
8989

@@ -108,7 +108,7 @@ cmsenv
108108
~~~
109109
{: .language-bash}
110110

111-
The first command is needed because CMSSW_10_6_30 is pretty old (we chose an old one on purpose!) and it does not have any build for the recent alma9 LXPLUS.
111+
The first command is needed because CMSSW_10_6_30 is pretty old (we chose an old one on purpose!), and it does not have any build for the recent alma9 LXPLUS.
112112
So we need to start a CentOS7 container first, which we do with the `cmssw-el7` command, as described in the [CMS singularity guide](https://cms-sw.github.io/singularity.html).
113113

114114
Depending on the software version chosen, the third command may print out a warning such as
@@ -150,14 +150,14 @@ of this command is that a few helper functions are defined, such as `cmsrel` and
150150

151151
A common pitfall when setting up CMSSW in GitLab is that the execution
152152
fails because the setup script doesn't follow best practices for shell
153-
scripts such as returning non-zero return values even if the setup is OK or
154-
using unset variables. Even if the script exits without visible error message,
153+
scripts, such as returning non-zero return values even if the setup is OK or
154+
using unset variables. Even if the script exits without a visible error message,
155155
there could be something wrong. It is therefore often a good idea to
156156
circumvent issues like that by disabling strict checks (issuing `set +u`) before running the
157157
setup command and enabling these checks afterwards again (issuing `set -u`).
158158

159159
> ## Exercise: Set up CMSSW in GitLab
160-
> Knowing all this, can you write the `.gitlab-ci.yml` file to set up CMSSW in GitLab starting from the fragment above and check if this is all working by executing `cmsRun --help` at the end?
160+
> Knowing all this, can you write the `.gitlab-ci.yml` file to set up CMSSW in GitLab, starting from the fragment above, and check if this is all working by executing `cmsRun --help` at the end?
161161
{: .challenge}
162162

163163
> ## Solution: Set up CMSSW in GitLab
@@ -181,8 +181,8 @@ setup command and enabling these checks afterwards again (issuing `set -u`).
181181
> ~~~
182182
> {: .language-yaml}
183183
>
184-
> The `image` directive tells the gitlab runner that it should run in a CentOS7 container, just like you would manually do on LXPLUS issuing `cmssw-el7`.
185-
> The `set +u` command turns off errors for referencing unset variables. It isn't really needed here, since `-u` (i.e. not allowing to use unset variables) isn't set by default, but the script would fail if one used `set -u` somewhere else, so it's safer to catch this here.
184+
> The `image` directive tells the GitLab runner that it should run in a CentOS7 container, just like you would manually do on LXPLUS issuing `cmssw-el7`.
185+
> The `set +u` command turns off errors for referencing unset variables. It isn't really needed here, since `-u` (i.e., not allowing to use unset variables) isn't set by default, but the script would fail if one used `set -u` somewhere else, so it's safer to catch this here.
186186
{: .solution}
187187
188188
The reason why in the example above the variable `${CMS_PATH}` is used and not simply

_episodes/02-compiling.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ questions:
66
- "How can I compile my CMSSW package using GitLab CI?"
77
- "How do I add other CMSSW packages?"
88
objectives:
9-
- "Successfully compile CMSSW example analysis code in GitLab CI"
9+
- "Successfully compile CMSSW example analysis code in GitLab CI."
1010
keypoints:
1111
- "For code to be compiled in CMSSW, it needs to reside within the work area's `src` directory."
1212
- "The analysis code from the Git repository is copied to the CMSSW work area in the CI script."
@@ -17,20 +17,20 @@ Now that you know how to get a CMSSW environment, it is time to do something use
1717
## Compiling code within the repository
1818

1919
For your analysis to be compiled with CMSSW, it needs to reside in the
20-
workarea's `src` directory, and in there follow the directory structure of
21-
two subdirectories (e.g. `AnalysisCode/MyAnalysis`) within which there can be
20+
workarea's `src` directory, and, within it, follow the directory structure of
21+
two subdirectories (e.g., `AnalysisCode/MyAnalysis`) in which there can be
2222
`src`, `interface`, `plugin` and further directories. Your analysis code
2323
(under version control in GitLab/GitHub) will usually not contain the
2424
CMSSW workarea. The git repository will either
2525
contain the analysis code at the lowest level or have a subdirectory
26-
for the analysis code, to disentangle it from your configuration files such as the
26+
for the analysis code, to disentangle it from your configuration files, such as the
2727
`.gitlab-ci.yml` file.
2828

2929
We will use an example analysis, which selects pairs of electrons and muons.
3030
[Download the zip file containing the analysis](../files/ZPeakAnalysis.zip)
3131
and extract it now. The analysis code is
3232
in a directory called `ZPeakAnalysis` within which `plugins` (the C++ code)
33-
and `test` (the python config) directories reside.
33+
and `test` (the Python config) directories reside.
3434
Add this directory to your repository:
3535

3636
~~~
@@ -43,7 +43,7 @@ git commit -m "Add ZPeakAnalysis"
4343
{: .language-bash}
4444

4545
When compiling the code in a GitLab pipeline, the `ZPeakAnalysis` needs
46-
to be copied into the CMSSW workarea, and it's advisable to use environment
46+
to be copied into the CMSSW work area, and it's advisable to use environment
4747
variables for this purpose. This would be achieved like this:
4848

4949
~~~
@@ -52,7 +52,7 @@ cp -r "${CI_PROJECT_DIR}/ZPeakAnalysis" "${CMSSW_BASE}/src/AnalysisCode/"
5252
~~~
5353
{: .language-bash}
5454

55-
With these two commands we will now be able to extend the `.gitlab-ci.yml`
55+
With these two commands, we will now be able to extend the `.gitlab-ci.yml`
5656
file such that we can compile our analysis code in GitLab. To improve the
5757
readability of the file, the `CMSSW_RELEASE` is defined as a variable:
5858

@@ -87,15 +87,15 @@ cmssw_compile:
8787

8888
> ## Always add CMSSW packages before compiling analysis code!
8989
>
90-
> Adding CMSSW packages has to happen *before* compiling analysis code in the
90+
> Adding CMSSW packages has to happen *before* compiling the analysis code in the
9191
> repository, since `git cms-addpkg` will call `git cms-init` for the
9292
> `$CMSSW_BASE/src` directory, and `git init` doesn't work if the directory
9393
> already contains files.
9494
{: .callout}
9595

9696
When developing CMSSW code, you will sometimes find yourself in the situation where you need
9797
to rebuild one of the CMSSW packages.
98-
This need can arise either from the fact you are modifying this package,
98+
This need can arise either from the fact that you are modifying this package,
9999
or from the fact that another CMSSW package depends on the one you are developing
100100
and thus needs to be rebuilt.
101101

@@ -131,7 +131,7 @@ There are a couple of options to make things work:
131131
For simplicity, and since we do not need to commit anything back to CMSSW from
132132
GitLab, we will use the latter approach.
133133
A complete `yaml` fragment that checks out a CMSSW package after having set up
134-
CMSSW and then compiles the code looks as follows:
134+
CMSSW and then compiles the code, which looks as follows:
135135

136136
~~~
137137
cmssw_addpkg:
@@ -164,17 +164,17 @@ The additional two variables that are exported here, `CMSSW_MIRROR` and
164164
`CMSSW_GIT_REFERENCE` can speed up interaction with git, in particular
165165
faster package checkouts. The `CMSSW_MIRROR` points to a GitHub mirror within the CERN network,
166166
accessible only from machines within the same network, which is the case for the GitLab runners.
167-
Settings these variables is *not* mandatory.
167+
Setting these variables is *not* mandatory.
168168

169-
> ## Bonus: have you tried putting both `cmssw_compile` and `cmssw_addpkg` in the same `.gitlab-ci.yml` file?
169+
> ## Bonus: Have you tried putting both `cmssw_compile` and `cmssw_addpkg` in the same `.gitlab-ci.yml` file?
170170
> If you do that, the two jobs will run in parallel.
171-
> GitLab CI also allows running jobs in stages. Stages define group of jobs running together.
171+
> GitLab CI also allows running jobs in stages. Stages define a group of jobs running together.
172172
> To assign a job to a stage, just add `stage: some_name` in its definition.
173173
> Stages run in sequence according to the order typically defined at the beginning of your `.gitlab-ci.yml`.
174174
> If any job in a stage fails, the next stage will not run.
175175
{: .testimonial}
176176

177-
> ## Exercise: can you put `cmssw_compile` and `cmssw_addpkg` in two stages?
177+
> ## Exercise: Can you put `cmssw_compile` and `cmssw_addpkg` in two stages?
178178
>
179179
{: .challenge}
180180

@@ -226,7 +226,7 @@ Settings these variables is *not* mandatory.
226226
> - scram b
227227
> ~~~
228228
> {: language-yaml}
229-
> In the solution above you will also notice that we have moved the definition of some variables
229+
> In the solution above, you will also notice that we have moved the definition of some variables
230230
> outside of the job definition, because they are used by both jobs.
231231
{: .solution}
232232

_episodes/03-vomsproxy.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ exercises: 15
55
questions:
66
- "How can I obtain a grid proxy in GitLab?"
77
objectives:
8-
- "Securely add grid proxy certificates and passwords to GitLab"
9-
- "Successfully obtain a grid proxy for the CMS VO"
8+
- "Securely add grid proxy certificates and passwords to GitLab."
9+
- "Successfully obtain a grid proxy for the CMS VO."
1010
keypoints:
11-
- "Special care is needed when adding secrets in GitLab"
12-
- "Passwords and certificates should always be set to `Protected` state"
13-
- "Certificates need to be `base64`-encoded for use as secrets"
11+
- "Special care is needed when adding secrets in GitLab."
12+
- "Passwords and certificates should always be set to `Protected` state."
13+
- "Certificates need to be `base64`-encoded for use as secrets."
1414
---
1515

1616
## Securely adding passwords and files to GitLab
@@ -22,24 +22,24 @@ files, which by default will reside in the `~/.globus` directory, will need
2222
to be stored in GitLab.
2323

2424
> ## Keep your secrets secret!
25-
> Please be extra careful when it comes to your account and grid passwords as
25+
> Please be extra careful when it comes to your account and grid passwords, as
2626
> well as your certificates! They should never be put in any public place.
2727
> Putting them under version control is risky, since even if you delete them
2828
> from the `HEAD` of your `master` branch, they will still be in the commit
29-
> history. Furthermore, putting them in a public, or even a private but shared
30-
> repository, is a violation of grid policy, and could lead to access being
29+
> history. Furthermore, putting them in a public or even a private but shared
30+
> repository is a violation of grid policy and could lead to access being
3131
> revoked for the offending user. Should you accidentally have put sensitive
3232
> data to a repository, please see the guides by [GitHub][removing-sensitive-github]
3333
> and [GitLab][removing-sensitive-gitlab] to
3434
> remove them (though the data should still be considered compromised).
3535
{: .callout}
3636

37-
For more information see the section on
37+
For more information, see the section on
3838
[private information/access control][lesson-gitlab-secrets]
3939
from the
4040
[Continuous Integration / Continuous Development (CI/CD)][lesson-gitlab]
41-
on how to add variables in GitLab CI/CD in general. From that lesson you will
42-
know how to add e.g. your grid proxy password. The grid certificate itself,
41+
on how to add variables in GitLab CI/CD in general. From that lesson, you will
42+
know how to add e.g., your grid proxy password. The grid certificate itself,
4343
however, consists of two files that look like this:
4444

4545
~~~
@@ -64,7 +64,7 @@ TH1s1SNT4R34lGr1DC3rt1f1C4t3But1Th4s4l3NgtH0F64CH4r4ct3rSP3rL1N3
6464
### We need more base: `base64`
6565

6666
Simply pasting them into GitLab does not work since the line breaks will not
67-
be reflected correctly. There is a trick we can play though: we can encode the
67+
be reflected correctly. There is a trick we can play, though: we can encode the
6868
files including line breaks so that they are simply a string, which we can
6969
decode to yield the same result as the input. The tool of our choice is
7070
`base64`. Let's give this a go.
@@ -73,7 +73,7 @@ decode to yield the same result as the input. The tool of our choice is
7373
>
7474
> Copy the output of the `cat ~/.globus/usercert.pem` output above into a
7575
> text file called `testcert.txt`, and pipe the content of this file to the
76-
> `base64` command or use it as input file directly (hint: `base64 --help`).
76+
> `base64` command or use it as an input file directly (hint: `base64 --help`).
7777
>
7878
{: .challenge}
7979

@@ -139,12 +139,12 @@ There are a couple of important things to keep in mind when adding passwords
139139
and certificates as variables to GitLab:
140140
141141
- Variables should always be set to `Protected` state.
142-
- As an additional safety measure, set them as `Masked` as well if possible (this will not work for the certificates but should for your grid password).
142+
- As an additional safety measure, set them as `Masked` as well if possible (this will not work for the certificates, but should for your grid password).
143143
144144
For more details, see the
145145
[GitLab CI/CD variables][gitlab-variables-advanced]
146146
of the GitLab documentation. Setting variables to `Protected` means that
147-
they are only available in protected branches, e.g. your `master` branch.
147+
they are only available in protected branches, e.g., your `master` branch.
148148
This is important when collaborating with others, since anyone with access
149149
could just `echo` the variables when making a merge request if you run
150150
automated tests on merge requests.
@@ -181,7 +181,7 @@ base64 -i ~/.globus/userkey.pem -w 0
181181
and copy the output into GitLab.
182182
183183
> ## Every equal sign counts!
184-
> Make sure to copy the full string including the trailing equal signs.
184+
> Make sure to copy the full string, including the trailing equal signs.
185185
{: .callout}
186186
187187
The `Settings` --> `CI / CD` --> `Variables` section should look like this:
@@ -242,7 +242,7 @@ voms_proxy_test:
242242
~~~
243243
{: .language-yaml}
244244
245-
You could take this further by e.g. performing a DAS query to keep your input files
245+
You could take this further, e.g., by performing a DAS query to keep your input files
246246
up-to-date.
247247
248248
Confirm that this works for you before moving on to the next section!

0 commit comments

Comments
 (0)