Skip to content

Commit b5c7de9

Browse files
committed
Final content for first day of 20231130/20231207
1 parent 58291c2 commit b5c7de9

File tree

32 files changed

+418
-244
lines changed

32 files changed

+418
-244
lines changed

160_gitlab_ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ nav:
8989
- GitLab: 000_rollout/exercise_gitlab.md
9090
- IDE: 000_rollout/exercise_ide.md
9191
- Project: 000_rollout/exercise_project.md
92+
- You are ready: you_are_ready.md
9293
- Basics:
9394
- Jobs and Stages: 010_jobs_and_stages/exercise.md
9495
- Variables: 020_variables/exercise.md
@@ -97,6 +98,7 @@ nav:
9798
- Defaults: 050_defaults/exercise.md
9899
- Artifacts: 060_artifacts/exercise.md
99100
- Job Dependencies: 065_job_dependencies/exercise.md
101+
- Schedules: 070_schedules/exercise.md
100102
- Unit Tests: 090_unit_tests/exercise.md
101103
- Advanced:
102104
- Environments: 100_environments/exercise.md

160_gitlab_ci/000_rollout/exercise_project.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Your instance of Visual Studio Code is provisioned with your credentials to allo
99

1010
## Task 2: Pulling from the upstream repository
1111

12-
XXX
12+
The local clone of the `demo` project is configured with a remote pointing to the location of [the original project on GitHub](https://github.com/nicholasdille/container-slides). This is prepared in case the instructor needs to fix a demo. Let's test this safeguard:
1313

1414
1. Open a terminal
1515
1. Change to the `demo` project directory
1616
1. List remotes: `git remote -v`
17-
1. Pull from the upstream repository: `git pull upstream --all`
17+
1. Pull from the upstream repository: `git pull upstream`

160_gitlab_ci/000_rollout/slides.md

+4-54
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,10 @@
66

77
---
88

9-
## GitLab
9+
## Environment
1010

11-
Deploy a containerized stack for this workshop
11+
Containerized service stack for this workshop
1212

13-
![](160_gitlab_ci/000_rollout/stack.drawio.svg) <!-- .element: style="width: 95%" -->
13+
![](160_gitlab_ci/000_rollout/stack.drawio.svg) <!-- .element: style="width: 90%; margin-top: 1em;" -->
1414

15-
Obviously GitLab <i class="fa-duotone fa-face-smile-wink fa-duotone-colors"></i>
16-
17-
traefik routes requests to containers
18-
19-
---
20-
21-
## Problems with credentials
22-
23-
If your credentials are not working:
24-
25-
1. Go to https://code.inmylab.de
26-
1. Click on "Show username and password"
27-
1. Authenticate using the user `seat` and your code
28-
29-
The code was provided as part of your credentials:
30-
31-
```plaintext
32-
code;hostname;username;password
33-
ABCDE;seatN.inmylab.de;seatN;0123456789abcdef0123456789abcdef
34-
```
35-
36-
OR
37-
38-
```plaintext
39-
Host seatN.vscode.inmylab.de
40-
User seatN
41-
Code ABCDE
42-
Password 0123456789abcdef0123456789abcdef
43-
```
44-
45-
---
46-
47-
## Code
48-
49-
The source for the slides as well as the demos are located in my repository called [container-slides](https://github.com/nicholasdille/container-slides)
50-
51-
Please refer to the release matching the date of your workshop
52-
53-
You should use the release tag to access the files in the repository
54-
55-
The hands-on chapters have a link to the exact directory in the repository
56-
57-
### Demos tell a story
58-
59-
Demos focus on a single feature
60-
61-
Each demo improves the previous state
62-
63-
All demos will have unanswered questions
64-
65-
Following demos will again improve
15+
See [introduction](/hands-on/2023-11-30/)

160_gitlab_ci/010_jobs_and_stages/exercise.md

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
112112
Both jobs `lint` and `audit` must be in the stage `check`.
113113

114114
??? example "Solution (Click if you are stuck)"
115+
`.gitlab-ci.yml`:
116+
115117
```yaml linenums="1" hl_lines="5-17"
116118
stages:
117119
- check

160_gitlab_ci/020_variables/ci.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ Available in project-, group- and instance-level
1010

1111
Careful with protected variables
1212

13-
---
14-
15-
## Hands-On
13+
### Hands-On
1614

1715
See chapter [Variables](/hands-on/20231130/020_variables/exercise/)
1816

160_gitlab_ci/020_variables/exercise.md

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
3030
2. Replace the build command with the one provided above
3131

3232
??? example "Solution (Click if you are stuck)"
33+
`.gitlab-ci.yml`:
34+
3335
```yaml linenums="1" hl_lines="21-22 26-30"
3436
stages:
3537
- check
@@ -79,6 +81,8 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
7981
2. Replace the variable `${version}` with the predefined variable `${CI_COMMIT_REF_NAME}`
8082

8183
??? example "Solution (Click if you are stuck)"
84+
`.gitlab-ci.yml`:
85+
8286
```yaml linenums="1" hl_lines="25-28"
8387
stages:
8488
- check
@@ -137,6 +141,8 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
137141
The `-ldflags` option needs to be extended with `-X 'main.Author=${AUTHOR}'`
138142

139143
??? example "Solution (Click if you are stuck)"
144+
`.gitlab-ci.yml`:
145+
140146
```yaml linenums="1" hl_lines="25-28"
141147
stages:
142148
- check
@@ -172,3 +178,7 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
172178
If you want to jump to the solution, execute the following command:
173179

174180
git checkout origin/160_gitlab_ci/020_variables/ci -- '*'
181+
182+
<!-- TODO: masked variables -->
183+
184+
<!-- TODO: protected variables -->

160_gitlab_ci/020_variables/slides.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ Variables [](https://docs.gitlab.com/ee/ci/yaml/#variables) can be...
1414
- predefined by GitLab
1515
- defined in the UI
1616

17-
---
18-
19-
## Hands-On
17+
### Hands-On
2018

2119
See chapter [Variables](/hands-on/20231130/020_variables/exercise/)

160_gitlab_ci/030_script_blocks/exercise.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
1818
Move calls to `apk` to the `before_script`.
1919

2020
??? example "Solution (Click if you are stuck)"
21+
`.gitlab-ci.yml`:
22+
2123
```yaml linenums="1" hl_lines="7-9 15-17 23-25"
2224
stages:
2325
- check

160_gitlab_ci/040_image/exercise.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
Learn how to...
55

66
- specify which container image to use for a job
7-
- XXX
7+
- tailor the execution environment to your needs
88

99
## Task: Simplify using container images
1010

1111
In the previous exampes, we called `apk` at the beginning of every job to install Go. This had to be repeated for every job because Go was not present. Choosing an image for a job using the `image` directive, time is saved by avoiding commands to install required tools. See the [official documentation](https://docs.gitlab.com/ee/ci/yaml/#image).
1212

1313
Replace the calls to `apk` with the container image `golang:1.19.2`.
1414

15-
XXX version bump for `golang` image
16-
1715
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run.
1816

1917
??? info "Hint (Click if you are stuck)"
2018
- Remove `before_script`
2119
- Add `image: golang:1.19.2` instead
2220

2321
??? example "Solution (Click if you are stuck)"
22+
`.gitlab-ci.yml`:
23+
2424
```yaml linenums="1" hl_lines="7 13 19"
2525
stages:
2626
- check

160_gitlab_ci/040_image/slides.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ Do not use community images
1818

1919
Avoid maintaining custom image
2020

21-
---
22-
23-
## Hands-On
21+
### Hands-On
2422

2523
See chapter [Variables](/hands-on/20231130/040_image/exercise/)

160_gitlab_ci/050_defaults/exercise.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
!!! tip "Goal"
44
Learn how to...
55

6-
- Avoid repetition in jobs
7-
- Specify defaults are the top of your pipeline
6+
- avoid repetition in jobs
7+
- specify defaults are the top of your pipeline
88

99
## Task: Don't repeat yourself
1010

@@ -19,6 +19,8 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
1919
1. Add `default` with the `image` directive at the top
2020

2121
??? example "Solution (Click if you are stuck)"
22+
`.gitlab-ci.yml`:
23+
2224
```yaml linenums="1" hl_lines="5-6"
2325
stages:
2426
- check
@@ -63,4 +65,7 @@ Jobs can still choose to use an image different from the default:
6365

6466
## Bonus 2: Default values for variables
6567

66-
XXX `variables` outside `default`
68+
See the official documentation for [`default`](https://docs.gitlab.com/ee/ci/yaml/#default) as well as [`variables`](https://docs.gitlab.com/ee/ci/yaml/#variables) and check how they are related.
69+
70+
??? example "Solution (Click if you are stuck)"
71+
Global variables are not located under `default` but under the global `variables` keyword.

160_gitlab_ci/050_defaults/slides.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Apply settings to all jobs using `default` [](https://docs.gitlab.com/ee/ci/yaml
1717
- `after_script`
1818
- and some more we will explore later <i class="fa-duotone fa-face-smile-halo fa-duotone-colors"></i>
1919

20-
---
21-
22-
## Hands-On
20+
### Hands-On
2321

2422
See chapter [Variables](/hands-on/20231130/050_defaults/exercise/)

160_gitlab_ci/060_artifacts/exercise.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
3131
```
3232

3333
??? example "Solution (Click if you are stuck)"
34+
`.gitlab-ci.yml`:
35+
3436
```yaml linenums="1" hl_lines="4 27-35"
3537
stages:
3638
- check
@@ -75,11 +77,13 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
7577

7678
## Bonus 1: Define from which jobs to receive artifacts
7779

78-
Usually, artifacts are received from all job in the previous stages. Decide from which jobs to receive artifacts using the `dependencies` directive. See the [official documentation](https://docs.gitlab.com/ee/ci/yaml/#dependencies).
80+
Usually, artifacts are received from all jobs in the previous stages. Decide from which jobs to receive artifacts using the `dependencies` keyword. See the [official documentation](https://docs.gitlab.com/ee/ci/yaml/#dependencies).
7981

80-
XXX
82+
Modify the job `test` to consume artifacts only from the job `build`.
8183

8284
??? example "Solution (Click if you are stuck)"
85+
`.gitlab-ci.yml`:
86+
8387
```yaml linenums="1" hl_lines="34-35"
8488
stages:
8589
- check
@@ -122,7 +126,9 @@ XXX
122126

123127
## Bonus 2: Passing environment variables
124128

125-
XXX https://docs.gitlab.com/ee/ci/variables/index.html#pass-an-environment-variable-to-another-job
129+
In some situations, artifacts are to heavy-weight and passing a variable would be enough. Read the documentation for [passing environment variables](https://docs.gitlab.com/ee/ci/variables/index.html#pass-an-environment-variable-to-another-job) and implement this between two jobs of your choice.
130+
131+
The following hint and solution are a working example.
126132

127133
??? info "Hint (Click if you are stuck)"
128134
Example for creating an artifact for environment variables:
@@ -137,6 +143,8 @@ XXX https://docs.gitlab.com/ee/ci/variables/index.html#pass-an-environment-varia
137143
```
138144

139145
??? example "Solution (Click if you are stuck)"
146+
`.gitlab-ci.yml`:
147+
140148
```yaml linenums="1" hl_lines="21-22 27 29 33-34 40"
141149
stages:
142150
- check

160_gitlab_ci/060_artifacts/slides.md

-54
Original file line numberDiff line numberDiff line change
@@ -63,60 +63,6 @@ See GitLab API [](https://docs.gitlab.com/ee/api/job_artifacts.html#download-the
6363

6464
---
6565

66-
## Job dependencies using `needs` 1/
67-
68-
`needs` [](https://docs.gitlab.com/ee/ci/yaml/#needs) can start jobs from the next stage early...
69-
70-
```yaml
71-
job1:
72-
stage: stage1
73-
#...
74-
job2:
75-
stage: stage2
76-
needs: job1
77-
#...
78-
```
79-
80-
...or delay them in the same stage
81-
82-
```yaml
83-
job1:
84-
stage: test
85-
#...
86-
job2:
87-
stage: test
88-
needs: job1
89-
#...
90-
```
91-
92-
---
93-
94-
## Job dependencies using `needs` 2/2
95-
96-
Depend on a job but do not consume artifacts [](https://docs.gitlab.com/ee/ci/yaml/#needsartifacts):
97-
98-
```yaml
99-
job_name:
100-
#...
101-
102-
job_name2:
103-
needs:
104-
job: job_name
105-
artifacts: false
106-
```
107-
108-
Consume artifacts from parent (upstream) pipeline [](https://docs.gitlab.com/ee/ci/yaml/#needspipelinejob):
109-
110-
```yaml
111-
job_name:
112-
script: cat artifact.txt
113-
needs:
114-
- pipeline: $PARENT_PIPELINE_ID
115-
job: create-artifact
116-
```
117-
118-
---
119-
12066
## Pro tip: When variables are enough
12167

12268
Passing variables between jobs **is** possible (since GitLab 12.9)

160_gitlab_ci/065_job_dependencies/exercise.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
!!! tip "Goal"
44
Learn how to...
55

6-
- XXX
6+
- ignore stages
7+
- start jobs as soon as dependencies are met
78

8-
## Task: Start the build job early
9+
## Task: Start a job early
910

10-
XXX start `build` after `audit` without waiting for `lint`
11+
Start the job `build` as soon as the job `audit` completes without waiting for other job of the stage `check` to finish. Check out the official documentation of [`needs`](https://docs.gitlab.com/ee/ci/yaml/#needs).
1112

1213
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run.
1314

14-
??? info "Hint (Click if you are stuck)"
15-
XXX
16-
1715
??? example "Solution (Click if you are stuck)"
16+
`.gitlab-ci.yml`:
17+
1818
```yaml linenums="1" hl_lines="21-22"
1919
stages:
2020
- check
@@ -57,16 +57,15 @@ Afterwards check the pipeline in the GitLab UI. You should see a successful pipe
5757

5858
This was just a demonstration. The changes will not be preserved in the following chapters.
5959

60-
## Bonus: Start the lint job late
60+
## Bonus: Start a job late
6161

62-
XXX start `lint` after `audit`
62+
If two jobs in the same stage should not be executed at the same time, the [`needs`](https://docs.gitlab.com/ee/ci/yaml/#needs) keyword can also delay a job until the dependencies are met. Modify the job `lint` so that it waits for the job `audit` to finish.
6363

6464
Afterwards check the pipeline in the GitLab UI. You should see a successful pipeline run.
6565

66-
??? info "Hint (Click if you are stuck)"
67-
XXX
68-
6966
??? example "Solution (Click if you are stuck)"
67+
`.gitlab-ci.yml`:
68+
7069
```yaml linenums="1" hl_lines="11-12"
7170
stages:
7271
- check

0 commit comments

Comments
 (0)