zoukankan      html  css  js  c++  java
  • docker+jenkins自动发布步骤及命令

    docker images

    docker container ls

    docker ps

    docker stop

    docker rm

    docker push rd-server:5000/ubuntu

    停止并删除容器

    docker stop pid && docker rm -v pid

    删除tag

    docker rmi -f hub.doge.com/ubuntu:latest

    openssl生成证书

    在home下创建auth目录和certs目录

    openssl genrsa -out dockerreg.cg.glodon.com.key 2048

    openssl req -newkey rsa:4096 -nodes -sha256 -key dockerreg.cg.glodon.com.key -x509 -days 3650 -out dockerreg.cg.glodon.com.crt

    拷贝证书给docker

    cp ~/certs/dockerreg.cg.glodon.com.crt /etc/docker/certs.d/dockerreg.cg.glodon.com/

    客户端安装证书

    把crt文件拷贝到客户端的相同位置,如果不行就用下面的渔具执行以下

    cat 证书名.crt >>/etc/pki/tls/certs/ca-bundle.crt

    设置注册中心用户名密码

    docker run --entrypoint htpasswd registry:2 -Bbn 用户名 密码  >> htpasswd 

    注册中心启动

    docker run -d

      --restart=always

      --name registry

      -v `pwd`/auth:/auth

      -e "REGISTRY_AUTH=htpasswd"

      -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm"

      -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd

      -v `pwd`/certs:/certs

      -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/dockerreg.cg.glodon.com.crt

      -e REGISTRY_HTTP_TLS_KEY=/certs/dockerreg.cg.glodon.com.key

      -p 443:5000

      registry:2

    运行centos

    docker run -i -t centos:7 /bin/bash

    进入容器

    docker exec -i -t pid /bin/bash

    登录私服

    docker login dockerreg.cg.glodon.com:443

    向私服中注册image

    docker tag image的pid dockerreg.cg.glodon.com:443/centos:7.3.1611

    基础Dockerfile

    FROM dockerreg.cg.glodon.com:443/centos:7.3.1611

    MAINTAINER fanc

    ADD apache-tomcat-8.0.46.tar.gz /usr/local/tomcat

    ADD jdk-8u111-linux-x64.gz /usr/local/java/

    ENV JAVA_HOME /usr/local/java/jdk-8u111-linux-x64/

    ENV JAVA_OPTS -Xms512m -Xmx1024m -XX:MaxNewSize=512m -XX:MaxPermSize=1024m

    EXPOSE 8080

    CMD /usr/local/tomcat/apache-tomcat-8.0.46/bin/catalina.sh run

    构建基础image

    docker build -t centos7jdk8tomcat8 .

    运行

    docker run --name centos7jdk8tomcat8 centos7jdk8tomcat8:latest

    项目Dockerfile

    FROM dockerreg.cg.glodon.com:443/centos7jdk8tomcat8:latest

    MAINTAINER fanc

    COPY project/target/gjc-buyer-web-6.0.0-SNAPSHOT/ /usr/local/tomcat/apache-tomcat-8.0.46/webapps/cg/

    COPY project/deploy/ /usr/local/deploy/

    COPY project/deploy/alpha/ /usr/local/tomcat/apache-tomcat-8.0.46/webapps/cg/

    COPY project/deploy/alpha/Tomcat/ /usr/local/tomcat/apache-tomcat-8.0.46/

    RUN rm -rf /usr/local/tomcat/apache-tomcat-8.0.46/webapps/cg/Tomcat

    RUN mkdir -p /home/upload/gjc6/gjc_upload

    jenkins打包后的shell

    #!/bin/bash

    dockerfiledir="/root/fanc_docker/gjc6-buyer"

    project="gjc6-buyer"

    projectdir="project"

    uploaddir="/home/upload/gjc6/gjc_upload"

    workspace="/root/.jenkins/workspace/gjc6.0-buyer/gjc-buyer-web"

    date=`date +%Y%m%d%H%M`

    pid=`docker container ls -a | grep $project | awk '{print $1}'`

    docker stop $pid && docker rm -v $pid

    cd $dockerfiledir

    if [ ! -d "$projectdir" ]; then

    mkdir $projectdir

    else

    rm -rf $projectdir

    mkdir $projectdir

    fi

    if [ ! -d "$uploaddir" ]; then

    mkdir -p $uploaddir

    fi

    cp -rf $workspace/* $projectdir/

    docker login -u fanc -p 111111 dockerreg.cg.glodon.com:443

    docker build -t $project:$date .

    docker run -p 85:8080 -v $uploaddir:$uploaddir --restart always --name $project $project:$date &

    正式环境Dockerfile

    FROM gjc6-buyer:201708291622

    MAINTAINER fanc

    RUN cp -rf /usr/local/deploy/release/. /usr/local/tomcat/apache-tomcat-8.0.46/webapps/cg/

    RUN cp -rf /usr/local/deploy/release/Tomcat/. /usr/local/tomcat/apache-tomcat-8.0.46/

    RUN rm -rf /usr/local/tomcat/apache-tomcat-8.0.46/webapps/cg/Tomcat

    正式镜像打包shell

    #!/bin/bash

    dockerfiledir="/root/fanc_docker/gjc6-buyer-release"

    project="gjc6-buyer"

    date=`date +%Y%m%d%H%M`

    docker login -u fanc -p 111111 dockerreg.cg.glodon.com:443

    docker build -t $project:release-$date .

    pid=`docker images | grep $project | grep release-$date | awk '{print $3}'`

    docker tag $pid dockerreg.cg.glodon.com:443/$project

    docker push dockerreg.cg.glodon.com:443/$project

    正式环境下载镜像shell

    #!/bin/bash

    project="gjc6-buyer"

    uploaddir="/home/upload/gjc6/gjc_upload"

    pid=`docker container ls -a | grep $project | awk '{print $1}'`

    docker stop $pid && docker rm -v $pid

    docker login -u fanc -p 111111 dockerreg.cg.glodon.com:443

    docker pull dockerreg.cg.glodon.com:443/$project

    if [ ! -d "$uploaddir" ]; then

    mkdir -p $uploaddir

    fi

    docker run -d -p 85:8080 -v $uploaddir:$uploaddir --restart always --name $project dockerreg.cg.glodon.com:443/$project

    SVN同步批处理脚本

    @echo off

    setlocal enabledelayedexpansion

    echo %date% %time%

    for /f %%i in (project.txt) do (

    set url=%%i

    set path_old=!url:http://server-code/GJC/GJC/=!

    set path=repo!path_old:/=!

    echo delete path

    if exist !path!_temp (

    rmdir /S /Q !path!_temp

    )

    echo checkout !url!

    "C:Program FilesVisualSVN Serverinsvn.exe" export -r HEAD !url! !path!_temp -q --username fanc

    if exist !path! (

    "C:Program FilesVisualSVN Serverinsvn.exe" update -r HEAD !path! -q --username fanc

    del /Q /F /A:-H !path!*.*

    for /d %%j in (!path!*) do rd /S /Q "%%j"

    ) else (

    "C:Program FilesVisualSVN Serverinsvn.exe" checkout -r HEAD https://192.168.8.152:8443/svn/GJC/!path_old! !path! -q --username fanc

    )

    "C:WindowsSystem32xcopy.exe" !path!_temp !path! /Y /Q /S /E /H

    "C:Program FilesVisualSVN Serverinsvn.exe" add !path!* -q --force --username fanc

    "C:Program FilesVisualSVN Serverinsvn.exe" commit !path! -q --username fanc --message commit

    echo success!

    )

  • 相关阅读:
    泛型
    Math类
    Static关键字
    Java最新面试问答整理
    Jenkins显示语言切换为中文(最终解决办法)
    eclipse中导入SVN项目步骤
    Xshell连接不上虚拟机Linux系统
    SQLYog执行SQL脚本提示:错误代码: 1067
    Web应用三种部署方式的优缺点
    web应用配置虚拟路径映射方式一配置不成功问题解决办法
  • 原文地址:https://www.cnblogs.com/xiaoQ0725/p/8482001.html
Copyright © 2011-2022 走看看