Integración Contínua
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594809/ci-0.png)
![](https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/GitLab_Logo.svg/245px-GitLab_Logo.svg.png)
![](https://jarisafi.files.wordpress.com/2018/01/docker.png?w=336)
Gitlab CI/CD
![](https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/GitLab_Logo.svg/245px-GitLab_Logo.svg.png)
![](https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/GitLab_Logo.svg/245px-GitLab_Logo.svg.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5618353/cicd_pipeline_infograph-1.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5618350/cicd_pipeline_infograph-2.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5618352/cicd_pipeline_infograph-3.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5618351/cicd_pipeline_infograph-4.png)
Planificación
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594808/ci-1.png)
Planificación
En la Planificación se deben incluir los casos de Test
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594808/ci-1.png)
- Necesito un lugar en donde si yo entro mi nombre, me diga 'Hola' más el nombre que le dí.
Planificación
- ¿Y si no le paso nombre?
- No sé... que diga 'Persona sin Nombre'
- Listo
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594808/ci-1.png)
(ejemplo burdo)
Planificación
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5140371/Screenshot_20180727_151336.png)
Text
Text
Se crea el Issue en Gitlab
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594808/ci-1.png)
(ejemplo burdo)
var chai = require('chai'),
chaiHttp = require('chai-http'),
server = require('../src/index'),
expect = chai.expect;
chai.use(chaiHttp);
after(()=>{
server.close();
})
describe('GET /greet', () => {
it('debería decir Hola Todos', (done)=>{
chai.request(server)
.get('/greet')
.query({name: 'Todos'})
.end((err, res)=>{
expect(res).to.have.status(200);
expect(res.text).to.equal('Hola Todos');
done();
});
});
it('debería decir Hola Persona sin Nombre', (done)=>{
chai.request(server)
.get('/greet')
.end((err, res)=>{
expect(res).to.have.status(400);
expect(res.text).to.equal('Hola Persona sin Nombre');
done();
});
});
});
Planificación
~/test/issue-1.js
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594808/ci-1.png)
(ejemplo burdo)
Desarrollo
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594807/ci-2.png)
Desarrollo
Cuando se crea proyecto en Gitlab, se asignan "runners"
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5140376/Screenshot_20180727_152012.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594807/ci-2.png)
Desarrollo
var express = require('express'),
app = express(app);
app.get('/greet', function(req, res, next) {
res.set('Content-Type', 'text/plain');
if(req.query.name) {
return res.send('Hola '+req.query.name);
}
res.status(400).send('Hola Persona sin Nombre');
});
module.exports = app.listen(80);
index.js
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594807/ci-2.png)
Desarrollo
Dockerfile
FROM node:9-alpine
ARG STAGE=production
ENV NODE_ENV=${STAGE}
RUN mkdir /opt/project
WORKDIR /opt/project
COPY package.json package.json
RUN npm install
COPY src/ src/
COPY test/ test/
CMD ["npm", "start"]
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594807/ci-2.png)
Desarrollo
.gitlab-ci.yml
image: docker:stable
variables:
# When using dind service we need to instruct docker, to talk with the
# daemon started inside of the service. The daemon is available with
# a network connection instead of the default /var/run/docker.sock socket.
#
# The 'docker' hostname is the alias of the service container as described at
# https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services
#
# Note that if you're using Kubernetes executor, the variable should be set to
# tcp://localhost:2375 because of how Kubernetes executor connects services
# to the job container
DOCKER_HOST: tcp://docker:2375/
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
DOCKER_DRIVER: overlay2
services:
- name: docker:dind
command: ["--insecure-registry=hub.psi.unc.edu.ar"]
stages:
- test
- release
- deploy
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594807/ci-2.png)
Test
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594806/ci-3.png)
Test
.gitlab-ci.yml
stages:
- test
- release
- deploy
test:
stage: test
script:
- docker build -t integracion-ci --build-arg STAGE=development .
- docker run integracion-ci npm test
sast:
stage: test
allow_failure: true
script:
- VERSION=$(echo $CI_SERVER_VERSION|sed 's/\.[^.]*$//'|sed 's/\./-/g')-stable
- docker pull registry.gitlab.com/gitlab-org/security-products/sast:${VERSION:-latest}
- docker run -v "$PWD":/code -v /var/run/docker.sock:/var/run/docker.sock
registry.gitlab.com/gitlab-org/security-products/sast:${VERSION:-latest} /app/bin/run /code
artifacts:
paths: [gl-sast-report.json]
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594806/ci-3.png)
Test
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594806/ci-3.png)
Algunos tests incluidos en Gitlab:
- Code Quality
- Static Application Security Testing (SAST)
- Dependency Scanning
- Vulnerability Static Analysis for containers
- Dynamic Application Security Testing (DAST)
- Browser Performance Testing
Release
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594803/ci-4.png)
Release
.gitlab-ci.yml
stages:
- test
- release
- deploy
...
hub:
stage: release
script:
- docker build -t hub.psi.unc.edu.ar/prueba/integracion-ci:latest
-t hub.psi.unc.edu.ar/prueba/integracion-ci:$CI_COMMIT_TAG .
- docker push hub.psi.unc.edu.ar/prueba/integracion-ci:latest
- docker push hub.psi.unc.edu.ar/prueba/integracion-ci:$CI_COMMIT_TAG
only:
- tags
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594803/ci-4.png)
Deploy
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594805/ci-5.png)
Deploy
.gitlab-ci.yml
staging:
stage: deploy
image: cdrx/rancher-gitlab-deploy
script:
- upgrade --create --environment dev
--rancher-url $RANCHER_URL
--rancher-secret=$RANCHER_SECRET_KEY
--rancher-key=$RANCHER_ACCESS_KEY
--new-image hub.psi.unc.edu.ar/prueba/integracion-ci:$CI_COMMIT_TAG
only:
- tags
production:
stage: deploy
image: cdrx/rancher-gitlab-deploy
script:
- upgrade --create --environment prod
--rancher-url $RANCHER_PROD_URL
--rancher-secret=$RANCHER_PROD_SECRET_KEY
--rancher-key=$RANCHER_PROD_ACCESS_KEY
--new-image hub.psi.unc.edu.ar/prueba/integracion-ci:$CI_COMMIT_TAG
when: manual
only:
- tags
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594805/ci-5.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598705/ci.gif)
Gitlab
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5151526/Screenshot_20180802_142344.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598705/ci.gif)
Gitlab
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598429/Screenshot_20181212_135146.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598705/ci.gif)
Gitlab
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5151735/Screenshot_20180802_153636.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598705/ci.gif)
Gitlab
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5151755/Screenshot_20180802_154427.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598705/ci.gif)
Rancher
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598557/Screenshot_20181212_142714.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598705/ci.gif)
Monitoreo
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594809/ci-0.png)
Monitoreo
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598485/Screenshot_20181212_140909.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5594809/ci-0.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598536/1_k5mUP1KpgcmDS1YGmT0sCQ.png)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598545/kibana.png)
Preguntas
![](https://s3.amazonaws.com/media-p.slid.es/uploads/371782/images/5598773/preguntas.png)
Integración Contínua
By Agustin Moyano
Integración Contínua
- 504