devops-jenkins

Jenkins

安装说明

安装docker 配置docker信任私库 见Harbor


mkdir -p ~/jenkins/jenkins_home
mkdir -p ~/jenkins/build_tools
chmod -R 777 ~/jenkins

docker run \
  -u root \
  -d \
  --restart always \
  -p 80:8080 \
  -p 50000:50000 \
  -v ~/jenkins/jenkins_home:/var/jenkins_home \
  -v ~/jenkins/build_tools:/var/build_tools \
  -v /etc/localtime:/etc/localtime \
  -v /var/run/docker.sock:/var/run/docker.sock \
  jenkinsci/blueocean

配置镜像
vi ~/jenkins/jenkins_home/hudson.model.UpdateCenter.xm

<?xml version='1.1' encoding='UTF-8'?>
<sites>
  <site>
    <id>default</id>
    <url>https://mirrors.cloud.tencent.com/jenkins/updates/update-center.json</url>
  </site>
</sites>

重启
docker restart 93285fbca5c0

访问 192.168.44.23
默认密码
cat ~/jenkins/jenkins_home/secrets/initialAdminPassword

-下载openjdk8 nodejs14.19 maven3.8

image

image

  • 配置凭据

image

Jenkins新建流水线项目

image

image

Springboot-Maven项目

  • pom
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>dockerfile-maven-plugin</artifactId>
            <version>1.4.13</version>
            <configuration>
                <repository>${project.artifactId}</repository>
                <!--<tag>${project.version}</tag>-->
                <buildArgs>
                    <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                </buildArgs>
            </configuration>
        </plugin>
    </plugins>
</build>
  • Dockerfile
FROM openjdk:8-jdk-alpine
ENV LANG en_US.UTF-8
RUN echo "http://mirrors.aliyun.com/alpine/v3.6/main" > /etc/apk/repositories \
    && echo "http://mirrors.aliyun.com/alpine/v3.6/community" >> /etc/apk/repositories \
    && apk update upgrade \
    && apk add --no-cache procps unzip curl bash tzdata \
    && apk add ttf-dejavu \
    && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone
ARG JAR_FILE
ADD ${JAR_FILE} /app.jar
ENTRYPOINT ["java", "-jar","/app.jar", "--spring.profiles.active=prod"]
EXPOSE 8101
  • Jenkinsfile
//gitlab的凭证
def git_auth = "gitlab"
//项目名称
def project_name = "spring-boot-case-ci"
//构建版本的名称
def tag = "latest"
//Harbor私服地址
def harbor_url = "192.168.44.22"
//Harbor的项目名称
def harbor_project_name = "test"
//Harbor的凭证
def harbor_auth = "harbor"

node {
    stage('git pull') {
        checkout([
            $class: 'GitSCM',
            branches: [[name: "*/${branch}"]],
            doGenerateSubmoduleConfigurations: false,
            extensions: [],
            submoduleCfg: [],
            userRemoteConfigs: [[credentialsId: "${git_auth}",url:"http://192.168.44.24/root/spring-boot-case-ci.git"]]
        ])
    }
    stage('build') {
        sh "mvn -v"
        sh "java --version"
        //定义镜像名称
        def imageName = "${project_name}:${tag}"
        //编译,构建本地镜像
        sh "mvn clean package dockerfile:build"
        //给镜像打标签
        sh "docker tag ${imageName} ${harbor_url}/${harbor_project_name}/${imageName}"
        //登录Harbor,并上传镜像
        withCredentials([usernamePassword(credentialsId: "${harbor_auth}",passwordVariable: 'password', usernameVariable: 'username')]) {
            //登录
            sh "docker login -u ${username} -p ${password} ${harbor_url}"
            //上传镜像
            sh "docker push ${harbor_url}/${harbor_project_name}/${imageName}"
        }
        //删除本地镜像
        sh "docker rmi -f ${imageName}"
        sh "docker rmi -f ${harbor_url}/${harbor_project_name}/${imageName}"
    }
}

前端项目-vue

  • nginx.conf/default.conf
server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html = 404;
    }

    location /prod-api/{
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://xxx/;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
  • Dockerfile
FROM nginx
RUN rm /etc/nginx/conf.d/default.conf
ADD default.conf /etc/nginx/conf.d/
COPY dist/ /usr/share/nginx/html/
EXPOSE 80
  • Jenkinsfile

构建部分

sh "npm install"
sh "npm run build:prod"
sh "docker build -t ${imageName} ."
posted @   Ranger-dev  阅读(64)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示