Skip to content

Commit

Permalink
Finalized slides for 20220519
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasdille committed May 18, 2022
1 parent e26999c commit a7e9001
Show file tree
Hide file tree
Showing 36 changed files with 951 additions and 183 deletions.
27 changes: 23 additions & 4 deletions 160_gitlab_ci/000_rollout/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,26 @@ Portainer to manage Docker

traefik routes requests to containers

---

## Rollout 2/

Use SSH to login to you VM

```bash
ssh [email protected]
```

Clone repository with slides and demos

```bash
git clone https://github.com/nicholasdille/container-slides
```

Deploy stack

```bash
cd container-slides/160_gitlab_ci/000_rollout
docker compose \
--project-name gitlab \
up -d
Expand All @@ -30,7 +49,7 @@ Go to https://seatN.inmylab.de where seatN matches your subdomain

---

## Rollout 2/
## Rollout 3/

Wait for GitLab to be available (status is `running (healthy)`):

Expand All @@ -53,7 +72,7 @@ Login to GitLab

---

## Rollout step 3/3
## Rollout step 4/4

Connect GitLab runner

Expand Down Expand Up @@ -91,9 +110,9 @@ Containers are based on `alpine` by default

---

## Visual Studio Code
## IDE

XXX
Use the web-based Visual Studio Code

1. Go to https://vscode.seatN.inmylab.de
1. Authenticate using the user seat and your personal password
Expand Down
2 changes: 2 additions & 0 deletions 160_gitlab_ci/010_jobs_and_stages/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Jobs in the same stage are executed in parallel

![](160_gitlab_ci/010_jobs_and_stages/jobs_and_stages.drawio.svg) <!-- .element: style="width: 60%;" -->

Described in `.gitlab-ci.yml` in YAML [](https://yaml.org/)

Special stages `.pre` and `.post`

---
Expand Down
32 changes: 30 additions & 2 deletions 160_gitlab_ci/080_configuration/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@

---

## CI configuration
## CI configuration 1/

Some useful settings

### General pipelines

Git strategy is not relevant for executors like Docker and Kubernetes

Get badges for pipelines status, coverage report and the latest release

### Auto DevOps

Audo DevOps [](https://docs.gitlab.com/ee/topics/autodevops/) provides preconfigured jobs for building, testing and scanning software projects

### Runners

Connect specific runners

Disable shared runners

---

## CI configuration 2/2

More useful settings

### Deploy freezes

Prevent unintentional deployments using Deploy Freeze [](https://docs.gitlab.com/ee/user/project/releases/index.html#prevent-unintentional-releases-by-setting-a-deploy-freeze)

XXX /-/settings/ci_cd
Use `$CI_DEPLOY_FREEZE` to check for deploy freeze
2 changes: 0 additions & 2 deletions 160_gitlab_ci/100_environments/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Environments are deployment targets [](https://docs.gitlab.com/ee/ci/environment

CI variables can be scoped to environments

XXX

![](160_gitlab_ci/100_environments/webdav.drawio.svg) <!-- .element: style="width: 70%;" -->

(Hint: Environments can also be assigned using branch names)
Expand Down
3 changes: 2 additions & 1 deletion 160_gitlab_ci/110_triggers/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ test:
- ./hello

trigger:
stage: trigger
script: |
curl https://gitlab.seatN.inmylab.de/api/v4/projects/<PROJECT_ID>/trigger/pipeline \
curl https://gitlab.seat${SEAT_INDEX}.inmylab.de/api/v4/projects/<PROJECT_ID>/trigger/pipeline \
--request POST \
--fail \
-F token=<TOKEN> \
Expand Down
58 changes: 58 additions & 0 deletions 160_gitlab_ci/110_triggers/multi-project/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
stages:
- check
- build
- test
- deploy
- trigger

default:
image: golang:1.17.9

lint:
stage: check
script:
- go fmt .

audit:
stage: check
script:
- go vet .

build:
stage: build
script:
- |
go build \
-ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X 'main.Author=${AUTHOR}'" \
-o hello \
.
artifacts:
paths:
- hello

test:
stage: test
image: alpine
script:
- ./hello

deploy:
stage: deploy
environment:
name: ${CI_COMMIT_REF_NAME}
before_script:
- apt-get update
- apt-get -y install curl ca-certificates
script:
- |
curl https://${CI_COMMIT_REF_NAME}.seat${SEAT_INDEX}.inmylab.de/ \
--fail \
--verbose \
--upload-file hello \
--user admin:${PASS}
trigger:
stage: trigger
trigger:
project: <GROUP>/<PROJECT>
branch: <BRANCH>
41 changes: 41 additions & 0 deletions 160_gitlab_ci/110_triggers/parent-child/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
stages:
- check
- build
- test
- trigger

default:
image: golang:1.17.9

lint:
stage: check
script:
- go fmt .

audit:
stage: check
script:
- go vet .

build:
stage: build
script:
- |
go build \
-ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X main.Author=${AUTHOR}" \
-o hello \
.
artifacts:
paths:
- hello

test:
stage: test
image: alpine
script:
- ./hello

trigger:
stage: trigger
trigger:
include: child.yml
3 changes: 3 additions & 0 deletions 160_gitlab_ci/110_triggers/parent-child/child.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
script:
- printenv | sort
31 changes: 26 additions & 5 deletions 160_gitlab_ci/110_triggers/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,42 @@ Run additional stages and jobs from a file [](https://docs.gitlab.com/ee/ci/pipe
1. Go back to previous project
1. Add new stage and job called `trigger`
1. Add curl snippet in `script` block
1. Store `TOKEN` as CI variable [](#/gitlab_ci_variable)
1. Store `TOKEN` as unprotected but masked CI variable [<i class="fa-solid fa-arrow-right-to-bracket"></i>](#/gitlab_ci_variable)
1. Fill in `REF_NAME` with branch name (probably `main`)

(See new `.gitlab-ci.yml`)

(Pass variables using `--form "variables[NAME]=VALUE"`)

---

## Hands-On: Multi-project pipelines

XXX
1. Replace `script` with `trigger` keyword
1. Specify project and branch:

```yaml
job_name:
trigger:
project: foo/bar
branch: baz
```
1. Check pipeline
---
## Hands-On: Parent-child pipelines
XXX
1. Add `parent/child/child.yml` to first project
1. Replace project and branch in `trigger` with `include` [<i class="fa-solid fa-arrow-right-to-bracket"></i>](#/gitlab_templates)

```yaml
job_name:
trigger:
include: child.yml
```

Child pipeline can be made from multiple files

`include` supports `local` for files in the same repository

`project`/`ref`/`file` for files in other repositories
26 changes: 25 additions & 1 deletion 160_gitlab_ci/120_templates/file/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
include:
- local: go.yaml
- project: foo/template-go
ref: main
file: go.yaml

stages:
- check
- build
- test
- deploy
- trigger

default:
image: golang:1.17.9
Expand All @@ -31,3 +35,23 @@ test:
image: alpine
script:
- ./hello

deploy:
stage: deploy
environment:
name: ${CI_COMMIT_REF_NAME}
before_script:
- apt-get update
- apt-get -y install curl ca-certificates
script:
- |
curl https://${CI_COMMIT_REF_NAME}.seat${SEAT_INDEX}.inmylab.de/ \
--fail \
--verbose \
--upload-file hello \
--user admin:${PASS}
trigger:
stage: trigger
trigger:
include: child.yml
24 changes: 23 additions & 1 deletion 160_gitlab_ci/120_templates/inline/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ stages:
- check
- build
- test
- deploy
- trigger

default:
image: golang:1.17.9
Expand All @@ -20,7 +22,7 @@ audit:
script:
- |
go build \
-ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X main.Author=${AUTHOR}" \
-ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X 'main.Author=${AUTHOR}'" \
-o hello \
.
Expand All @@ -36,3 +38,23 @@ test:
image: alpine
script:
- ./hello

deploy:
stage: deploy
environment:
name: ${CI_COMMIT_REF_NAME}
before_script:
- apt-get update
- apt-get -y install curl ca-certificates
script:
- |
curl https://${CI_COMMIT_REF_NAME}.seat${SEAT_INDEX}.inmylab.de/ \
--fail \
--verbose \
--upload-file hello \
--user admin:${PASS}
trigger:
stage: trigger
trigger:
include: child.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
script:
- |
go build \
-ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X main.Author=${AUTHOR}" \
-ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X 'main.Author=${AUTHOR}'" \
-o hello \
.
13 changes: 8 additions & 5 deletions 160_gitlab_ci/120_templates/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

## Make jobs reusable

XXX include [](https://docs.gitlab.com/ee/ci/yaml/#include)
Job templates begin with a dot to prevent execution

XXX local
Templates can be imported using `include` [](https://docs.gitlab.com/ee/ci/yaml/#include) from...

XXX file
- The same `.gitlab-ci.yml`
- Files in the same repository
- Files in othe repositories of the same instance
- Remote locations

XXX remote
See also the development guide for templates [](https://docs.gitlab.com/ee/development/cicd/templates.html)

---

Expand All @@ -27,7 +30,7 @@ XXX remote
script:
- |
go build \
-ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X main.Author=${AUTHOR}" \
-ldflags "-X main.Version=${CI_COMMIT_REF_NAME} -X 'main.Author=${AUTHOR}'" \
-o hello \
.
```
Expand Down
Loading

0 comments on commit a7e9001

Please sign in to comment.