首页 > 其他分享 >application deployment by jenkinsfile and docker compose

application deployment by jenkinsfile and docker compose

时间:2023-06-04 22:23:14浏览次数:47  
标签:compose run -- application sh https docker jenkinsfile

Using Jenkins CI/CD for your NodeJS app

https://blog.harveydelaney.com/jenkins-build-test-deploy-node-app/

 

Jenkinsfile

https://github.com/internetarchive/openlibrary/blob/9b7fda26cd154239ac498e06ee513a239c233ee8/scripts/solr_builder/Jenkinsfile#L3

    stage('2: Populate solr') {
      stages {
        stage('Restart Postgres') {
          // Have to restart to because the previous workspace was destroyed on cleanup
          when { expression { return params.REUSE_POSTGRES } }
          steps {
            dir(env.HOST_SOLR_BUILDER_DIR) {
              sh(label: 'Stop the db containers',
                script: 'docker compose stop db adminer')

              sh(label: 'Start the db containers',
                script: 'docker compose up -d --no-deps db adminer')
            }
          }
        }

 

 

https://github.com/grv231/Jenkins-Docker-demo/blob/master/misc/Jenkinsfile

node {
   def git_commit_id
   def to = emailextrecipients([
        [$class: 'CulpritsRecipientProvider'],
        [$class: 'DevelopersRecipientProvider'],
        [$class: 'RequesterRecipientProvider']
  ])
   
   
   stage('Prepare') {
     checkout scm
     sh "git rev-parse --short HEAD > .git/commit-id"
     git_commit_id = readFile('.git/commit-id').trim()
   }
   
   stage('test') {
     def testContainer = docker.image('node:4.6')
     testContainer.pull()
     testContainer.inside {
       sh 'npm install --only=dev'
       sh 'npm test'
     }
   }
   
   try {
   stage('Running Tests with a Database') {
     def mysql = docker.image('mysql').run("-e MYSQL_ALLOW_EMPTY_PASSWORD=yes") 
     def testContainer = docker.image('node:4.6')
     testContainer.pull()
     testContainer.inside("--link ${mysql.id}:mysql") {
          sh 'npm install --only=dev' 
          sh 'npm test'                     
     }     
     currentBuild.result = "SUCCESS";
     mysql.stop()
    }  
   } catch (Exception err) {
     currentBuild.result = "FAILURE";
     def subject = "${env.JOB_NAME} - Build #${env.BUILD_NUMBER} ${currentBuild.result}"
     def content = '${JELLY_SCRIPT,template="html"}'
     
     if(to != null && !to.isEmpty()) {
      emailext(body: content, mimeType: 'text/html',
         replyTo: '$DEFAULT_REPLYTO', subject: subject,
         to: to, attachLog: true )
    }
   }
   
   echo "RESULT_MYSQL_JOB: ${currentBuild.result}"

   
   stage('Pushing builds in Docker hub') {            
     docker.withRegistry('https://index.docker.io/v1/', 'dockerhub') {
       def app = docker.build("grv231/nodejs-docker-jenkins-demo:${git_commit_id}", '.').push()
     }                                     
   }                                       
}                                          

 

Docker Compose Detached: Modes explained

https://bobcares.com/blog/docker-compose-detached/

A Docker Compose command, like a docker run command, launches the services in the foreground by default.

docker compose detached

 

To execute this in the background, use the vom compose-up command with the -d or we can also use the —detach option. Now let us move ahead to the main topic.

 

Docker Compose Detached

In the detachment mode or in the background, we have to  run the docker-compose up command as shown below:

 

docker-compose up -d
- or -
docker-compose up --detach

 

The preceding command launches the containers in the background and prints the new container names.

 

Run Docker Container in Background (Detached Mode)

Before starting a Docker container, you must, first of all, decide if you want to run it in the default foreground mode or in the background in a detached mode.

In the foreground mode, Docker can start the process in the container and attach the console to the process’s standard input, standard output, and standard error.

 

The disadvantage of running a container in the foreground is that you can not access the command prompt anymore, as you can see from the screenshot above. Which means you can not run any other commands while the container is running.

To run a Docker container in the background, use the use -d=true or just -d option. First, stop it from the foreground mode by pressing [Ctrl+C], then run it in a detached mode as shown:

# docker run -d --rm -p 8000:80 -p 8443:443 --name pandorafms pandorafms/pandorafms:latest

In addition, to reattach to a detached container, use docker attach command.

# docker attach --name pandorafms
OR
# docker attach 301aef99c1f3

https://docs.docker.com/engine/reference/commandline/run/

 

https://docs.docker.com/engine/reference/commandline/compose_up/

The docker compose up command aggregates the output of each container (like docker compose logs --follow does). One can optionally select a subset of services to attach to using --attach flag, or exclude some services using --no-attach to prevent output to be flooded by some verbose services.

When the command exits, all containers are stopped. Running docker compose up --detach starts the containers in the background and leaves them running.

 

nohup &

https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html#:~:text=The%20SIGHUP%28%E2%80%9Chang-up%E2%80%9D%29%20signal%20is%20used%20to%20report%20that,terminal%20to%20jobs%20associated%20with%20that%20session%3B%20this

Macro: int SIGHUP

The SIGHUP (“hang-up”) signal is used to report that the user’s terminal is disconnected, perhaps because a network or telephone connection was broken. For more information about this, see Control Modes.

This signal is also used to report the termination of the controlling process on a terminal to jobs associated with that session; this termination effectively disconnects all processes in the session from the controlling terminal. For more information, see Termination Internals.

 

https://www.cnblogs.com/yunwangjun-python-520/p/10713564.html#_label0_4

&:是指在后台运行,当用户退出(挂起)的时候,命令自动跟着结束


nohup:不挂断的运行,注意并没有后台运行的功能,就是指用nohup运行命令可以使命令永久的执行下去,和用户终端没有关系,例如我们断开SSH连接都不会影响他的运行,注意了nohup没有后台运行的意思;&才是后台运行

因此将nohup和&结合使用,就可以实现使命令永久地在后台执行的功能

 

https://zhuanlan.zhihu.com/p/380607264

后台运行转前台

既然任务可以从前台转后台,那反过来从后台转前台是否可行呢?答案是可以的 首先以后台运行run.sh

$ nohup bash  run.sh 2>&1 & 
[1] 482
nohup: ignoring input and appending output to 'nohup.out'

查看后台任务

$ jobs
[1]  + running    nohup bash run.sh 2>&1

运行fg命令,将任务从后台转到前台

$ fg %1                    
[1]  + 482 running    nohup bash run.sh 2>&1

 

标签:compose,run,--,application,sh,https,docker,jenkinsfile
From: https://www.cnblogs.com/lightsong/p/17456515.html

相关文章

  • 开启docker报错
     解决方法:开启管理员权限 ......
  • docker attach退出
    当你通过`dockerattach`连接到容器并使用`/bin/bash`启动容器时,如果你直接使用`Ctrl+C`或者输入`exit`命令来退出容器,那么容器会停止。如果你想在退出容器时保持容器继续运行,有几种方法可以实现:1.使用`Ctrl+P,Ctrl+Q`组合键:按下`Ctrl+P`和`Ctrl+Q`组......
  • Failed to start docker.service: Unit docker.service not found.
    1、卸载docker 2、添加Docker官方的GPG密钥 3、更新源 4、导入证书 5、更新 6、安装docker 7、验证是否安装成功 8、安装dockercompose 9、验证是否安装成功 ......
  • Docker安装Java, Apache, Redis, Tomcat, Postgresql, SSH
    [color=red]centos安装Supervisor[/color][url]http://www.alphadevx.com/a/455-Installing-Supervisor-and-Superlance-on-CentOS[/url]网络设定[b][color=darkblue]#创建网络brctladdbrbr0iplinksetdevbr0upipaddradd192.168.2.1/24devbr0#创建容器#......
  • nas使用docker部署导航页Heimdall
    一、下载镜像linuxserver/heimdall:latest二、创建容器文件/文件夹:此处填写在nas上事先创建好的目录位置装载路径:/config类型选读写本地端口其实用自动的就行,不与已有端口冲突即可。启动容器,检查日志是否有报错项。如没有报错,容器应该为运行中的状态。三、打开Heimdall导航页点击快......
  • Docker安装MS SQL Server并使用Navicat远程连接
    MSSQLServer简介MicrosoftSQLServer(简称SQLServer)是由微软公司开发的关系数据库管理系统,它是一个功能强大、性能卓越的企业级数据库平台,用于存储和处理大型数据集、支持高效查询和分析等操作。SQLServer支持广泛的应用程序开发接口(API),包括T-SQL、ADO.NET、ODBC、OLE......
  • 云原生之使用Docker部署TeaKKi知识文档管理工具
    (云原生之使用Docker部署TeaKKi知识文档管理工具)一、TeaKKi介绍Teakki是一款知识文档管理工具,当前支持企业本地私有化部署,免费试用有效期30天。适用于团队,企业的知识协作和管理.,为你构建团队的知识库!TeaKKi专注知识知识协作,让团队知识协作变得简单高效。二、检查docker......
  • docker安装过程
    1.下载必要的包sudoyuminstall-yyum-utilsdevice-mapper-persistent-datalvm22.指定虚拟机去哪里安装docker sudoyum-config-manager--add-repohttps://download.docker.com/linux/centos/docker-ce.repo3.安装docker  sudoyuminstalldocker-cedocker-c......
  • (五)Spring源码解析:ApplicationContext源码解析
    一、概述1.1>整体概览在前面的内容中,我们针对BeanFactory进行了深度的分析。那么,下面我们将针对BeanFactory的功能扩展类ApplicationContext进行深度的分析。ApplicationConext与BeanFactory的功能相似,都是用于向IOC中加载Bean的。由于ApplicationConext的功能是大于BeanFactory的......
  • docker安装mysql
    1.从DockerHub下载MySQL镜像:dockerpullmysql2.运行MySQL容器,并将主机的3306端口映射到容器的3306端口:dockerrun-p3306:3306--namemysql-eMYSQL_ROOT_PASSWORD=your_password-dmysql其中,--namemysql指定容器的名称为mysql,-p3306:3306将容器的3306端口映射......