|
|
|
|
|
**O runner deve estar em servidor diferente do que roda o GitLab**
|
|
|
No LabES:
|
|
|
- GitLab em gitlab.labes.inf.ufes.br
|
|
|
- Runner em dev.labes.inf.ufes.br
|
|
|
|
|
|
Docker - Instruções de instalação:
|
|
|
https://docs.docker.com/engine/install/
|
|
|
|
|
|
```shell
|
|
|
sudo apt update
|
|
|
sudo apt install ca-certificates curl gnupg lsb-release
|
|
|
sudo mkdir -p /etc/apt/keyrings
|
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
|
|
echo \
|
|
|
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
|
|
|
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
|
sudo apt update
|
|
|
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
|
sudo docker run hello-world
|
|
|
```
|
|
|
|
|
|
(O último comando é só pra testar)
|
|
|
|
|
|
GitLab Runner - Instruções de instalação:
|
|
|
https://docs.gitlab.com/runner/install/
|
|
|
|
|
|
```shell
|
|
|
curl -LJO "https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb"
|
|
|
sudo dpkg -i gitlab-runner_amd64.deb
|
|
|
```
|
|
|
|
|
|
Registro do Runner - Instruções:
|
|
|
https://docs.gitlab.com/runner/register/index.html
|
|
|
|
|
|
No GitLab, pra registrar um Shared Runner, vai em Admin Area > Overview > Runners, clica no botão _Register an instance runner_ e copia o token.
|
|
|
|
|
|
```shell
|
|
|
sudo gitlab-runner register
|
|
|
```
|
|
|
|
|
|
Siga as instruções. No meu caso: GitLab instance URL = https://gitlab.labes.inf.ufes.br. Tag obtida do GitLab. Runner executor = docker. Default image = maven:3.8-openjdk-18-slim. As demais opções em branco (default).
|
|
|
|
|
|
(Defult image = docker:stable ??)
|
|
|
(From: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-continuous-deployment-pipeline-with-gitlab-ci-cd-on-ubuntu-18-04)
|
|
|
|
|
|
----------- Implantação Contínua (CD) -----------
|
|
|
|
|
|
Adaptando de: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-continuous-deployment-pipeline-with-gitlab-ci-cd-on-ubuntu-18-04
|
|
|
|
|
|
sudo gitlab-runner register -n --url https://gitlab.labes.inf.ufes.br --registration-token <project_token> --executor docker --description "dev-labes-deployment" --docker-image "docker:latest" --tag-list deployment --docker-privileged –docker-volumes /var/run/docker.sock:/var/run/docker.sock
|
|
|
|
|
|
sudo adduser deployer
|
|
|
sudo usermod -aG docker deployer
|
|
|
su deployer
|
|
|
ssh-keygen -b 4096
|
|
|
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
|
|
|
|
|
|
Copia conteúdo de ~/.ssh/id_rsa (todo e adiciona uma quebra de linha no final) e cola em Settings > CI / CD > Variables > Add Variable:
|
|
|
- Key: ID_RSA
|
|
|
- Value <o valor>
|
|
|
- Type: File
|
|
|
- Environment Scope: All (default)
|
|
|
- Protect variable: Checked
|
|
|
- Mask variable: Unchecked
|
|
|
|
|
|
Outra variável:
|
|
|
- Key: SERVER_IP
|
|
|
- Value: <your_server_IP>
|
|
|
- Type: Variable
|
|
|
- Environment scope: All (default)
|
|
|
- Protect variable: Checked
|
|
|
- Mask variable: Checked
|
|
|
|
|
|
Mais uma:
|
|
|
- Key: SERVER_USER
|
|
|
- Value: deployer
|
|
|
- Type: Variable
|
|
|
- Environment scope: All (default)
|
|
|
- Protect variable: Checked
|
|
|
- Mask variable: Checked
|
|
|
|
|
|
Vai pro arquivo .gitlab-ci.yml e modifica conforme instruções. Antes era só o stage test, agora são especificados 3 stages. Comentários originais (removidos do arquivo):
|
|
|
|
|
|
# Based on the GitLab Maven template:
|
|
|
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Maven.gitlab-ci.yml
|
|
|
|
|
|
# Using docker images from:
|
|
|
# https://hub.docker.com/_/maven/
|
|
|
|
|
|
# For general lifecycle information see:
|
|
|
# https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
|
|
|
|
|
|
# This configures a pipeline to:
|
|
|
# * Caches downloaded dependencies and plugins between invocation;
|
|
|
# * Verify the Maven project at every commit.
|
|
|
|
|
|
# TODO:
|
|
|
# * See if other verifications can be added (e.g., a linter for code convention/formatting)
|
|
|
# * Continuous Deployment triggered when code is merged into main.
|
|
|
|
|
|
Tive que modificar conforme este comentário num bug report do GitLab por conta do docker-dind:
|
|
|
https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27300#note_571697847
|
|
|
|
|
|
Adicionei build do Maven como parte do processo, inspirado neste post:
|
|
|
https://about.gitlab.com/blog/2016/12/14/continuous-delivery-of-a-spring-boot-application-with-gitlab-ci-and-kubernetes/
|
|
|
|
|
|
Troquei o uso do docker build pelo docker-compose basedo nesse post:
|
|
|
https://medium.com/@vitalypanukhin/docker-compose-and-gitlab-b209d09210f6
|
|
|
|
|
|
Known hosts pra conectar via SSH do docker-compose:
|
|
|
https://stackoverflow.com/questions/57290734/ssh-host-key-verification-failed-inside-gitlab-ci
|
|
|
|
|
|
Docker Hub - coloquei a imagem base do WildFly JEE9 lá:
|
|
|
https://docs.docker.com/docker-hub/
|
|
|
|
|
|
----------- Hub ES+ Java no Docker -----------
|
|
|
|
|
|
Usei como base para construir o meu build personalizado:
|
|
|
https://github.com/jboss-dockerfiles/wildfly/blob/master/Dockerfile
|
|
|
https://github.com/christianmetz/wildfly-mysql/blob/master/Dockerfile
|
|
|
|
|
|
Usei como base para fazer o docker compose do WildFly com MySQL:
|
|
|
https://betterprogramming.pub/setting-up-mysql-database-in-a-docker-d6c69a3e9afe
|
|
|
|
|
|
Documentação Docker compose:
|
|
|
https://docs.docker.com/compose/
|
|
|
|
|
|
Imagens MySQL:
|
|
|
https://hub.docker.com/_/mysql
|
|
|
|
|
|
Pra desativar o JASPI:
|
|
|
https://github.com/vitorsouza/jakarta-security-example
|
|
|
https://stackoverflow.com/a/70240973/361343
|
|
|
https://github.com/wildfly/quickstart/tree/main/ee-security#configure-the-server
|
|
|
https://stackoverflow.com/questions/56060964/how-run-jboss-cli-on-start-docker-container-with-dockerfile
|
|
|
|
|
|
|