Jenkins、GitLab部署

一把梭

[root@es1 jenkins]# tree -L 2
.
├── docker-compose.yml
├── nginx
      ├── conf.d
             └── gitlab.conf
      └── nginx.conf
# nginx.conf
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    client_max_body_size 50m;
    include /etc/nginx/conf.d/*.conf;
}

stream {
    server{
        listen 2222;
        proxy_pass gitlab:22;
    }

}
# gitlab.conf
server {
  listen 80;
  server_name test.gitlab.com;

  server_tokens off;
  client_max_body_size 0;
  
 
  gzip on;
  gzip_static on;
  gzip_comp_level 2;
  gzip_http_version 1.1;
  gzip_vary on;
  gzip_disable "msie6";
  gzip_min_length 250;
  gzip_proxied no-cache no-store private expired auth;
  gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;
  
  
  add_header Referrer-Policy strict-origin-when-cross-origin;

  proxy_read_timeout      3600;
  proxy_connect_timeout   300;
  proxy_redirect          off;
  proxy_http_version 1.1;
  
  proxy_set_header Host $host:$server_port;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto http;

  location / {
    proxy_pass http://gitlab;
  }
}
version: '3'
services:                                      # 集合
  docker_jenkins:
    user: root                                 # 为了避免一些权限问题 在这我使用了root
    restart: always                            # 重启方式
    image: jenkins/jenkins:lts                 # 指定服务所使用的镜像 在这里我选择了 LTS (长期支持)
    container_name: jenkins                    # 容器名称
    environment:
      TZ: 'Asia/Shanghai'
    extra_hosts:               # 设置DNS本地域名解析
      - "test.gitlab.com:10.11.19.141"
    ports:                                     # 对外暴露的端口定义
      - 8080:8080
      - 50000:50000
    volumes:                                   # 卷挂载路径
      - $PWD/jenkins/jenkins_home/.ssh/:/root/.ssh/   # SSH 密钥
      - $PWD/jenkins/jenkins_home/:/var/jenkins_home  # 这是我们一开始创建的目录挂载到容器内的jenkins_home目录
      - /var/run/docker.sock:/var/run/docker.sock
      - /usr/bin/docker:/usr/bin/docker                # 这是为了我们可以在容器内使用docker命令
  docker_gitlab:
    image: 'gitlab/gitlab-ce:latest'
    container_name: gitlab
    restart: always
    environment:
      TZ: 'Asia/Shanghai'
      GITLAB_OMNIBUS_CONFIG: |
        external_url "http://test.gitlab.com"
        gitlab_rails['gitlab_ssh_host'] = 'test.gitlab.com'
        gitlab_rails['gitlab_shell_ssh_port'] = 2222
        gitlab_rails['time_zone'] = 'Asia/Shanghai'
        gitlab_rails['smtp_enable'] = true
        gitlab_rails['smtp_address'] = "smtp.163.com"
        gitlab_rails['smtp_port'] = 25
        gitlab_rails['smtp_user_name'] = "xxxxxx@163.com"
        gitlab_rails['smtp_password'] = "xxxxxx"
        gitlab_rails['smtp_domain'] = "smtp.163.com"
        gitlab_rails['smtp_authentication'] = "login"
        gitlab_rails['smtp_enable_starttls_auto'] = true
        gitlab_rails['smtp_tls'] = false
        gitlab_rails['gitlab_email_from'] = "xxxxxx@163.com"
    #ports:
    #  - '8000:80'
    #  - '4443:443'
    #  - '2222:22'
    expose:
      - 80
      - 443
      - 22
    volumes:
      - $PWD/gitlab/config:/etc/gitlab
      - $PWD/gitlab/data:/var/opt/gitlab
      - $PWD/gitlab/logs:/var/log/gitlab
    privileged: true
  docker_nginx:
    restart: always
    image: nginx
    container_name: nginx
    extra_hosts:               # 设置DNS本地域名解析
      - "test.gitlab.com:10.11.19.141"
    ports:
      - 80:80
      - 443:443
      - 2222:2222
    volumes:
      - $PWD/nginx/nginx.conf:/etc/nginx/nginx.conf
      - $PWD/nginx/conf.d/:/etc/nginx/conf.d
    links:
      - "docker_gitlab:gitlab"
    depends_on:
      - docker_gitlab
  webserver:
    restart: always
    image: nginx
    container_name: webserver
    ports:
      - 60080:80
    volumes:
      - $PWD/webserver/static/jenkins/dist/dist:/usr/share/nginx/html

Last updated