Skip to content

Commit f4d1a72

Browse files
authored
Merge pull request #206 from Lemoncode/feature/gitlab-2022
gitlab 2022 files
2 parents 7158c29 + ce34cc2 commit f4d1a72

37 files changed

+1294
-0
lines changed

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

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

03-cd/02-gitlab-2022/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 = "20221128.0.0"
30+
config.vm.network "private_network", ip: "192.168.56.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 [ "python3" ]
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==2.1.0
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:15.4.4-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:alpine-v15.4.2'
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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op0Q3fD6yrT42SBnKdxEXgTqPCmuVkhM97YbLgbDE
25+
0uWV/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)