docker-compose CD

还是看一下docker-compose.yml

version: '3.2'

services:

  mysql:
    #build: ./docker-cmdb/mysql
    #image: mysql_db
    image: mysql/mysql-server:5.7
    container_name: mysql-cmdb
    expose:
      - "3306"
    volumes:
    #  - ./docker-cmdb/data/mysql/data:/var/lib/mysql
      - ./docker-cmdb/mysql/init:/docker-entrypoint-initdb.d/
      - ./docker-cmdb/mysql/data:/var/lib/mysql
    networks:
      - jumpserver-test
    environment:
      MYSQL_ROOT_PASSWORD: QFedu123!

  redis:
    build: ./docker-cmdb/redis
    container_name: redis-cmdb
    expose:
      - "6379"
    restart: always
    volumes:
      - ./docker-cmdb/data/redis/data:/var/lib/redis
    networks:
      - jumpserver-test
   
  
  nginx:
    image: nginx:alpine3.8
   # build: ./docker-cmdb/nginx
    restart: always
    container_name: nginx-cmdb
    ports:
      - "9090:80"
    networks:
      - jumpserver-test
    volumes:
       - ./docker-cmdb/nginx/conf.d:/etc/nginx/conf.d
       - ./docker-cmdb/nginx/allstatic:/allstatic
    depends_on:
       - cmdb    

  rabbitmq:
     image: rabbitmq_rabbitmq 
     #build: ./docker-cmdb/rabbitmq
     container_name: rabbitmq-cmdb
     expose: 
       - "5672"
     networks: 
       - jumpserver-test
     volumes:
       - ./docker-cmdb/data/rabbitmq/data:/var/lib/rabbitmq

  cmdb:
    build: ./docker-cmdb/cmdb
    container_name: cmdb-server
    expose:
      - "8000"
    tty: true
    restart: always
    networks:
      - jumpserver-test
    volumes:
      - ./docker-cmdb/cmdb/auth_cmdb:/opt/auth_cmdb
    depends_on:
      - mysql
      - redis
      - rabbitmq
    command:
      - /bin/bash
      - -c 
      - | 
        cd /opt/auth_cmdb
        pip3 install uwsgi
        python3 manage.py makemigrations
        python3 manage.py migrate
        uwsgi --ini /opt/auth_cmdb/conf/auth_cmdb.ini

  gitlab:
    image: gitlab-ce:1.0
    restart: always
    hostname: 'gitlab.xiaodai.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://10.0.122.178:80'
        unicorn['worker_timeout'] = 60
        unicorn['worker_processes'] = 3 # worker进程数
        unicorn['worker_memory_limit_min'] = "200 * 1 << 20" # worker最小内存
        unicorn['worker_memory_limit_max'] = "300 * 1 << 20"  # worker最大内存
        sidekiq['concurrency'] = 10
        postgresql['shared_buffers'] = "128MB"
        postgresql['max_worker_processes'] = 8
    networks:
      - jumpserver-test
    ports:
      - '9280:80'
    volumes:
      - './gitlab/config:/etc/gitlab'
      - './gitlab/logs:/var/log/gitlab'
      - './gitlab/data:/var/opt/gitlab'

  jenkins:
    image: jenkinsci/blueocean
    restart: always
    privileged: true
    user: root
    volumes:
      - type: bind
        source: ./jenkins/jenkins_home
        target: /var/jenkins_home
      - type: bind
        source: /var/run/docker/docker.sock
        target: /var/run/docker.sock
        read_only: "yes"
    networks:
      - jumpserver-test
    ports:
      - "9980:8080"
    
networks:
  jumpserver-test:

通过docker-compose.yml启动后的容器


image.png

进入到容器 auth_cmdb_jenkins_1

加密方式因版本原因需下面指令

ssh-keygen -t rsa -b 4096 -m PEM

进入到装项目的容器充当应用服务器中把ssh服务开启
在jenkins的容器

ssh-copy-id  
实现jenkins与应用服务器免密登录

jenkins上配置 在系统配置

image.png

配置新建任务 和只之前ci一样 加了如下步骤


image.png

修改了服务后git上去 、jenkins去拉取版本然后发送到远程应用服务器上 服务不停的时候直接更新


image.png

容器中的目录变化


image.png

你可能感兴趣的:(docker-compose CD)