zoukankan      html  css  js  c++  java
  • 部署代码review和CI

    公司原先搭了一个代码Review的服务器,由于历史原因,装的是一个32bit的Ubuntu系统,后来由于需要,需要安装gitlab,由于gitlab需要64位系统,所以临时凑合了个vagrant,本质就是一个纯粹的虚拟机,感觉不爽,这两天终于抽出时间来重新整理了一下。基于Ubuntu 18.04 x64版本和Docker来部署,减少后面换机器换系统可能导致的重复安装工作。

    Docker安装

    Docker安装还是比较简单的。

    $ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    $ sudo apt-key fingerprint 0EBFCD88 # should have something output, key 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
    $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    $ sudo apt-get update
    $ sudo apt-get install docker-ce docker-ce-cli containerd.io
    $ sudo usermod -aG docker $USER  # 执行完重新登录,后面就可以不用sudo执行docker命令了。
    

    gitlab转移

    gitlab转移还是比较方便的,gitlab本身就提供各个版本的docker镜像,gitlab转移必须要在同一个版本之间,下载该版本对应的docker镜像,以daemon方式运行:

    $ docker run --detach --publish 192.168.30.102:443:443 --publish 192.168.30.102:80:80 --publish 8222:22 --restart always --volume /home/gitlab/config:/etc/gitlab --volume /home/gitlab/logs:/var/log/gitlab --volume /home/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:9.5.4-ce.0
    

    按照Backing up and restoring GitLab指导,对于Omnibus Package方式的安装,只要在源机器端执行:

    $ sudo gitlab-rake gitlab:backup:create
    

    在/var/opt/gitlab/backups/下找到备份文件,复制到目标机器的/home/gitlab/data/backups/下。注意:这个步骤同时复制源机器的“/etc/gitlab/gitlab-secrets.json”到目标机器对应目录“/home/gitlab/config”下

    进入docker机器,执行恢复:

    gitlab-ctl stop unicorn
    gitlab-ctl stop sidekiq
    gitlab-rake gitlab:backup:restore BACKUP=ts_yyyy_mm_dd_ver
    gitlab-ctl status
    gitlab-ctl restart
    gitlab-rake gitlab:check SANITIZE=true
    

    提示一切成功。如果“gitlab-secrets.json”在执行gitlab:backup:restore前没有复制到目标机,恢复的时候可能会提示出错。 ts_yyyy_mm_dd_ver是指gitlab生成的备份文件,文件名最后的“_gitlab_backup.tar”不需要输入。访问“http://192.168.30.102”,一切如旧,数据转移成功。

    Phabricator转移

    由于这个有一定的特殊要求,比较合适的“fauria/lamp”映像,php是7.0的,不符合phabricator的要求,所以基于“fauria/lamp”的Dockerfile和“ubuntu 18.04”镜像,自己build了一个,Dockerfile如下:

    FROM ubuntu:18.04
    MAINTAINER zhuhongbing<hongbingzhu@gmail.com>
    LABEL Description="My own LAMP stack, based on Ubuntu 18.04 LTS. Based on fauria/docker-lamp." 
            License="Apache License 2.0" 
            Usage="docker run -d ..." 
            Version="1.0"
    
    RUN apt-get update
    RUN apt-get upgrade -y
    
    ENV DEBIAN_FRONTEND noninteractive
    ENV ALLOW_OVERRIDE All
    ENV DATE_TIMEZONE UTC
    ENV TERM xterm
    
    RUN apt-get install mysql-server php apache2 libapache2-mod-php -y
    RUN apt-get install php-mysql php-gd php-curl php-apcu php-cli php-json php-mbstring -y
    RUN apt-get install git vim curl ftp -y
    RUN apt-get install python-pygments subversion -y
    
    COPY index.php /var/www/html/
    COPY run-lamp.sh /usr/sbin/
    
    RUN a2enmod rewrite
    RUN chmod +x /usr/sbin/run-lamp.sh
    RUN chown -R www-data:www-data /var/www/html
    
    VOLUME /mnt/host
    
    EXPOSE 80
    EXPOSE 443
    
    CMD ["/usr/sbin/run-lamp.sh"]
    

    这里需要注意的是ENV命令,这个会影响build的过程和最终映像运行的。里面的TERM原先是“dumb”,这个会导致vim界面异常,如果基于Ubuntu,测试设置为xterm是比较好的。也是服务器版ubuntu的缺省设置。

    Phabricator要求的组件在定制版docker里面基本都就绪了,所以后面基本上在运行的容器中执行数据恢复就行了。

    phabricator/ $ ./bin/storage dump | gzip > backup.sql.gz # 源机器
    $ gunzip -c backup.sql.gz | mysql # 目标机器
    

    同时注意恢复文件“phabricator/conf/local/local.json”。 注意:phabricator的190418版本,似乎恢复完毕以后,需要先开一下phd,才能正常访问,比较坑。折腾了好久。以前版本的phabricator邮件很好配置,更新版本之后,邮件始终折腾不成功了,比较坑,谁有经验告诉我一下。配置如下:

      "metamta.default-address": "phabricator@byhx-china.com",
      "cluster.mailers": [
        {
          "key": "smtp-mailer",
          "type": "smtp",
          "options": {
            "host": "mail.my-company.com",
            "port": 25,
            "user": "phabricator@my-company.com",
            "password": "my-account-pwd",
            "message-id": false
          }
        }
      ],
    

    编译服务器

    编译服务器主要用于从代码服务器抓取代码版本并编译,主要是做交叉编译,比较坑的是“/etc/hosts”文件,这个文件运行的时候会自动重新生成,见 /etc/hosts file of a docker container gets overwritten里面指向的discussion Allow customization of /etc/hosts, /etc/resolv.conf, etc. in containers #2267。简而言之,就是需要在运行docker的时候增加参数“–add-host=”<name_host>:<ip_host>"”来解决。

  • 相关阅读:
    Centos7下部署两套python版本并存环境的操作记录
    JSON格式化输出和解析工具
    利用阿里云的源yum方式安装Mongodb
    Ansible配置及常用模块总结
    VMware/KVM/OpenStack虚拟化之网络模式总结
    Mac下通过VMware Fusion安装centos虚拟机操作记录
    Supervisor (进程管理利器) 使用说明
    zabbix中配置当memory剩余不足20%时触发报警
    分布式监控系统Zabbix-3.0.3--短信报警设置
    linux下用户操作记录审计环境的部署记录
  • 原文地址:https://www.cnblogs.com/dabbler/p/10754570.html
Copyright © 2011-2022 走看看