惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
P
Palo Alto Networks Blog
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
aimingoo的专栏
aimingoo的专栏
腾讯CDC
T
Threatpost
D
DataBreaches.Net
Vercel News
Vercel News
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
C
Cybersecurity and Infrastructure Security Agency CISA
Forbes - Security
Forbes - Security
U
Unit 42
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
O
OpenAI News
量子位
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Visual Studio Blog
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
Security Archives - TechRepublic
Security Archives - TechRepublic
The Last Watchdog
The Last Watchdog
S
Security Affairs
Attack and Defense Labs
Attack and Defense Labs
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
小众软件
小众软件
S
SegmentFault 最新的问题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 聂微东
I
Intezer
Know Your Adversary
Know Your Adversary
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
博客园_首页
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

mafeifan 的编程技术分享

mafengwo-mp3-downloader | mafeifan 的编程技术分享 示例页面 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 查看 default namespace 下的 default service account名称 mafeifan 的编程技术分享 检查日志 | mafeifan 的编程技术分享 bridge fdb show dev flannel.1 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 数据收集原理分析 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 几种方法 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 check the export on the very top of this document so we can use $do mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 延伸 -- 关于前端路由 xdebug 3 和 2 的区别
mafeifan 的编程技术分享
2026-01-16 · via mafeifan 的编程技术分享

构建任务在指定Docker镜像中进行 ​

如下面例子,首先pull一个我打包好的基于ubuntu的node镜像,这个镜像里面已经包含了nodejs10, wget, zip, curl, python,chrome,firefox, aws-cli 等常用工具,可以方便的在里面执行npm install,npm run test 启动浏览器跑测试等。

groovy

pipeline {
  agent {
    docker {
       image 'finleyma/circleci-nodejs-browser-awscli'
    }
  }
  stage('Checkout') {
       steps {
          git branch: 'develop', credentialsId: 'github-private-key', url: 'git@github.com:your-name/angular-web.git'
     }
  }
  stage('Node modules') {
     steps {
        sh 'npm install'
     }
   }
  stage('Code Lint') {
     steps {
        sh 'npm run lint'
     }
  }
  stage('Unit Test') {
    steps {
      sh 'npm run test'
    }
  }
  // .... build, delpoy
}

pipeline 中操作镜像 ​

需要安装 Jenkins docker workflow 插件, 下面的例子展示了:

  • 连接远程Docker主机
  • 登录私有Docker 仓库(阿里云镜像服务)
  • 根据代码中的 Dockerfile 构建镜像并push
  • 删除Docker远程主机中构建好的镜像,不占用空间
  • 不包含目标主机中部署镜像 其实就说上篇文章中的pipeline版本

groovy

#!groovy

pipeline {
    agent any
    
    environment {
        // PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
        _docker_remote_server='tcp://192.100.155.155:2375'
        _aliyun_registry='https://registry.cn-zhangjiakou.aliyuncs.com'
    }

    stages {
        stage('debug')  {
            steps {
                script {
                    sh "printenv"
                }
            }
        }

        stage('connect remote docker') {
            steps {
                // 注意 代码是先拉到了Jenkins主机上,但是构建镜像在Docker远程
                git 'https://github.com/mafeifan/docker-express-demo.git'

                script {
                    docker.withServer("${env._docker_remote_server}") {
                         // 第一个参数是私有仓库地址,注意要带http(s),第二个参数是账号密码登录凭证,需要提前创建
                        docker.withRegistry("${env._aliyun_registry}", 'aliyun-docker-registry') {
                            // 使用 ${GIT_PREVIOUS_COMMIT} 取不到 commint_id
                            // https://stackoverflow.com/questions/35554983/git-variables-in-jenkins-workflow-plugin
                            git_commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
                            echo git_commit
                            def customImage = docker.build("fineyma/node-demo:${env.BUILD_NUMBER}-${git_commit}")
                            /* Push the container to the custom Registry */
                            customImage.push()
                            // 可以优化,用匹配搜索并删除
                            sh "docker rmi fineyma/node-demo:${env.BUILD_NUMBER}-${git_commit}"
                        }
                    }
                }

                // clean workspace
                cleanWs()
            }
        }
    }
}

这里 customImage.push() 貌似有个bug,构建之后的镜像有两个一样的,一个带registry name一个不带

关于 docker.build, docker.withRegistry 等是Jenkins docker workflow 插件提供的, 可以看源码,其实是封装了docker build, docker login,你完全可以写原生的docker 命令

关于远程容器部署 ​

既然镜像已经成功上传到阿里云的镜像服务,理论上任何装有Docker的主机只要docker run就可以完成部署了(需要网络通)。 实现方法我想到有几种:

  1. 阿里云的镜像服务提供触发器,即每当push新的镜像上去,可以发送一个post请求到配置的地址,这样可以完成容器部署操作。Jenkins可以添加一个job,暴露一个触发地址给阿里云镜像服务的触发器。
  2. 在pipeline中添加ssh登录目标主机,然后添加 docker run --rm fineyma/node-demo:${env.BUILD_NUMBER}-${git_commit} step 步骤
  3. 目标主机也开放dockerd,这样连登录都不需要了,直接docker client 操作远程Docker完成部署。

参考 ​

https://jenkins.io/doc/pipeline/steps/docker-workflow

https://www.jenkins.io/doc/book/pipeline/docker/