Skip to content

Commit 68f7783

Browse files
authored
Merge pull request #14 from Lemoncode/feature/gitlab
Feature/gitlab
2 parents e9baafc + 2f1501f commit 68f7783

34 files changed

+951
-0
lines changed

03-cd/02-gitlab/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# GitLab BOOTCAMP
2+
![](https://about.gitlab.com/images/press/logo/jpg/gitlab-logo-gray-rgb.jpg)
3+
4+
> El entorno está preparado para funcionar tanto en docker(Recomendado) en local o con una maquina virtual vagrant
5+
## Versiones de software
6+
- Vagrant: >= 2.2.x
7+
- Docker Engine: >= 19
8+
- [Docker Compose >= 1.27.4](https://docs.docker.com/compose/install/)
9+
- VirtualBox >= 6.x
10+
11+
## Creación del entorno
12+
1. Permitimos registry inseguro a docker
13+
* En Linux En el fichero /etc/docker/daemon.json
14+
```
15+
{"insecure-registries" : ["gitlab.local:5001"]}
16+
```
17+
* En windows lo hacemos via Docker Desktop
18+
19+
2a. Preparando el entorno con docker(Linux y windows).
20+
>> Es necesario permisos sudo (Linux) o Administrador(Windows)
21+
```bash
22+
user@localhost:~$ cd 02-gitlab/gitlab/docker/
23+
user@localhost:~02-gitlab/gitlab/docker$ sudo docker-compose up -d
24+
```
25+
2b. Preparando el entorno con Vagrant y Virtualbox
26+
```bash
27+
user@localhost:~$ cd 02-gitlab/
28+
user@localhost:~02-gitlab/$ sudo vagrant up
29+
```
30+
3. Añadimos entrada al fichero hosts la entrada -> <Direccion_ip_local> gitlab.local
31+
* Linux en el fichero /etc/hosts
32+
* Windows en el fichero c:\windows\system32\drivers\etc\hosts
33+
34+
35+
## Enlaces de documentación necesaria
36+
- [¿Què es gitlab?](https://about.gitlab.com/)
37+
- [Un poco de arquitectura](https://docs.gitlab.com/ee/development/img/architecture_simplified.png)
38+
39+
## ¿Qué vamos a aprender?
40+
- Gestion de Usuarios
41+
- Gestión de proyectos(repositorios)
42+
- Entendiendo los pipelines
43+
- Creacion de pipelines de build,test y deploy
44+
- Uso de container registry
45+
- Pipelines de creación de imagenes Base
46+
- Usar nuestras Imágenes
47+
- Gitlab Pages
48+
49+
## Cheatsheet
50+
### [Variables Predefinidas](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)
51+
### [Referencia configuración de pipeline](https://docs.gitlab.com/ce/ci/yaml/)
52+
53+
## Guía de Clase
54+
1. Nuestro primer acceso con Gitlab
55+
2. Damos de alta un usuario sin role de administrador
56+
3. Creamos nuestro primer grupo para contener los proyectos de la bootcamp
57+
4. Creamos nuestro primer repositorio hola_mundo con el user creado
58+
5. Creamos nuestro primer pipeline en el repositorio hola_mundo
59+
- Creamos el branch develop
60+
- ¿Cuando se ejecuta un pipeline? ¿Un commit, un merge, manual? ¿y en que branch? ¿AutoDevOps? Vaya lio!
61+
- Conociendo LINT y Web IDE
62+
- Estructura básica de un pipeline con Hola Mundo
63+
- Mostrando las variables predefinidias
64+
- Control sobre que branch se ejecuta cada job
65+
- Merge Request
66+
- ¿y si falla un job? ¿Se puede puede omitir el fallo?
67+
- ¿y un Environment qué es? ¿Para que sirve?
68+
- ¿Se puede hacer un redeploy?
69+
- La hemos liado! Necesito un rollback!
70+
6. El juego de las variables de grupo, proyecto y pipeline
71+
7. Nuestra primera aplicación en flask
72+
- Como se hace un build de una app en docker
73+
- Deploy
74+
- Redeploy de la aplicación
75+
- Rollback de la aplicación
76+
8. Ejemplo de aplicación spring con tests
77+
9. Conatiner Registry
78+
- Creando nuestras propias imágenes base
79+
- usando nuestras propias imágenes base
80+
10. Gitlab Pages
81+
82+
83+
84+

03-cd/02-gitlab/Vagrantfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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:19.03.13~3-0~ubuntu-focal docker-ce-cli=5:19.03.13~3-0~ubuntu-focal containerd.io -y
11+
curl -L "https://github.com/docker/compose/releases/download/1.27.4/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 = "20201112.1.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+
end

03-cd/02-gitlab/flaskapp/Dockerfile

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

03-cd/02-gitlab/flaskapp/bootcamp.py

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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
version: "3.8"
2+
services:
3+
gitlab:
4+
image: 'gitlab/gitlab-ce:13.6.2-ce.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+
ports:
18+
- '8888:8888'
19+
- '8443:8443'
20+
- '2222:22'
21+
- '5001:5001'
22+
volumes:
23+
- 'gitlab-config:/etc/gitlab'
24+
- 'gitlab-logs:/var/log/gitlab'
25+
- 'gitlab-data:/var/opt/gitlab'
26+
networks:
27+
bootcamp_network:
28+
ipv4_address: 172.40.0.2
29+
extra_hosts:
30+
- "gitlab.local:172.40.0.2"
31+
gitlabrunner:
32+
image: 'gitlab/gitlab-runner:v13.6.0'
33+
container_name: gitlab-runner
34+
depends_on:
35+
- gitlab
36+
restart: always
37+
volumes:
38+
- '/var/run/docker.sock:/var/run/docker.sock'
39+
- 'gitlab-runner-config:/etc/gitlab-runner'
40+
networks:
41+
bootcamp_network:
42+
ipv4_address: 172.40.0.3
43+
extra_hosts:
44+
- "gitlab.local:172.40.0.2"
45+
portainer:
46+
image: portainer/portainer-ce
47+
restart: always
48+
container_name: portainer
49+
ports:
50+
- '9000:9000'
51+
volumes:
52+
- '/var/run/docker.sock:/var/run/docker.sock'
53+
- 'portainer_data:/data'
54+
volumes:
55+
gitlab-config:
56+
gitlab-data:
57+
gitlab-logs:
58+
gitlab-runner-config:
59+
portainer_data:
60+
networks:
61+
bootcamp_network:
62+
name: bootcamp_network
63+
ipam:
64+
driver: default
65+
config:
66+
- subnet: 172.40.0.0/24

03-cd/02-gitlab/gitlab/docker/id_rsa

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+
M7gmIL2TyV65Qpyg4Y93W2RXBTevVrqLCBj6xjrTwviK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feAAAAgQD5VO+lSXtlvgtDIJOMbpxtZdWuUpUw07VWjQYUvvmXcSEIP3fTSX4l
22+
CZUme6R0savFQo0J+5d25bMaiAejH5aYtiErFo+c18V82G1lKLbZ8FWqFdb22MD+Ta2iyK
23+
UtcBDr7DVpiwCtotjDaG0Jt7yBpZqt2+M8YRXTUVIUzMotVwAAAIEA3b6enwuJXdb8CQQC
24+
0/bd/FB3j6tTu51iyIJ209aeGGAetop0Q3fD6yrT42SBnKdxEXgTqPCmuVkhM97YbLgbDE
25+
0uWV/P99RgTitNQb8YeDfW/5ZkT8lyC8+mrWD2NQ90QUzr0DrCF5t/sWfXCDqOFD/zOk48
26+
yL4LrTX0dZ42IocAAAARZW1haWxAZXhhbXBsZS5jb20BAg==
27+
-----END OPENSSH PRIVATE KEY-----
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDX9/po4AFbkvZZLv8O1fcAVt+ZHPE2b6qqbwHX1a9MgHRLQDjw6TLmbsy2g3mO8+IMaBLwp2ddpjHyXzZ0jM/ZuTWzWxoD1n12QhDOMUEXunxzs5QHlz+aAt8buq+NLd1RdEgFvdCf/lvUimElkCBvOK29B282J3Gw+0Um0WR5jPmMarpZeA81dUhxS9SNFCYzuCYgvZPJXrlCnKDhj3dbZFcFN69WuosIGPrGOtPC+Iod/GZuwpi/ITHz5MKtXJeXwvcKWNEXJFuMoEAUuuDCJAnr26e6urfmvJqLVFf6Og82hCKlbTlYOFbB84dfGaCY29R0miq+Ud0xq48a/Xbh email@example.com
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash -x
2+
3+
# Redirect all stdout and stderr to mytest.log
4+
exec > mytest.log 2>&1
5+
while ! curl -f -LI localhost:8888;do echo sleeping; sleep 5;done;
6+
echo Connected!;
7+
export gitlab_id=$(sudo docker ps --filter "name=^gitlab$" --format "{{.ID}}")
8+
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")
9+
export runner_id=$(docker ps --filter "name=^gitlab-runner$" --format "{{.ID}}")
10+
docker exec -i $runner_id gitlab-runner register --non-interactive --url "http://gitlab.local:8888/" --registration-token $runner_token --executor "docker" --docker-image docker:19.03.13 --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)