jenkins构建+远程部署前端项目


##/bin/bash

npm config set registry https://registry.npm.taobao.org
npm install
npm run build
cd dist
rm -rf new_dist.tar.gz
tar -zcvf new_dist.tar.gz *

Publish over SSH

## /bin/bash

cd /data/jenkins-npm-demo
mkdir -p dist
rm -rf new_dist
rm -rf old_dist
mkdir new_dist
tar -zxvf new_dist.tar.gz -C ./new_dist
mv ./dist ./old_dist
mv ./new_dist ./dist

pipeline语法


sshPublisher(
  publishers: [
    sshPublisherDesc(
      configName: '192.168.7.66', 
      transfers: [
        sshTransfer(
          cleanRemote: false, 
          excludes: '', 
          execCommand: '''
            cd /data/jenkins-npm-demo
            mkdir -p dist
            rm -rf new_dist
            rm -rf old_dist
            mkdir new_dist
            tar -zxvf new_dist.tar.gz -C ./new_dist
            mv ./dist ./old_dist
            mv ./new_dist ./dist
          ''',
        execTimeout: 120000, 
        flatten: false, 
        makeEmptyDirs: false, 
        noDefaultExcludes: false, 
        patternSeparator: '[, ]+', 
        remoteDirectory: '/data/jenkins-npm-demo', 
        remoteDirectorySDF: false, 
        removePrefix: 'dist', 
        sourceFiles: 'dist/new_dist.tar.gz')], 
        usePromotionTimestamp: false, 
        useWorkspaceInPromotion: false, 
        verbose: false
      )
  ]
)

jenkins安装备忘

修改成清华镜像站

清华镜像站网址
https://mirrors.tuna.tsinghua.edu.cn/
https://www.cnblogs.com/ninefish/p/9818080.html
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
https://jenkins.pentaq.com/pluginManager/advanced


docker中运行jenkins

##/bin/bash

docker run \
  --rm \
  --name jenkins-tutorials \
  -u root \
  -p 17780:8080 \
  -v jenkins-data:/var/jenkins_home \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$HOME":/home \
  jenkinsci/blueocean

官网兼容wordpress预览文章

##nginx

    location = / {
        error_page 588 = @wordpress;
        #如果有preview参数,则返回wordpress页面
        if ($arg_preview) {
            return 588;
        }
        add_header Cache-Control "no-store";
        add_header Pragma "No-cache";
        expires -1;
        etag off;
        root /data/pentaq-weui-wap/dist;
        try_files $uri $uri/ /index.html;
    }

    location @wordpress {
        root /data/var/www/trunk/app/news;
        try_files $uri $uri/ /index.php?$args;
    }

nginx 当出现502状态时访问备用服务

先启动备用服务,再停主服务,然后更新主服务代码,最后启动主服务关闭备用服务。

达成服务无缝更新。

##nginx

    location / {
        error_page 502 = @backup;
        proxy_pass http://127.0.0.1:4000;
        proxy_redirect off;
        proxy_set_header X-Forwarded-For             $proxy_add_x_forwarded_for; 
    }
    location @backup {
        proxy_pass http://127.0.0.1:5000;
        proxy_redirect off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

gitlab的相关信息

gitlab打包了nginx, redis, postgresql, sidekiq 和 unicorn 服务。
也因此在安装gitlab的机器上你不能再独立安装nginx,你可以直接使用gitlab提供的nginx。


相关配置文件Location
/var/opt/gitlab


启动、重启命令gitlab-ctl start gitlab-ctl stop gitlab-ctl restart
更多信息gitlab-ctl status gitlab-ctl help


只重启nginxsudo gitlab-ctl restart nginx

nginx单个IP的请求频率限制、并发连接限制

全局配置 ### nginx.conf
        limit_req_zone $binary_remote_addr zone=global_req_limit:10m rate=20r/s;         limit_req zone=global_req_limit burst=100 nodelay;
        limit_conn_zone $binary_remote_addr zone=global_conn_limit:10m;         limit_conn global_conn_limit 500;

        limit_conn_zone $binary_remote_addr zone=my_conn_limit:10m;


单个服务配置
看情况限制最大并发数, 比如websock长链接
### xxx.com.conf         
location /faye {             limit_conn my_conn_limit 12;  }