Skip to content

Commit 4edeea2

Browse files
committed
Gitlab 2021
1 parent 2c8ca8c commit 4edeea2

36 files changed

+1229
-0
lines changed

03-cd/02-gitlab-2021/README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# GitLab BOOTCAMP
2+
![](https://about.gitlab.com/images/press/logo/jpg/gitlab-logo-gray-rgb.jpg)
3+
<p align="center">
4+
<img src="https://avatars.githubusercontent.com/u/7702396?s=200&v=4">
5+
</p>
6+
7+
8+
> El entorno está preparado para funcionar tanto en docker(Recomendado) en local o con una maquina virtual vagrant
9+
## Versiones de software
10+
- Vagrant: >= 2.2.x
11+
- Docker Engine: >= 19
12+
- [Docker Compose >= 1.27.4](https://docs.docker.com/compose/install/)
13+
- VirtualBox >= 6.x
14+
15+
## Creación del entorno
16+
1. Permitimos registry inseguro a docker
17+
* En Linux En el fichero /etc/docker/daemon.json
18+
```
19+
{"insecure-registries" : ["gitlab.local:5001"]}
20+
```
21+
* En windows lo hacemos via Docker Desktop
22+
23+
2a. Preparando el entorno con docker(Linux y windows).
24+
>> Es necesario permisos sudo (Linux) o Administrador(Windows)
25+
```bash
26+
user@localhost:~$ cd 02-gitlab/gitlab/docker/
27+
user@localhost:~02-gitlab/$ sudo chmod +x build_gitlab_docker.sh && sudo ./build_gitlab_docker.sh
28+
```
29+
2b. Preparando el entorno con Vagrant y Virtualbox
30+
```bash
31+
user@localhost:~$ cd 02-gitlab/
32+
user@localhost:~02-gitlab/$ sudo vagrant up
33+
```
34+
3. Añadimos entrada al fichero hosts la entrada -> <Direccion_ip_local> gitlab.local
35+
* Linux en el fichero /etc/hosts
36+
* Windows en el fichero c:\windows\system32\drivers\etc\hosts
37+
38+
39+
## Un poco de arquitectura
40+
41+
- Gitlab
42+
![](https://docs.gitlab.com/ee/development/img/architecture_simplified.png)
43+
- Gitlab Runner(https://docs.gitlab.com/runner/#runner-execution-flow)
44+
- Gitlab Runner Executors(https://docs.gitlab.com/runner/executors/)
45+
- CI FLOW ![](https://docs.gitlab.com/ee/development/cicd/img/ci_architecture.png)
46+
## ¿Qué vamos a aprender?
47+
1. Conceptos Gitlab
48+
- ¿Qué es Gitlab?
49+
- ¿Qué es un runner?
50+
- ¿Qué es un pipeline?
51+
2. Gestión de Usuarios
52+
- Alta de usuarios
53+
- Impersonate
54+
- SSH Keys
55+
- Access Token
56+
3. Gestión de proyectos(repositorios)
57+
- Miembros del proyecto
58+
- Deploy Tokens
59+
- Deploy Keys
60+
- Protected Branches
61+
- Protected TAGS
62+
4. Entendiendo los pipelines
63+
- Conceptos de Pipeline
64+
- ¿Qué es un pipeline?
65+
- ¿Como se define?
66+
- ¿Cuando se ejecuta?
67+
- ¿Qué es un stage?
68+
- ¿Qué es un Job?
69+
- Herramientas para crear pipelines
70+
- Web IDE
71+
- LINT
72+
- PipeLine Editor
73+
- Estructura básica
74+
- image
75+
- job
76+
- stage
77+
- script
78+
- before_script
79+
- Variables de grupo, proyecto y pipeline
80+
- Variables predefinidas
81+
- Usando variables
82+
- Orden de precedencia
83+
- Casos de uso
84+
- Control sobre los pipelines
85+
- Condicionales when y only
86+
- Condicionales avanzados con rules
87+
- Control de errores
88+
- Artifacts
89+
- ¿Qué es un artifact?
90+
- ¿Para que lo usamos?
91+
- Casos de uso
92+
- Environments
93+
- ¿Qué es un environment?
94+
- ¿Para que lo usamos?
95+
- Redeploy
96+
- Rollback
97+
- Workflows
98+
5. Creacion de pipelines de build,test y deploy
99+
6. Uso de container registry
100+
- ¿Qué es un container registry?
101+
- Repositando nuestra imágenes
102+
8. Pipelines de creación de imagenes Base
103+
9. Usar nuestras Imágenes
104+
10. Gitlab Pages
105+
11. Bonus
106+
- Releases
107+
- Optimizando pipelines con Templates
108+
- Triggers
109+
110+
111+
## Cheatsheet
112+
### [Variables Predefinidas](http://gitlab.local:8888/help/ci/variables/predefined_variables.md)
113+
### [Referencia configuración de pipeline](http://gitlab.local:8888/help/ci/yaml/index)
114+
115+
## Información usada en la Clase
116+
### Gestion de Usuarios
117+
- User: **root**, Pass: **Gitl@bPass** , Access Level: **Admin** (Usuario ya creado)
118+
- User: **developer1**, Pass: **dev€loper1** , Access Level: **Regular**
119+
- User: **developer2**, Pass: **dev€loper2** , Access Level: **Regular**
120+
### [Roles]( http://gitlab.local:8888/help/user/permissions)
121+
- Guest
122+
- Reporter
123+
- Developer
124+
- Maintainer
125+
- Owner
126+
### [Visibilidad de grupos y proyectos](http://gitlab.local:8888/help/public_access/public_access.md)
127+
- **Private**: El grupo y sus proyectos sólo pueden ser vistos por los miembros.
128+
- **Internal**: El grupo y los proyectos internos pueden ser vistos por cualquier usuario conectado, excepto los usuarios externos.
129+
- **Public**: El grupo y los proyectos públicos pueden verse sin necesidad de autenticación.
130+
131+
132+
133+

03-cd/02-gitlab-2021/Vagrantfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
$install_docker = <<-SCRIPT
4+
apt-get update
5+
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
6+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
7+
apt-key fingerprint 0EBFCD88
8+
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
9+
apt-get update
10+
apt-get install docker-ce=5:20.10.11~3-0~ubuntu-focal docker-ce-cli=5:20.10.11~3-0~ubuntu-focal containerd.io -y
11+
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
12+
chmod +x /usr/local/bin/docker-compose
13+
14+
SCRIPT
15+
16+
$configure_docker = <<-SCRIPT
17+
echo '{"insecure-registries" : ["gitlab.local:5001"]}' > /etc/docker/daemon.json
18+
sed -i "/ExecStart/ s/$/ -H tcp:\\/\\\/0.0.0.0:2375/" /lib/systemd/system/docker.service && systemctl daemon-reload && systemctl restart docker
19+
echo "172.40.0.2 gitlab.local" >> /etc/hosts
20+
SCRIPT
21+
22+
23+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
24+
# configures the configuration version (we support older styles for
25+
# backwards compatibility). Please don't change it unless you know what
26+
# you're doing.
27+
Vagrant.configure("2") do |config|
28+
config.vm.box = "ubuntu/focal64"
29+
config.vm.box_version = "20211026.0.0"
30+
config.vm.network "private_network", ip: "192.168.10.150"
31+
config.vm.hostname = "bootcampVM"
32+
#config.vagrant.plugins = ["vagrant-vbguest"]
33+
config.vm.provider "virtualbox" do |vb|
34+
vb.name = "bootcampVM"
35+
vb.memory = "6144"
36+
vb.cpus = 4
37+
end
38+
# add swap
39+
config.vm.provision :shell, inline: "fallocate -l 4G /swapfile && chmod 0600 /swapfile && mkswap /swapfile && swapon /swapfile && echo '/swapfile none swap sw 0 0' >> /etc/fstab"
40+
config.vm.provision :shell, inline: "echo vm.swappiness = 10 >> /etc/sysctl.conf && echo vm.vfs_cache_pressure = 50 >> /etc/sysctl.conf && sysctl -p"
41+
config.vm.provision "file", source: "gitlab", destination: "$HOME/"
42+
config.vm.provision "shell", inline: $install_docker
43+
config.vm.provision "shell", inline: $configure_docker
44+
config.vm.provision "shell", inline: "cd gitlab/docker; docker-compose up -d"
45+
config.vm.provision "shell", inline: "cd gitlab/docker; /bin/bash runner_register.sh"
46+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# Run docker-compose
3+
docker-compose -f gitlab/docker/docker-compose.yml up -d
4+
5+
#Auto register runner to gitlab
6+
/bin/bash gitlab/docker/runner_register.sh
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:3.8-slim
2+
MAINTAINER Sergio Ramírez "sergio@localhost"
3+
COPY ./requirements.txt /app/requirements.txt
4+
WORKDIR /app
5+
RUN pip install -r requirements.txt
6+
COPY bootcamp.py /app/
7+
ENTRYPOINT [ "python" ]
8+
CMD [ "bootcamp.py" ]
9+
EXPOSE 8080
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from flask import Flask
2+
app = Flask(__name__)
3+
4+
@app.route("/")
5+
def welcome():
6+
return "Welcome to Gitlab Bootcamp!!!!"
7+
8+
if __name__ == "__main__":
9+
app.run(host='0.0.0.0',port=8080)
10+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Flask==1.1.2
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
version: "3.8"
2+
services:
3+
gitlab:
4+
image: 'gitlab/gitlab-ee:14.2.6-ee.0'
5+
restart: always
6+
hostname: 'gitlab'
7+
container_name: gitlab
8+
environment:
9+
GITLAB_OMNIBUS_CONFIG: |
10+
external_url 'http://gitlab.local:8888'
11+
registry_external_url 'http://gitlab.local:5001'
12+
gitlab_rails['registry_enabled'] = true
13+
registry['enable'] = true
14+
pages_external_url "http://gitlab.local:8888"
15+
gitlab_pages['enable'] = true
16+
gitlab_pages['inplace_chroot'] = true
17+
gitlab_rails['initial_root_password'] = 'Gitl@bPass'
18+
ports:
19+
- '8888:8888'
20+
- '8443:8443'
21+
- '2222:22'
22+
- '5001:5001'
23+
volumes:
24+
- 'gitlab-config:/etc/gitlab'
25+
- 'gitlab-logs:/var/log/gitlab'
26+
- 'gitlab-data:/var/opt/gitlab'
27+
networks:
28+
bootcamp_network:
29+
ipv4_address: 172.40.0.2
30+
extra_hosts:
31+
- "gitlab.local:172.40.0.2"
32+
gitlabrunner:
33+
image: 'gitlab/gitlab-runner:v14.2.0'
34+
container_name: gitlab-runner
35+
depends_on:
36+
- gitlab
37+
restart: always
38+
volumes:
39+
- '/var/run/docker.sock:/var/run/docker.sock'
40+
- 'gitlab-runner-config:/etc/gitlab-runner'
41+
networks:
42+
bootcamp_network:
43+
ipv4_address: 172.40.0.3
44+
extra_hosts:
45+
- "gitlab.local:172.40.0.2"
46+
portainer:
47+
image: portainer/portainer-ce
48+
restart: always
49+
container_name: portainer
50+
ports:
51+
- '9000:9000'
52+
volumes:
53+
- '/var/run/docker.sock:/var/run/docker.sock'
54+
- 'portainer_data:/data'
55+
volumes:
56+
gitlab-config:
57+
gitlab-data:
58+
gitlab-logs:
59+
gitlab-runner-config:
60+
portainer_data:
61+
networks:
62+
bootcamp_network:
63+
name: bootcamp_network
64+
ipam:
65+
driver: default
66+
config:
67+
- subnet: 172.40.0.0/24
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN OPENSSH PRIVATE KEY-----
2+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
3+
NhAAAAAwEAAQAAAQEA1/f6aOABW5L2WS7/DtX3AFbfmRzxNm+qqm8B19WvTIB0S0A48Oky
4+
5m7MtoN5jvPiDGgS8KdnXaYx8l82dIzP2bk1s1saA9Z9dkIQzjFBF7p8c7OUB5c/mgLfG7
5+
qvjS3dUXRIBb3Qn/5b1IphJZAgbzitvQdvNidxsPtFJtFkeYz5jGq6WXgPNXVIcUvUjRQm
6+
M7gmIL2TyV65Qpyg4Y93W2RXBTevVrqLCBj6xjrTwviKHfxmbsKYvyEx8+TCrVyXl8L3Cl
7+
jRFyRbjKBAFLrgwiQJ69unurq35ryai1RX+joPNoQipW05WDhWwfOHXxmgmNvUdJoqvlHd
8+
MauPGv124QAAA8iZtBYTmbQWEwAAAAdzc2gtcnNhAAABAQDX9/po4AFbkvZZLv8O1fcAVt
9+
+ZHPE2b6qqbwHX1a9MgHRLQDjw6TLmbsy2g3mO8+IMaBLwp2ddpjHyXzZ0jM/ZuTWzWxoD
10+
1n12QhDOMUEXunxzs5QHlz+aAt8buq+NL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WV/P99RgTitNQb8YeDfW/5ZkT8lyC8+mrWD2NQ90QUzr0DrCF5t/sWfXCDqOFD/zOk48
26+
yL4LrTX0dZ42IocAAAARZW1haWxAZXhhbXBsZS5jb20BAg==
27+
-----END OPENSSH PRIVATE KEY-----
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash -x
2+
3+
# Redirect all stdout and stderr to mytest.log
4+
exec > /tmp/runner_register.log 2>&1
5+
6+
while ! curl -f -LI localhost:8888;do echo sleeping; sleep 5;done;
7+
echo Connected!;
8+
export gitlab_id=$(sudo docker ps --filter "name=^gitlab$" --format "{{.ID}}")
9+
export runner_token=$(docker exec -i $gitlab_id /opt/gitlab/bin/gitlab-rails runner -e production "puts Gitlab::CurrentSettings.current_application_settings.runners_registration_token")
10+
export runner_id=$(docker ps --filter "name=^gitlab-runner$" --format "{{.ID}}")
11+
docker exec -i $runner_id gitlab-runner register --non-interactive --url "http://gitlab.local:8888/" --registration-token $runner_token --executor "docker" --docker-image docker:20.10 --description "docker-runner" --docker-volumes /var/run/docker.sock:/var/run/docker.sock --tag-list "docker" --run-untagged="true" --locked="false" --access-level="not_protected" --env "DOCKER_DRIVER=overlay2" --env "DOCKER_TLS_CERTDIR=" --docker-privileged --docker-network-mode "bootcamp_network" --docker-extra-hosts "gitlab.local:172.40.0.2" --docker-pull-policy if-not-present

0 commit comments

Comments
 (0)