gitlab

29/05/2020

create a .env

PASSWORD=xxxxxx

add in docker compose

gitlab:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    container_name: gitlab
    hostname: gitlab.raphaelpiccolo.com
    environment:
        GITLAB_OMNIBUS_CONFIG: |
            external_url 'https://gitlab.raphaelpiccolo.com'
            # Add any other gitlab.rb configuration here, each on its own line
            gitlab_rails['gitlab_shell_ssh_port'] = 20022
            gitlab_rails['initial_root_password'] = '${PASSWORD}'
            nginx['listen_port'] = 80
            nginx['listen_https'] = false
            nginx['proxy_set_headers'] = {
                'X-Forwarded-Proto' => 'https',
                'X-Forwarded-Ssl' => 'on',
                'Host' => 'gitlab.raphaelpiccolo.com'
            }
    ports:
        - '20022:22'
    volumes:
        - './gitlab/config:/etc/gitlab'
        - './gitlab/logs:/var/log/gitlab'
        - './gitlab/data:/var/opt/gitlab'
    labels:
        - traefik.enable=true
        - traefik.http.routers.gitlab.rule=Host(`gitlab.raphaelpiccolo.com`)
        - traefik.http.services.gitlab.loadbalancer.server.port=80
        - traefik.http.routers.gitlab.tls.certresolver=le
        - traefik.http.routers.gitlab.entrypoints=websecure
        - traefik.http.routers.gitlab.middlewares=securityheaders

go on gitlab :
https://gitlab.raphaelpiccolo.com

user: root
password: generate on first launch

create a project

install a ssh key in settings/ssh

now you can clone/pull/push

Activate CICD

create a package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "test",
  "main": "index.js",
  "scripts": {
    "test": "mocha"
  },
  "repository": {
    "type": "git",
    "url": "http://gitlab.raphaelpiccolo.com/root/test.git"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "mocha": "^6.2.2"
  }
}

inside the project, create .gitlab-ci.yml

image: node:latest

stages:
  - build
  - test

cache:
  paths:
    - node_modules/

install_dependencies:
  stage: build
  script:
    - npm install
  artifacts:
    paths:
      - node_modules/

testing_testing:
  stage: test
  script: npm test

create .gitignore

node_modules/
*~

create test.js

var assert = require('assert');
describe('Array', function() {
    describe('#indexOf()', function() {
        it('should return -1 when the value is not present', function() {
            assert.equal([1, 2, 3].indexOf(4), -1);
        });
    });
});

create index.js

const express = require('express')
const app = express()

app.get('/', function (req, res) {
    res.send('Hello World!')
})

app.listen(3000, function () {
    console.log('Example app listening on port 3000!')
})

when you commit and push gitlab wil start the pipeline

Install the runner

gitlabrunner:
    image: gitlab/gitlab-runner:latest
    container_name: gitlabrunner
    restart: always
    volumes:
        - ./gitlab-runner/config:/etc/gitlab-runner
        - /var/run/docker.sock:/var/run/docker.sock

on gitlab :
go in settings, cicd, "install runner"
get url and token then run it once to set token and url

docker-compose run gitlabrunner register

choose the runner : docker

Raccourcis